Click here to Skip to main content
15,896,269 members
Articles / Programming Languages / C#

Deep copy of objects in C#

Rate me:
Please Sign up or sign in to vote.
4.83/5 (15 votes)
18 Jul 2009CPOL 154.1K   1.2K   34  
How to do a deep copy of objects using System.Reflection.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using HAKGERSoft;
using NUnit.Framework;

namespace HAKGERSoft {

    [HClonerTestObject]
    public class SimpleTestObject {

        public int PubInt=5;
        private int PrivInt=3;

        public string StrProp {
            get;
            set;
        }

        private string _StrProp2="teststring";
        public string StrProp2 {
            get {
                return _StrProp2;
            }
            set {
                _StrProp2=value;
            }
        }

        public StringBuilder StrBuilder=new StringBuilder();

        public int Method(string arg) {
            return PrivInt;
        }



    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
Poland Poland
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions