GetElementType() public static méthode

public static GetElementType ( System.TypeSpec t ) : System.TypeSpec
t System.TypeSpec
Résultat System.TypeSpec
Exemple #1
0
        public void SymbolRelatedToPreviousError(Type type)
        {
            if (reporting_disabled > 0 || !printer.HasRelatedSymbolSupport)
            {
                return;
            }

            type = TypeManager.DropGenericTypeArguments(type);

            if (TypeManager.IsGenericParameter(type))
            {
                TypeParameter tp = TypeManager.LookupTypeParameter(type);
                if (tp != null)
                {
                    SymbolRelatedToPreviousError(tp.Location, "");
                    return;
                }
            }

            if (type is TypeBuilder)
            {
                DeclSpace temp_ds = TypeManager.LookupDeclSpace(type);
                SymbolRelatedToPreviousError(temp_ds.Location, TypeManager.CSharpName(type));
            }
            else if (TypeManager.HasElementType(type))
            {
                SymbolRelatedToPreviousError(TypeManager.GetElementType(type));
            }
            else
            {
                SymbolRelatedToPreviousError(type.Assembly.Location, TypeManager.CSharpName(type));
            }
        }
        //
        // Imports SRE parameters
        //
        public static AParametersCollection Create(ParameterInfo [] pi, MethodBase method)
        {
            if (pi.Length == 0)
            {
                if (method != null && (method.CallingConvention & CallingConventions.VarArgs) != 0)
                {
                    return(new ParametersCollection(new IParameterData [0], Type.EmptyTypes, method, false));
                }

                return(Parameters.EmptyReadOnlyParameters);
            }

            Type []           types = new Type [pi.Length];
            IParameterData [] par   = new IParameterData [pi.Length];
            bool is_params          = false;

            for (int i = 0; i < types.Length; i++)
            {
                types [i] = TypeManager.TypeToCoreType(pi [i].ParameterType);

                ParameterInfo      p   = pi [i];
                Parameter.Modifier mod = 0;
                if (types [i].IsByRef)
                {
                    if ((p.Attributes & (ParameterAttributes.Out | ParameterAttributes.In)) == ParameterAttributes.Out)
                    {
                        mod = Parameter.Modifier.OUT;
                    }
                    else
                    {
                        mod = Parameter.Modifier.REF;
                    }

                    //
                    // Strip reference wrapping
                    //
                    types [i] = TypeManager.GetElementType(types [i]);
                }
                else if (i == 0 && TypeManager.extension_attribute_type != null && method != null && method.IsStatic &&
                         (method.DeclaringType.Attributes & Class.StaticClassAttribute) == Class.StaticClassAttribute &&
                         method.IsDefined(TypeManager.extension_attribute_type, false))
                {
                    mod = Parameter.Modifier.This;
                }
                else if (i >= pi.Length - 2 && types [i].IsArray)
                {
                    if (p.IsDefined(TypeManager.param_array_type, false))
                    {
                        mod       = Parameter.Modifier.PARAMS;
                        is_params = true;
                    }
                }

                par [i] = new ParameterData(p.Name, mod);
            }

            return(method != null ?
                   new ParametersCollection(par, types, method, is_params) :
                   new ParametersCollection(par, types));
        }
Exemple #3
0
        //
        // Generic method parameters importer, param is shared between all instances
        //
        public static AParametersCollection Create(AParametersCollection param, MethodBase method)
        {
            if (param.IsEmpty)
            {
                return(param);
            }

            ParameterInfo [] pi    = method.GetParameters();
            Type []          types = new Type [pi.Length];
            for (int i = 0; i < types.Length; i++)
            {
                Type t = pi [i].ParameterType;
                if (t.IsByRef)
                {
                    t = TypeManager.GetElementType(t);
                }

                types [i] = TypeManager.TypeToCoreType(t);
            }

            return(new ParametersImported(param, types));
        }
Exemple #4
0
        //
        // Checks whether the type P is as accessible as this member
        //
        public bool IsAccessibleAs(TypeSpec p)
        {
            //
            // if M is private, its accessibility is the same as this declspace.
            // we already know that P is accessible to T before this method, so we
            // may return true.
            //
            if ((mod_flags & Modifiers.PRIVATE) != 0)
            {
                return(true);
            }

            while (TypeManager.HasElementType(p))
            {
                p = TypeManager.GetElementType(p);
            }

            if (p.IsGenericParameter)
            {
                return(true);
            }

            for (TypeSpec p_parent; p != null; p = p_parent)
            {
                p_parent = p.DeclaringType;

                if (p.IsGeneric)
                {
                    foreach (TypeSpec t in p.TypeArguments)
                    {
                        if (!IsAccessibleAs(t))
                        {
                            return(false);
                        }
                    }
                }

                var pAccess = p.Modifiers & Modifiers.AccessibilityMask;
                if (pAccess == Modifiers.PUBLIC)
                {
                    continue;
                }

                bool same_access_restrictions = false;
                for (MemberCore mc = this; !same_access_restrictions && mc != null && mc.Parent != null; mc = mc.Parent)
                {
                    var al = mc.ModFlags & Modifiers.AccessibilityMask;
                    switch (pAccess)
                    {
                    case Modifiers.INTERNAL:
                        if (al == Modifiers.PRIVATE || al == Modifiers.INTERNAL)
                        {
                            same_access_restrictions = p.MemberDefinition.IsInternalAsPublic(mc.Module.DeclaringAssembly);
                        }

                        break;

                    case Modifiers.PROTECTED:
                        if (al == Modifiers.PROTECTED)
                        {
                            same_access_restrictions = mc.Parent.PartialContainer.IsBaseTypeDefinition(p_parent);
                            break;
                        }

                        if (al == Modifiers.PRIVATE)
                        {
                            //
                            // When type is private and any of its parents derives from
                            // protected type then the type is accessible
                            //
                            while (mc.Parent != null && mc.Parent.PartialContainer != null)
                            {
                                if (mc.Parent.PartialContainer.IsBaseTypeDefinition(p_parent))
                                {
                                    same_access_restrictions = true;
                                }
                                mc = mc.Parent;
                            }
                        }

                        break;

                    case Modifiers.PROTECTED | Modifiers.INTERNAL:
                        if (al == Modifiers.INTERNAL)
                        {
                            same_access_restrictions = p.MemberDefinition.IsInternalAsPublic(mc.Module.DeclaringAssembly);
                        }
                        else if (al == (Modifiers.PROTECTED | Modifiers.INTERNAL))
                        {
                            same_access_restrictions = mc.Parent.PartialContainer.IsBaseTypeDefinition(p_parent) && p.MemberDefinition.IsInternalAsPublic(mc.Module.DeclaringAssembly);
                        }
                        else
                        {
                            goto case Modifiers.PROTECTED;
                        }

                        break;

                    case Modifiers.PRIVATE:
                        //
                        // Both are private and share same parent
                        //
                        if (al == Modifiers.PRIVATE)
                        {
                            var decl = mc.Parent;
                            do
                            {
                                same_access_restrictions = decl.CurrentType.MemberDefinition == p_parent.MemberDefinition;
                            } while (!same_access_restrictions && !decl.PartialContainer.IsTopLevel && (decl = decl.Parent) != null);
                        }

                        break;

                    default:
                        throw new InternalErrorException(al.ToString());
                    }
                }

                if (!same_access_restrictions)
                {
                    return(false);
                }
            }

            return(true);
        }
Exemple #5
0
        //
        // Imports SRE parameters
        //
        public static AParametersCollection Create(ParameterInfo [] pi, MethodBase method)
        {
            int varargs = method != null && (method.CallingConvention & CallingConventions.VarArgs) != 0 ? 1 : 0;

            if (pi.Length == 0 && varargs == 0)
            {
                return(ParametersCompiled.EmptyReadOnlyParameters);
            }

            Type []           types            = new Type [pi.Length + varargs];
            IParameterData [] par              = new IParameterData [pi.Length + varargs];
            bool is_params                     = false;
            PredefinedAttribute extension_attr = PredefinedAttributes.Get.Extension;
            PredefinedAttribute param_attr     = PredefinedAttributes.Get.ParamArray;

            for (int i = 0; i < pi.Length; i++)
            {
                types [i] = TypeManager.TypeToCoreType(pi [i].ParameterType);

                ParameterInfo      p             = pi [i];
                Parameter.Modifier mod           = 0;
                Expression         default_value = null;
                if (types [i].IsByRef)
                {
                    if ((p.Attributes & (ParameterAttributes.Out | ParameterAttributes.In)) == ParameterAttributes.Out)
                    {
                        mod = Parameter.Modifier.OUT;
                    }
                    else
                    {
                        mod = Parameter.Modifier.REF;
                    }

                    //
                    // Strip reference wrapping
                    //
                    types [i] = TypeManager.GetElementType(types [i]);
                }
                else if (i == 0 && extension_attr.IsDefined && method != null && method.IsStatic &&
                         (method.DeclaringType.Attributes & Class.StaticClassAttribute) == Class.StaticClassAttribute &&
                         method.IsDefined(extension_attr.Type, false))
                {
                    mod = Parameter.Modifier.This;
                }
                else
                {
                    if (i >= pi.Length - 2 && types[i].IsArray)
                    {
                        if (p.IsDefined(param_attr.Type, false))
                        {
                            mod       = Parameter.Modifier.PARAMS;
                            is_params = true;
                        }
                    }

                    if (!is_params && p.IsOptional)
                    {
                        object value = p.DefaultValue;
                        if (value == Missing.Value)
                        {
                            default_value = EmptyExpression.Null;
                        }
                        else if (value == null)
                        {
                            default_value = new NullLiteral(Location.Null);
                        }
                        else
                        {
                            default_value = Constant.CreateConstant(value.GetType(), value, Location.Null);
                        }
                    }
                }

                par [i] = new ParameterData(p.Name, mod, default_value);
            }

            if (varargs != 0)
            {
                par [par.Length - 1]     = new ArglistParameter(Location.Null);
                types [types.Length - 1] = InternalType.Arglist;
            }

            return(method != null ?
                   new ParametersImported(par, types, varargs != 0, is_params) :
                   new ParametersImported(par, types));
        }