Returns the cloning method of the corresponding object.

Source: Internet
Author: User

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 );

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.