winrt简单克隆对象

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

 

你可能感兴趣的:(对象)