Using System;
Using System. Collections. Generic;
Using System. Text;
Using System. Collections;
Using System. Reflection;
Namespace Common. CloneObjBase
{
/// <Summary>
/// The BaseObject class is an abstract class used for inheritance.
/// Each class inherited from this class automatically supports the clone method.
/// This class implements the Icloneable interface, and each object inherited from this object will
/// Supports the Icloneable interface.
/// </Summary>
Public abstract class CloneObj: ICloneable
{
/// <Summary>
/// Author: Evan Lee
/// QQ: 278631309
// Blog: http://hi.baidu.com/genet
/// Email: Cant be Find
/// </Summary>
/// <Typeparam name = "T"> the clone object to be returned. The object must be a class </typeparam>
/// <Param name = "Tobj"> instance of the object to be cloned </param>
/// <Returns> </returns>
Public T Clone <T> (T Tobj) where T: class
{
// First, create an instance of the specified type
Object newObject = Activator. CreateInstance (typeof (T ));
// Obtain the field array of the New Type instance.
FieldInfo [] fields = newObject. GetType (). GetFields ();
Int I = 0;
Foreach (FieldInfo fi in typeof (T). GetFields ())
{
// Determine whether the field supports the ICloneable interface.
Type ICloneType = fi. FieldType. GetInterface ("ICloneable", true );