Example #1
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;
        }
Example #2
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();
            }
        }
Example #3
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;
        }