コード例 #1
0
 public static Type Type(this MemberInfo mi)
 {
     if (mi is FieldInfo)
     {
         var fi = mi.AssertCast <FieldInfo>();
         return(fi.FieldType);
     }
     else if (mi is PropertyInfo)
     {
         var pi = mi.AssertCast <PropertyInfo>();
         return(pi.PropertyType);
     }
     else
     {
         throw AssertionHelper.Fail();
     }
 }
コード例 #2
0
 public static void SetValue(this MemberInfo mi, Object target, Object value)
 {
     if (mi is FieldInfo)
     {
         var fi = mi.AssertCast <FieldInfo>();
         fi.SetValue(target, value);
     }
     else if (mi is PropertyInfo)
     {
         var pi = mi.AssertCast <PropertyInfo>();
         pi = pi.DeclaringType.GetProperties(BF.All | BF.DeclOnly).AssertSingle(pid => pid.MetadataToken == pi.MetadataToken);
         var set = pi.GetSetMethod(true);
         set.Invoke(target, new [] { value });
     }
     else
     {
         throw AssertionHelper.Fail();
     }
 }
コード例 #3
0
 public static bool CanWrite(this MemberInfo mi)
 {
     if (mi is FieldInfo)
     {
         return(true);
     }
     else if (mi is PropertyInfo)
     {
         var pi = mi.AssertCast <PropertyInfo>();
         return(pi.CanWrite);
     }
     else
     {
         throw AssertionHelper.Fail();
     }
 }
コード例 #4
0
 public sealed override Object BeforeSerialize(MemberInfo mi, Object value)
 {
     return(BeforeSerialize(mi.AssertCast <PropertyInfo>(), value));
 }
コード例 #5
0
 public sealed override void Validate(MemberInfo mi, Object value)
 {
     Validate(mi.AssertCast <Type>(), value);
 }
コード例 #6
0
        public static Visibility Visibility(this MemberInfo mi)
        {
            mi.AssertNotNull();
            if (mi is Type)
            {
                var t = mi.AssertCast <Type>();
                if (t.IsNested)
                {
                    if (t.IsNestedPublic)
                    {
                        return(Reflection.Visibility.Public);
                    }
                    if (t.IsNestedFamORAssem)
                    {
                        return(Reflection.Visibility.FamilyOrAssembly);
                    }
                    if (t.IsNestedFamily)
                    {
                        return(Reflection.Visibility.Family);
                    }
                    if (t.IsNestedAssembly)
                    {
                        return(Reflection.Visibility.Assembly);
                    }
                    if (t.IsNestedFamANDAssem)
                    {
                        return(Reflection.Visibility.FamilyAndAssembly);
                    }
                    if (t.IsNestedPrivate)
                    {
                        return(Reflection.Visibility.Private);
                    }
                    throw AssertionHelper.Fail();
                }
                else
                {
                    if (t.IsPublic)
                    {
                        return(Reflection.Visibility.Public);
                    }
                    return(Reflection.Visibility.Assembly);
                }
            }
            else if (mi is FieldInfo)
            {
                var fi = mi.AssertCast <FieldInfo>();
                if (fi.IsPublic)
                {
                    return(Reflection.Visibility.Public);
                }
                if (fi.IsFamilyOrAssembly)
                {
                    return(Reflection.Visibility.FamilyOrAssembly);
                }
                if (fi.IsFamily)
                {
                    return(Reflection.Visibility.Family);
                }
                if (fi.IsAssembly)
                {
                    return(Reflection.Visibility.Assembly);
                }
                if (fi.IsFamilyAndAssembly)
                {
                    return(Reflection.Visibility.FamilyAndAssembly);
                }
                if (fi.IsPrivate)
                {
                    return(Reflection.Visibility.Private);
                }
                throw AssertionHelper.Fail();
            }
            else if (mi is MethodBase)
            {
                var mb = mi.AssertCast <MethodBase>();
                if (mb.IsPublic)
                {
                    return(Reflection.Visibility.Public);
                }
                if (mb.IsFamilyOrAssembly)
                {
                    return(Reflection.Visibility.FamilyOrAssembly);
                }
                if (mb.IsFamily)
                {
                    return(Reflection.Visibility.Family);
                }
                if (mb.IsAssembly)
                {
                    return(Reflection.Visibility.Assembly);
                }
                if (mb.IsFamilyAndAssembly)
                {
                    return(Reflection.Visibility.FamilyAndAssembly);
                }
                if (mb.IsPrivate)
                {
                    return(Reflection.Visibility.Private);
                }
                throw AssertionHelper.Fail();
            }
            else if (mi is PropertyInfo)
            {
                var pi     = mi.AssertCast <PropertyInfo>();
                var getter = pi.CanRead ? null : pi.GetGetMethod(true);
                var setter = pi.CanRead ? null : pi.GetGetMethod(true);

                if (getter == null || setter == null)
                {
                    throw AssertionHelper.Fail();
                }
                else if (getter == null || setter == null)
                {
                    return((getter ?? setter).Visibility());
                }
                else
                {
                    var g_vis = getter.Visibility();
                    var s_vis = setter.Visibility();
                    return((Visibility)Math.Max((int)g_vis, (int)s_vis));
                }
            }
            else
            {
                throw AssertionHelper.Fail();
            }
        }
コード例 #7
0
 public sealed override Json Serialize(MemberInfo mi, Object value)
 {
     return(Serialize(mi.AssertCast <Type>(), value));
 }
コード例 #8
0
 public sealed override Object Deserialize(MemberInfo mi, Json json)
 {
     return(Deserialize(mi.AssertCast <Type>(), json));
 }
コード例 #9
0
ファイル: TypeAdapter.cs プロジェクト: avaranovich/xenogears
 public sealed override Object BeforeSerialize(MemberInfo mi, Object value) { return BeforeSerialize(mi.AssertCast<Type>(), value); }
コード例 #10
0
ファイル: TypeAdapter.cs プロジェクト: avaranovich/xenogears
 public sealed override Object AfterDeserialize(MemberInfo mi, Object value) { return AfterDeserialize(mi.AssertCast<Type>(), value); }