Esempio n. 1
0
        public MetadataOnlyTypeDef(MetadataOnlyModule scope, Token tokenTypeDef, Type[] typeParameters)
        {
            MetadataOnlyTypeDef.ValidateConstructorArguments(scope, tokenTypeDef);
            this.m_resolver       = scope;
            this.m_tokenTypeDef   = tokenTypeDef;
            this.m_typeParameters = null;
            this.m_resolver.GetTypeProps(this.m_tokenTypeDef, out this.m_tokenExtends, out this.m_fullName, out this.m_typeAttributes);
            int  num  = this.m_resolver.CountGenericParams(this.m_tokenTypeDef);
            bool flag = (typeParameters == null ? false : (int)typeParameters.Length > 0);

            if (num <= 0)
            {
                this.m_typeParameters = Type.EmptyTypes;
            }
            else
            {
                if (flag)
                {
                    if (num != (int)typeParameters.Length)
                    {
                        throw new ArgumentException(MetadataStringTable.WrongNumberOfGenericArguments);
                    }
                    this.m_typeParameters = typeParameters;
                    return;
                }
                this.m_typeParameters = new Type[num];
                int num1 = 0;
                foreach (int genericParameterToken in this.m_resolver.GetGenericParameterTokens(this.m_tokenTypeDef))
                {
                    int num2 = num1;
                    num1 = num2 + 1;
                    this.m_typeParameters[num2] = this.m_resolver.Factory.CreateTypeVariable(this.m_resolver, new Token(genericParameterToken));
                }
            }
        }
Esempio n. 2
0
        internal static bool IsAssignableFromHelper(Type current, Type target)
        {
            if (target == null)
            {
                return(false);
            }
            if (current.Equals(target))
            {
                return(true);
            }
            if (target.IsSubclassOf(current))
            {
                return(true);
            }
            Type[] interfaces = target.GetInterfaces();
            for (int i = 0; i < (int)interfaces.Length; i++)
            {
                if (interfaces[i].Equals(current))
                {
                    return(true);
                }
                if (current.IsAssignableFrom(interfaces[i]))
                {
                    return(true);
                }
            }
            if (target.IsGenericParameter)
            {
                Type[] genericParameterConstraints = target.GetGenericParameterConstraints();
                for (int j = 0; j < (int)genericParameterConstraints.Length; j++)
                {
                    if (MetadataOnlyTypeDef.IsAssignableFromHelper(current, genericParameterConstraints[j]))
                    {
                        return(true);
                    }
                }
            }
            ITypeUniverse typeUniverse = Helpers.Universe(current);

            if (typeUniverse == null || !current.Equals(typeUniverse.GetTypeXFromName("System.Object")))
            {
                return(false);
            }
            if (target.IsPointer || target.IsInterface)
            {
                return(true);
            }
            return(target.IsArray);
        }
Esempio n. 3
0
 public override bool IsAssignableFrom(Type c)
 {
     if (c == null)
     {
         return(false);
     }
     if (base.IsPointer && c.IsPointer || base.IsByRef && c.IsByRef)
     {
         Type elementType = c.GetElementType();
         if (this.m_type.IsAssignableFrom(elementType) && !elementType.IsValueType)
         {
             return(true);
         }
     }
     return(MetadataOnlyTypeDef.IsAssignableFromHelper(this, c));
 }
        public override bool IsAssignableFrom(Type c)
        {
            if (c == null)
            {
                return(false);
            }
            if (!c.IsArray || c.GetArrayRank() != 1 || !(c is MetadataOnlyVectorType))
            {
                return(MetadataOnlyTypeDef.IsAssignableFromHelper(this, c));
            }
            Type elementType = c.GetElementType();

            if (elementType.IsValueType)
            {
                return(this.GetElementType().Equals(elementType));
            }
            return(this.GetElementType().IsAssignableFrom(elementType));
        }
Esempio n. 5
0
 public override bool IsAssignableFrom(Type c)
 {
     return(MetadataOnlyTypeDef.IsAssignableFromHelper(this, c));
 }
Esempio n. 6
0
        internal static PropertyInfo GetPropertyImplHelper(MetadataOnlyCommonType type, string name, BindingFlags bindingAttr, Binder binder, Type returnType, Type[] types, ParameterModifier[] modifiers)
        {
            if (binder != null)
            {
                throw new NotSupportedException();
            }
            if (modifiers != null && (int)modifiers.Length != 0)
            {
                throw new NotSupportedException();
            }
            StringComparison stringComparison = SignatureUtil.GetStringComparison(bindingAttr);

            PropertyInfo[] properties = type.GetProperties(bindingAttr);
            for (int i = 0; i < (int)properties.Length; i++)
            {
                PropertyInfo propertyInfo = properties[i];
                if (propertyInfo.Name.Equals(name, stringComparison) && (!(returnType != null) || propertyInfo.PropertyType.Equals(returnType)) && MetadataOnlyTypeDef.PropertyParamTypesMatch(propertyInfo, types))
                {
                    return(propertyInfo);
                }
            }
            return(null);
        }
Esempio n. 7
0
 public override Type[] GetInterfaces()
 {
     return(MetadataOnlyTypeDef.GetAllInterfacesHelper(this));
 }
Esempio n. 8
0
 protected override PropertyInfo GetPropertyImpl(string name, BindingFlags bindingAttr, Binder binder, Type returnType, Type[] types, ParameterModifier[] modifiers)
 {
     return(MetadataOnlyTypeDef.GetPropertyImplHelper(this, name, bindingAttr, binder, returnType, types, modifiers));
 }
Esempio n. 9
0
 public override MemberInfo[] GetMembers(BindingFlags bindingAttr)
 {
     return(MetadataOnlyTypeDef.GetMembersHelper(this, bindingAttr));
 }