コード例 #1
0
        internal static FieldReflector Create(FieldInfo reflectionInfo)
        {
            if (reflectionInfo == null)
            {
                throw new ArgumentNullException(nameof(reflectionInfo));
            }

            return(ReflectorCacheUtils <FieldInfo, FieldReflector> .GetOrAdd(reflectionInfo, CreateInternal));

            FieldReflector CreateInternal(FieldInfo field)
            {
                if (field.DeclaringType.ContainsGenericParameters)
                {
                    return(new OpenGenericFieldReflector(field));
                }

                if (field.DeclaringType.IsEnum)
                {
                    return(new EnumFieldReflector(field));
                }

                if (field.IsStatic)
                {
                    return(new StaticFieldReflector(field));
                }

                return(new FieldReflector(field));
            }
        }
コード例 #2
0
        internal static PropertyReflector Create(PropertyInfo reflectionInfo, CallOptions callOption)
        {
            if (reflectionInfo == null)
            {
                throw new ArgumentNullException(nameof(reflectionInfo));
            }
            return(ReflectorCacheUtils <Pair <PropertyInfo, CallOptions>, PropertyReflector> .GetOrAdd(new Pair <PropertyInfo, CallOptions>(reflectionInfo, callOption), CreateInternal));

            PropertyReflector CreateInternal(Pair <PropertyInfo, CallOptions> item)
            {
                var property = item.Item1;

                if (property.DeclaringType.ContainsGenericParameters)
                {
                    return(new OpenGenericPropertyReflector(property));
                }
                if ((property.CanRead && property.GetGetMethod().IsStatic) || (property.CanWrite && property.GetSetMethod().IsStatic))
                {
                    return(new StaticPropertyReflector(property));
                }
                if (property.DeclaringType.IsValueType || item.Item2 == CallOptions.Call)
                {
                    return(new CallPropertyReflector(property));
                }

                return(new PropertyReflector(property));
            }
        }
コード例 #3
0
        internal static MethodReflector Create(MethodInfo reflectionInfo, CallOptions callOption)
        {
            if (reflectionInfo == null)
            {
                throw new ArgumentNullException(nameof(reflectionInfo));
            }
            return(ReflectorCacheUtils <Pair <MethodInfo, CallOptions>, MethodReflector> .GetOrAdd(new Pair <MethodInfo, CallOptions>(reflectionInfo, callOption), CreateInternal));

            MethodReflector CreateInternal(Pair <MethodInfo, CallOptions> item)
            {
                var methodInfo = item.Item1;

                if (methodInfo.ContainsGenericParameters)
                {
                    return(new OpenGenericMethodReflector(methodInfo));
                }
                if (methodInfo.IsStatic)
                {
                    return(new StaticMethodReflector(methodInfo));
                }
                if (methodInfo.DeclaringType.IsValueType || callOption == CallOptions.Call)
                {
                    return(new CallMethodReflector(methodInfo));
                }
                return(new MethodReflector(methodInfo));
            }
        }
コード例 #4
0
 internal static TypeReflector Create(Type typeInfo)
 {
     if (typeInfo == null)
     {
         throw new ArgumentNullException(nameof(typeInfo));
     }
     return(ReflectorCacheUtils <Type, TypeReflector> .GetOrAdd(typeInfo, info => new TypeReflector(info)));
 }
コード例 #5
0
 internal static ParameterReflector Create(ParameterInfo parameterInfo)
 {
     if (parameterInfo == null)
     {
         throw new ArgumentNullException(nameof(parameterInfo));
     }
     return(ReflectorCacheUtils <ParameterInfo, ParameterReflector> .GetOrAdd(parameterInfo, info => new ParameterReflector(info)));
 }
コード例 #6
0
 internal static ConstructorReflector Create(ConstructorInfo constructorInfo)
 {
     if (constructorInfo == null)
     {
         throw new ArgumentNullException(nameof(constructorInfo));
     }
     return(ReflectorCacheUtils <ConstructorInfo, ConstructorReflector> .GetOrAdd(constructorInfo, info =>
     {
         if (info.DeclaringType.ContainsGenericParameters)
         {
             return new OpenGenericConstructorReflector(info);
         }
         return new ConstructorReflector(info);
     }));
 }
コード例 #7
0
 internal static CustomAttributeReflector Create(CustomAttributeData customAttributeData)
 {
     return(ReflectorCacheUtils <CustomAttributeData, CustomAttributeReflector> .GetOrAdd(customAttributeData, data => new CustomAttributeReflector(data)));
 }