コード例 #1
0
        private void _HandlePublicMember(MemberInfo memberInfo)
        {
            if (!memberInfo.CanWrite() || memberInfo.GetCustomAttribute <IgnoreAttribute>() != null)
            {
                return;
            }

            var spec = _GenerateSpec(memberInfo, memberInfo.GetCustomAttribute <SpecAttribute>());

            mSpec2MemberInfo.Add(spec, memberInfo);
            mSpecs.AddSpec(spec);
        }
コード例 #2
0
        private void _HandleNonPublicMember(MemberInfo memberInfo)
        {
            if (!memberInfo.CanWrite() || memberInfo.GetCustomAttribute <IgnoreAttribute>() != null)
            {
                return;
            }

            var attr = memberInfo.GetCustomAttribute <SpecAttribute>();

            if (attr == null)
            {// 非public没有attribute不处理
                return;
            }

            var spec = _GenerateSpec(memberInfo, attr);

            mSpec2MemberInfo.Add(spec, memberInfo);
            mSpecs.AddSpec(spec);
        }
コード例 #3
0
 public AbstractMemberSetter(MemberInfo member, Type declaringType, bool allowInherited)
 {
     if (member == null)
     {
         throw new ArgumentNullException("member");
     }
     if (!member.CanWrite())
     {
         throw new BuilderException(string.Format("{0}: member is not writable", member));
     }
     Member           = member;
     MemberReturnType = member.ReturnType();
     DeclaringType    = declaringType;
     if (allowInherited)
     {
         _typeCheck = t => DeclaringType.IsAssignableFrom(t);
     }
     else
     {
         _typeCheck = t => DeclaringType == t;
     }
 }
コード例 #4
0
ファイル: Cloner.cs プロジェクト: twenty0ne/UnityDecompiled
 private static void CloneThing(MemberInfo thing, object target, object originValue, Type originValueType, Type targetValueType)
 {
     if ((!thing.CanWrite() || ((originValue != null) && !targetValueType.IsAssignableFrom(originValueType))) && typeof(IList).IsAssignableFrom(originValueType))
     {
         IList list = thing.GetValue(target) as IList;
         if ((list == null) && thing.CanWrite())
         {
             list = Activator.CreateInstance(targetValueType) as IList;
             thing.SetValue(target, list);
         }
         if (list != null)
         {
             IEnumerator enumerator = (originValue as IList).GetEnumerator();
             try
             {
                 while (enumerator.MoveNext())
                 {
                     object current = enumerator.Current;
                     if (current != null)
                     {
                         object obj3 = CloneObject(current, GetElementType(list.GetType()));
                         list.Add(obj3);
                     }
                 }
             }
             finally
             {
                 IDisposable disposable = enumerator as IDisposable;
                 if (disposable != null)
                 {
                     disposable.Dispose();
                 }
             }
             return;
         }
     }
     if (thing.CanWrite())
     {
         if ((originValue != null) && !targetValueType.IsAssignableFrom(originValueType))
         {
             if (targetValueType.IsAssignableFrom(typeof(Uri)) && originValueType.IsAssignableFrom(typeof(string)))
             {
                 Uri result = null;
                 if (Uri.TryCreate((string)originValue, UriKind.RelativeOrAbsolute, out result))
                 {
                     thing.SetValue(target, result);
                 }
             }
             else if (targetValueType.IsAssignableFrom(typeof(string)) && originValueType.IsAssignableFrom(typeof(Uri)))
             {
                 string str = string.Empty;
                 if (originValue != null)
                 {
                     str = originValue.ToString();
                 }
                 thing.SetValue(target, str);
             }
             else if (targetValueType.IsAssignableFrom(typeof(PackageVersion)) && originValueType.IsAssignableFrom(typeof(string)))
             {
                 try
                 {
                     PackageVersion version = new PackageVersion((string)originValue);
                     thing.SetValue(target, version);
                 }
                 catch
                 {
                 }
             }
             else if (targetValueType.IsAssignableFrom(typeof(string)) && originValueType.IsAssignableFrom(typeof(PackageVersion)))
             {
                 string str2 = string.Empty;
                 if (originValue != null)
                 {
                     str2 = originValue.ToString();
                 }
                 thing.SetValue(target, str2);
             }
             else if (targetValueType.IsClass)
             {
                 object obj4 = CloneObject(originValue, targetValueType);
                 if (obj4 == null)
                 {
                     obj4 = thing.GetValue(target);
                 }
                 if (obj4 != null)
                 {
                     thing.SetValue(target, obj4);
                 }
                 else
                 {
                     thing.SetValue(target, originValue);
                 }
             }
             else if (targetValueType.IsEnum)
             {
                 thing.SetValue(target, (int)originValue);
             }
         }
         else if (originValue == null)
         {
             thing.SetValue(target, originValue);
         }
         else if (targetValueType.IsClass && (targetValueType != typeof(string)))
         {
             object obj5 = CloneObject(originValue, targetValueType);
             if (obj5 == null)
             {
                 obj5 = thing.GetValue(target);
             }
             if (obj5 != null)
             {
                 thing.SetValue(target, obj5);
             }
             else
             {
                 thing.SetValue(target, originValue);
             }
         }
         else
         {
             thing.SetValue(target, originValue);
         }
     }
 }
コード例 #5
0
 private static void CloneThing(MemberInfo thing, object target, object originValue, Type originValueType, Type targetValueType)
 {
     if ((!thing.CanWrite() || (originValue != null && !targetValueType.IsAssignableFrom(originValueType))) && typeof(IList).IsAssignableFrom(originValueType))
     {
         IList list = thing.GetValue(target) as IList;
         if (list == null && thing.CanWrite())
         {
             list = (Activator.CreateInstance(targetValueType) as IList);
             thing.SetValue(target, list);
         }
         if (list != null)
         {
             IList list2 = originValue as IList;
             foreach (object current in list2)
             {
                 if (current != null)
                 {
                     object value = Cloner.CloneObject(current, Cloner.GetElementType(list.GetType()));
                     list.Add(value);
                 }
             }
             return;
         }
     }
     if (!thing.CanWrite())
     {
         return;
     }
     if (originValue != null && !targetValueType.IsAssignableFrom(originValueType))
     {
         if (targetValueType.IsAssignableFrom(typeof(Uri)) && originValueType.IsAssignableFrom(typeof(string)))
         {
             Uri value2 = null;
             if (Uri.TryCreate((string)originValue, UriKind.RelativeOrAbsolute, out value2))
             {
                 thing.SetValue(target, value2);
             }
         }
         else if (targetValueType.IsAssignableFrom(typeof(string)) && originValueType.IsAssignableFrom(typeof(Uri)))
         {
             string value3 = string.Empty;
             if (originValue != null)
             {
                 value3 = originValue.ToString();
             }
             thing.SetValue(target, value3);
         }
         else if (targetValueType.IsAssignableFrom(typeof(PackageVersion)) && originValueType.IsAssignableFrom(typeof(string)))
         {
             try
             {
                 PackageVersion value4 = new PackageVersion((string)originValue);
                 thing.SetValue(target, value4);
             }
             catch
             {
             }
         }
         else if (targetValueType.IsAssignableFrom(typeof(string)) && originValueType.IsAssignableFrom(typeof(PackageVersion)))
         {
             string value5 = string.Empty;
             if (originValue != null)
             {
                 value5 = originValue.ToString();
             }
             thing.SetValue(target, value5);
         }
         else if (targetValueType.IsClass)
         {
             object obj = Cloner.CloneObject(originValue, targetValueType);
             if (obj == null)
             {
                 obj = thing.GetValue(target);
             }
             if (obj != null)
             {
                 thing.SetValue(target, obj);
             }
             else
             {
                 thing.SetValue(target, originValue);
             }
         }
         else if (targetValueType.IsEnum)
         {
             thing.SetValue(target, (int)originValue);
         }
     }
     else if (originValue == null)
     {
         thing.SetValue(target, originValue);
     }
     else if (targetValueType.IsClass && targetValueType != typeof(string))
     {
         object obj2 = Cloner.CloneObject(originValue, targetValueType);
         if (obj2 == null)
         {
             obj2 = thing.GetValue(target);
         }
         if (obj2 != null)
         {
             thing.SetValue(target, obj2);
         }
         else
         {
             thing.SetValue(target, originValue);
         }
     }
     else
     {
         thing.SetValue(target, originValue);
     }
 }