Ejemplo n.º 1
0
 internal MethodBaseInfo(MethodBaseInfo methodBaseInfo, TypeInfoProvider typeInfoProvider)
     : base(methodBaseInfo, typeInfoProvider)
 {
     BindingFlags         = methodBaseInfo.BindingFlags;
     GenericArgumentTypes = methodBaseInfo.GenericArgumentTypes?.Select(typeInfoProvider.Get).ToList();
     ParameterTypes       = methodBaseInfo.ParameterTypes?.Select(typeInfoProvider.Get).ToList();
 }
Ejemplo n.º 2
0
 internal MethodBaseInfo(MethodBaseInfo methodBaseInfo, TypeInfoProvider typeInfoProvider)
     : base(methodBaseInfo, typeInfoProvider)
 {
     // TODO: why is the dammit operator required!?
     GenericArgumentTypes = methodBaseInfo.GenericArgumentTypes?.Select(typeInfoProvider.Get).ToList() !;
     ParameterTypes       = methodBaseInfo.ParameterTypes?.Select(typeInfoProvider.Get).ToList() !;
 }
Ejemplo n.º 3
0
        public virtual TypeInfo?Get(Type?type, bool?includePropertyInfosOverride = null, bool?setMemberDeclaringTypesOverride = null)
        {
            if (type is null)
            {
                return(null);
            }

            if (_referenceTracker.TryGetValue(type, out TypeInfo typeInfo))
            {
                return(typeInfo);
            }

            if (_parent != null)
            {
                return(_parent.Get(type, includePropertyInfosOverride, setMemberDeclaringTypesOverride));
            }

            var context = this;

            if ((includePropertyInfosOverride.HasValue && includePropertyInfosOverride != IncludePropertyInfos) ||
                (setMemberDeclaringTypesOverride.HasValue && setMemberDeclaringTypesOverride != SetMemberDeclaringTypes))
            {
                context = new TypeInfoProvider(
                    includePropertyInfosOverride ?? IncludePropertyInfos,
                    setMemberDeclaringTypesOverride ?? SetMemberDeclaringTypes,
                    this);
            }

            return(new TypeInfo(type, context));
        }
Ejemplo n.º 4
0
 internal MemberInfo(System.Reflection.MemberInfo memberInfo, TypeInfoProvider typeInfoProvider)
 {
     if (!(memberInfo is null))
     {
         Name          = memberInfo.Name;
         DeclaringType = typeInfoProvider.Get(memberInfo.DeclaringType, false, false);
     }
 }
Ejemplo n.º 5
0
 internal MemberInfo(MemberInfo memberInfo, TypeInfoProvider typeInfoProvider)
 {
     if (!(memberInfo is null))
     {
         Name          = memberInfo.Name;
         DeclaringType = typeInfoProvider.Get(memberInfo.DeclaringType);
     }
 }
Ejemplo n.º 6
0
 protected MemberInfo(System.Reflection.MemberInfo member, TypeInfoProvider typeInfoProvider)
 {
     Name = member.CheckNotNull(nameof(member)).Name;
     DeclaringType = typeInfoProvider.CheckNotNull(nameof(typeInfoProvider)).GetTypeInfo(member.DeclaringType, false, false);
     if (member.GetBindingFlags().Contains(System.Reflection.BindingFlags.Static))
     {
         IsStatic = true;
     }
 }
Ejemplo n.º 7
0
        internal PropertyInfo(PropertyInfo propertyInfo, TypeInfoProvider typeInfoProvider)
            : base(propertyInfo, typeInfoProvider)
        {
            if (propertyInfo is null)
            {
                throw new ArgumentNullException(nameof(propertyInfo));
            }

            PropertyType = typeInfoProvider.Get(propertyInfo.PropertyType);
            _property    = propertyInfo._property;
        }
Ejemplo n.º 8
0
 protected MethodBaseInfo(MethodBaseInfo method, TypeInfoProvider typeInfoProvider)
     : base(method, typeInfoProvider)
 {
     GenericArgumentTypes = method.CheckNotNull(nameof(method)).GenericArgumentTypes
                            .AsNullIfEmpty()?
                            .Select(x => typeInfoProvider.Get(x))
                            .ToList();
     ParameterTypes = method.ParameterTypes
                      .AsNullIfEmpty()?
                      .Select(x => typeInfoProvider.Get(x))
                      .ToList();
 }
Ejemplo n.º 9
0
        internal TypeInfo(TypeInfo typeInfo, TypeInfoProvider typeInfoProvider)
        {
            typeInfoProvider.RegisterReference(typeInfo, this);

            Name             = typeInfo.Name;
            Namespace        = typeInfo.Namespace;
            DeclaringType    = typeInfo.DeclaringType is null ? null : typeInfoProvider.Get(typeInfo.DeclaringType);
            GenericArguments = typeInfo.GenericArguments?.Select(x => typeInfoProvider.Get(x)).ToList();
            IsGenericType    = typeInfo.IsGenericType;
            IsAnonymousType  = typeInfo.IsAnonymousType;
            Properties       = typeInfo.Properties?.Select(x => new PropertyInfo(x, typeInfoProvider)).ToList();
            _type            = typeInfo._type;
        }
Ejemplo n.º 10
0
        internal TypeInfo(Type type, TypeInfoProvider typeInfoProvider)
        {
            if (type is null)
            {
                throw new ArgumentNullException(nameof(type));
            }

            typeInfoProvider.RegisterReference(type, this);

            _type = type;

            Name = type.Name;

            Namespace = type.Namespace;

            if (type.IsArray)
            {
                if (!IsArray)
                {
                    throw new ArgumentException("Type name is not in expected format for array type");
                }

                type = type.GetElementType();
            }

            if (type.IsNested && !type.IsGenericParameter)
            {
                DeclaringType = typeInfoProvider.Get(type.DeclaringType, false, false);
            }

            IsGenericType = type.IsGenericType;

            if (IsGenericType && !type.GetTypeInfo().IsGenericTypeDefinition)
            {
                GenericArguments = type
                                   .GetGenericArguments()
                                   .Select(x => typeInfoProvider.Get(x))
                                   .ToList();
            }

            IsAnonymousType = type.IsAnonymousType();

            if (IsAnonymousType || typeInfoProvider.IncludePropertyInfos)
            {
                Properties = type
                             .GetProperties()
                             .OrderBy(x => x.MetadataToken)
                             .Select(x => new PropertyInfo(x.Name, typeInfoProvider.Get(x.PropertyType), typeInfoProvider.SetMemberDeclaringTypes ? this : null))
                             .ToList();
            }
        }
Ejemplo n.º 11
0
        internal MemberInfo(System.Reflection.MemberInfo memberInfo, TypeInfoProvider typeInfoProvider)
        {
            if (memberInfo is null)
            {
                throw new ArgumentNullException(nameof(memberInfo));
            }

            Name          = memberInfo.Name;
            DeclaringType = typeInfoProvider.Get(memberInfo.DeclaringType, false, false);
            if (memberInfo.GetBindingFlags().Contains(System.Reflection.BindingFlags.Static))
            {
                IsStatic = true;
            }
        }
Ejemplo n.º 12
0
        internal MethodBaseInfo(System.Reflection.MethodBase methodInfo, TypeInfoProvider typeInfoProvider)
            : base(methodInfo, typeInfoProvider)
        {
            var genericArguments = methodInfo.IsGenericMethod ? methodInfo.GetGenericArguments() : null;

            GenericArgumentTypes = genericArguments is null || genericArguments.Length == 0
                ? null
                : genericArguments.Select(x => typeInfoProvider.Get(x, false, false)).ToList();

            var parameters = methodInfo.GetParameters();

            ParameterTypes = parameters.Length == 0
                ? null
                : parameters.Select(x => typeInfoProvider.Get(x.ParameterType, false, false)).ToList();
        }
Ejemplo n.º 13
0
        protected MethodBaseInfo(System.Reflection.MethodBase method, TypeInfoProvider typeInfoProvider)
            : base(method, typeInfoProvider)
        {
            var genericArguments = method.CheckNotNull(nameof(method)).IsGenericMethod ? method.GetGenericArguments() : null;

            GenericArgumentTypes = genericArguments
                                   .AsNullIfEmpty()?
                                   .Select(x => typeInfoProvider.GetTypeInfo(x, false, false))
                                   .ToList();
            ParameterTypes = method
                             .GetParameters()
                             .AsNullIfEmpty()?
                             .Select(x => typeInfoProvider.GetTypeInfo(x.ParameterType, false, false))
                             .ToList();
        }
Ejemplo n.º 14
0
        internal TypeInfo(TypeInfo typeInfo, TypeInfoProvider typeInfoProvider)
        {
            if (typeInfo is null)
            {
                throw new ArgumentNullException(nameof(typeInfo));
            }

            typeInfoProvider.RegisterReference(typeInfo, this);

            Name          = typeInfo.Name;
            Namespace     = typeInfo.Namespace;
            DeclaringType = typeInfo.DeclaringType is null ? null : typeInfoProvider.Get(typeInfo.DeclaringType);

            // TODO: why is the dammit operator required!?
            GenericArguments = typeInfo.GenericArguments?.Select(typeInfoProvider.Get).ToList() !;
            IsGenericType    = typeInfo.IsGenericType;
            IsAnonymousType  = typeInfo.IsAnonymousType;
            Properties       = typeInfo.Properties?.Select(x => new PropertyInfo(x, typeInfoProvider)).ToList();
            _type            = typeInfo._type;
        }
Ejemplo n.º 15
0
        internal MethodBaseInfo(System.Reflection.MethodBase methodInfo, TypeInfoProvider typeInfoProvider)
            : base(methodInfo, typeInfoProvider)
        {
            var bindingFlags = methodInfo.IsStatic ? BindingFlags.Static : BindingFlags.Instance;

            bindingFlags |= methodInfo.IsPublic ? BindingFlags.Public : BindingFlags.NonPublic;
            BindingFlags  = bindingFlags;

            var genericArguments = methodInfo.IsGenericMethod ? methodInfo.GetGenericArguments() : null;

            GenericArgumentTypes = genericArguments is null || genericArguments.Length == 0
                ? null
                : genericArguments.Select(x => typeInfoProvider.Get(x, false, false)).ToList();

            var parameters = methodInfo.GetParameters();

            ParameterTypes = parameters.Length == 0
                ? null
                : parameters.Select(x => typeInfoProvider.Get(x.ParameterType, false, false)).ToList();
        }
Ejemplo n.º 16
0
        internal static MemberInfo Create(System.Reflection.MemberInfo memberInfo, TypeInfoProvider typeInfoProvider)
        {
            switch (memberInfo.GetMemberType())
            {
            case MemberTypes.Field:
                return(new FieldInfo((System.Reflection.FieldInfo)memberInfo, typeInfoProvider));

            case MemberTypes.Constructor:
                return(new ConstructorInfo((System.Reflection.ConstructorInfo)memberInfo, typeInfoProvider));

            case MemberTypes.Property:
                return(new PropertyInfo((System.Reflection.PropertyInfo)memberInfo, typeInfoProvider));

            case MemberTypes.Method:
                return(new MethodInfo((System.Reflection.MethodInfo)memberInfo, typeInfoProvider));

            default:
                throw new Exception($"Not supported member type: {memberInfo.GetMemberType()}");
            }
        }
Ejemplo n.º 17
0
 public MethodInfo(System.Reflection.MethodInfo method, TypeInfoProvider typeInfoProvider)
     : base(method, typeInfoProvider)
 {
     _method    = method;
     ReturnType = typeInfoProvider.CheckNotNull(nameof(typeInfoProvider)).GetTypeInfo(method?.ReturnType, false, false);
 }
Ejemplo n.º 18
0
 internal MethodInfo(string name, Type declaringType, IEnumerable <Type>?genericArguments, IEnumerable <Type>?parameterTypes, Type?returnType, TypeInfoProvider typeInfoProvider)
     : base(name, declaringType, genericArguments, parameterTypes, typeInfoProvider)
 {
     ReturnType = typeInfoProvider.Get(returnType, false, false);
 }
Ejemplo n.º 19
0
 internal MethodInfo(System.Reflection.MethodInfo methodInfo, TypeInfoProvider typeInfoProvider)
     : base(methodInfo, typeInfoProvider)
 {
     _method    = methodInfo;
     ReturnType = typeInfoProvider.Get(methodInfo?.ReturnType, false, false);
 }
Ejemplo n.º 20
0
 internal MethodInfo(System.Reflection.MethodInfo methodInfo, TypeInfoProvider typeInfoProvider)
     : base(methodInfo, typeInfoProvider)
 {
     _method = methodInfo;
 }
Ejemplo n.º 21
0
 public ConstructorInfo(System.Reflection.ConstructorInfo constructor, TypeInfoProvider typeInfoProvider)
     : base(constructor, typeInfoProvider)
 {
     _constructor = constructor;
 }
Ejemplo n.º 22
0
 internal PropertyInfo(System.Reflection.PropertyInfo propertyInfo, TypeInfoProvider typeInfoProvider)
     : base(propertyInfo, typeInfoProvider)
 {
     _property    = propertyInfo;
     PropertyType = typeInfoProvider.Get(propertyInfo.PropertyType, false, false);
 }
Ejemplo n.º 23
0
 internal ConstructorInfo(System.Reflection.ConstructorInfo constructorInfo, TypeInfoProvider typeInfoProvider)
     : base(constructorInfo, typeInfoProvider)
 {
     _constructor = constructorInfo;
 }
Ejemplo n.º 24
0
 internal MethodBaseInfo(string name, Type declaringType, IEnumerable <Type>?genericArguments, IEnumerable <Type>?parameterTypes, TypeInfoProvider typeInfoProvider)
     : this(
         name,
         typeInfoProvider.Get(declaringType, includePropertyInfosOverride : false, setMemberDeclaringTypesOverride : false),
         genericArguments?.Select(x => typeInfoProvider.Get(x, false, false)),
         parameterTypes?.Select(x => typeInfoProvider.Get(x, false, false)))
 {
 }
Ejemplo n.º 25
0
 protected MethodBaseInfo(string name, Type declaringType, IEnumerable <Type>?genericArguments, IEnumerable <Type>?parameterTypes, TypeInfoProvider typeInfoProvider)
     : this(
         name,
         typeInfoProvider.CheckNotNull(nameof(typeInfoProvider)).GetTypeInfo(declaringType, includePropertyInfos : false, setMemberDeclaringTypes : false),
         genericArguments?.Select(x => typeInfoProvider.GetTypeInfo(x, false, false)),
         parameterTypes?.Select(x => typeInfoProvider.GetTypeInfo(x, false, false)))
 {
 }
Ejemplo n.º 26
0
 internal FieldInfo(System.Reflection.FieldInfo fieldInfo, TypeInfoProvider typeInfoProvider)
     : base(fieldInfo, typeInfoProvider)
 {
     _field = fieldInfo;
 }
Ejemplo n.º 27
0
 private PropertyInfo(string propertyName, Type propertyType, Type declaringType, TypeInfoProvider typeInfoProvider)
     : this(propertyName, typeInfoProvider.Get(propertyType, false, false), typeInfoProvider.Get(declaringType, false, false))
 {
 }
Ejemplo n.º 28
0
 public MethodInfo(string name, Type declaringType, IEnumerable <Type>?genericArguments, IEnumerable <Type>?parameterTypes, Type?returnType, TypeInfoProvider typeInfoProvider)
     : base(name, declaringType, genericArguments, parameterTypes, typeInfoProvider)
 {
     ReturnType = typeInfoProvider.CheckNotNull(nameof(typeInfoProvider)).GetTypeInfo(returnType, false, false);
 }
Ejemplo n.º 29
0
 // TODO: replace binding flags by bool flags
 internal MethodBaseInfo(string name, Type declaringType, BindingFlags bindingFlags, Type[] genericArguments, Type[] parameterTypes, TypeInfoProvider typeInfoProvider)
     : this(
         name,
         typeInfoProvider.Get(declaringType, includePropertyInfosOverride : false, setMemberDeclaringTypesOverride : false),
         bindingFlags,
         genericArguments?.Select(x => typeInfoProvider.Get(x, false, false)),
         parameterTypes?.Select(x => typeInfoProvider.Get(x, false, false)))
 {
 }
Ejemplo n.º 30
0
 internal PropertyInfo(PropertyInfo propertyInfo, TypeInfoProvider typeInfoProvider)
     : base(propertyInfo, typeInfoProvider)
 {
     PropertyType = typeInfoProvider.Get(propertyInfo.PropertyType);
     _property    = propertyInfo._property;
 }