码迷,mamicode.com
首页 > Windows程序 > 详细

winrt简单克隆对象

时间:2015-01-26 16:29:35      阅读:161      评论:0      收藏:0      [点我收藏+]

标签:

public MapPoint Copy()//MapPoint克隆方法
        {
            MapPoint p = new MapPoint();//这是我自定义的对象
            //利用反射获得类成员
            FieldInfo[] fieldFroms = IntrospectionExtensions.GetTypeInfo(p.GetType()).DeclaredFields.ToArray();
            FieldInfo[] fieldTos = IntrospectionExtensions.GetTypeInfo(this.GetType()).DeclaredFields.ToArray();
            int lenTo = fieldTos.Length;

            for (int i = 0, l = fieldFroms.Length; i < l; i++)
            {
                for (int j = 0; j < lenTo; j++)
                {
                    if (fieldTos[j].Name != fieldFroms[i].Name) continue;
                    fieldTos[j].SetValue(p, fieldFroms[i].GetValue(this));
            break; } }
return p; }

 

winrt简单克隆对象

标签:

原文地址:http://www.cnblogs.com/wangjinming/p/4250505.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!