コード例 #1
0
        public static TValue GetAttributeValue <TValue, TAttribute>(this MemberInfo memberInfo, Func <TAttribute, TValue> getter, TValue defaultValue = default(TValue), bool inherit = true)
            where TAttribute : Attribute
        {
            memberInfo.AssertParameterNotNull(nameof(memberInfo));
            getter = getter.AssertParameterNotNull(nameof(getter));

            var attr = memberInfo.GetCustomAttribute <TAttribute>(inherit);

            return(attr == null ? defaultValue : getter(attr));
        }
コード例 #2
0
        public static bool IsStatic(this MemberInfo memberInfo)
        {
            memberInfo.AssertParameterNotNull(nameof(memberInfo));
            switch (memberInfo.MemberType)
            {
            case MemberTypes.Event: return(((EventInfo)memberInfo).GetAddMethod().IsStatic);

            case MemberTypes.Field: return(((FieldInfo)memberInfo).IsStatic);

            case MemberTypes.Method: return(((MethodInfo)memberInfo).IsStatic);

            case MemberTypes.Property: return(((PropertyInfo)memberInfo).GetGetMethod(false).IsStatic);

            case MemberTypes.Constructor: return(((ConstructorInfo)memberInfo).IsStatic);

            case MemberTypes.TypeInfo: return(((Type)memberInfo).IsAbstract && ((Type)memberInfo).IsSealed);

            case MemberTypes.NestedType: return(((Type)memberInfo).IsAbstract && ((Type)memberInfo).IsSealed);

            default: throw new NotSupportedException();
            }
        }