IsDelegateType() public static method

public static IsDelegateType ( System.TypeSpec t ) : bool
t System.TypeSpec
return bool
Ejemplo n.º 1
0
        public override Expression DoResolve(ResolveContext ec)
        {
            if (Arguments == null || Arguments.Count != 1)
            {
                ec.Report.Error(149, loc, "Method name expected");
                return(null);
            }

            Argument a = Arguments [0];

            if (!a.ResolveMethodGroup(ec))
            {
                return(null);
            }

            Expression e = a.Expr;

            AnonymousMethodExpression ame = e as AnonymousMethodExpression;

            if (ame != null && RootContext.Version != LanguageVersion.ISO_1)
            {
                e = ame.Compatible(ec, type);
                if (e == null)
                {
                    return(null);
                }

                return(e.Resolve(ec));
            }

            method_group = e as MethodGroupExpr;
            if (method_group == null)
            {
                if (!TypeManager.IsDelegateType(e.Type))
                {
                    e.Error_UnexpectedKind(ec, ResolveFlags.MethodGroup | ResolveFlags.Type, loc);
                    return(null);
                }

                //
                // An argument is not a method but another delegate
                //
                delegate_instance_expression = e;
                method_group = new MethodGroupExpr(new MemberInfo [] {
                    Delegate.GetInvokeMethod(ec.Compiler, ec.CurrentType, e.Type)
                }, e.Type, loc);
            }

            return(base.DoResolve(ec));
        }
Ejemplo n.º 2
0
        public void SymbolRelatedToPreviousError(MemberInfo mi)
        {
            if (reporting_disabled > 0 || !printer.HasRelatedSymbolSupport)
            {
                return;
            }

            Type dt = TypeManager.DropGenericTypeArguments(mi.DeclaringType);

            if (TypeManager.IsDelegateType(dt))
            {
                SymbolRelatedToPreviousError(dt);
                return;
            }

            DeclSpace temp_ds = TypeManager.LookupDeclSpace(dt);

            if (temp_ds == null)
            {
                SymbolRelatedToPreviousError(dt.Assembly.Location, TypeManager.GetFullNameSignature(mi));
            }
            else
            {
                MethodBase mb = mi as MethodBase;
                if (mb != null)
                {
                    mb = TypeManager.DropGenericMethodArguments(mb);
                    IMethodData md = TypeManager.GetMethod(mb);
                    if (md != null)
                    {
                        SymbolRelatedToPreviousError(md.Location, md.GetSignatureForError());
                    }

                    return;
                }

                // FIXME: Completely wrong, it has to use FindMembers
                MemberCore mc = temp_ds.GetDefinition(mi.Name);
                if (mc != null)
                {
                    SymbolRelatedToPreviousError(mc);
                }
            }
        }
Ejemplo n.º 3
0
Archivo: doc.cs Proyecto: mdae/MonoRT
        //
        // Processes "see" or "seealso" elements.
        // Checks cref attribute.
        //
        private static void HandleXrefCommon(MemberCore mc,
                                             DeclSpace ds, XmlElement xref, Report Report)
        {
            string cref = xref.GetAttribute("cref").Trim(wsChars);

            // when, XmlReader, "if (cref == null)"
            if (!xref.HasAttribute("cref"))
            {
                return;
            }
            if (cref.Length == 0)
            {
                Report.Warning(1001, 1, mc.Location, "Identifier expected");
            }
            // ... and continue until CS1584.

            string signature;        // "x:" are stripped
            string name;             // method invokation "(...)" are removed
            string parameters;       // method parameter list

            // When it found '?:' ('T:' 'M:' 'F:' 'P:' 'E:' etc.),
            // MS ignores not only its member kind, but also
            // the entire syntax correctness. Nor it also does
            // type fullname resolution i.e. "T:List(int)" is kept
            // as T:List(int), not
            // T:System.Collections.Generic.List<System.Int32>
            if (cref.Length > 2 && cref [1] == ':')
            {
                return;
            }
            else
            {
                signature = cref;
            }

            // Also note that without "T:" any generic type
            // indication fails.

            int parens_pos = signature.IndexOf('(');
            int brace_pos  = parens_pos >= 0 ? -1 :
                             signature.IndexOf('[');

            if (parens_pos > 0 && signature [signature.Length - 1] == ')')
            {
                name       = signature.Substring(0, parens_pos).Trim(wsChars);
                parameters = signature.Substring(parens_pos + 1, signature.Length - parens_pos - 2).Trim(wsChars);
            }
            else if (brace_pos > 0 && signature [signature.Length - 1] == ']')
            {
                name       = signature.Substring(0, brace_pos).Trim(wsChars);
                parameters = signature.Substring(brace_pos + 1, signature.Length - brace_pos - 2).Trim(wsChars);
            }
            else
            {
                name       = signature;
                parameters = null;
            }
            Normalize(mc, ref name, Report);

            string identifier = GetBodyIdentifierFromName(name);

            // Check if identifier is valid.
            // This check is not necessary to mark as error, but
            // csc specially reports CS1584 for wrong identifiers.
            string [] name_elems = identifier.Split('.');
            for (int i = 0; i < name_elems.Length; i++)
            {
                string nameElem = GetBodyIdentifierFromName(name_elems [i]);
                if (i > 0)
                {
                    Normalize(mc, ref nameElem, Report);
                }
                if (!Tokenizer.IsValidIdentifier(nameElem) &&
                    nameElem.IndexOf("operator") < 0)
                {
                    Report.Warning(1584, 1, mc.Location, "XML comment on `{0}' has syntactically incorrect cref attribute `{1}'",
                                   mc.GetSignatureForError(), cref);
                    xref.SetAttribute("cref", "!:" + signature);
                    return;
                }
            }

            // check if parameters are valid
            Type [] parameter_types;
            if (parameters == null)
            {
                parameter_types = null;
            }
            else if (parameters.Length == 0)
            {
                parameter_types = Type.EmptyTypes;
            }
            else
            {
                string [] param_list = parameters.Split(',');
                ArrayList plist      = new ArrayList();
                for (int i = 0; i < param_list.Length; i++)
                {
                    string param_type_name = param_list [i].Trim(wsChars);
                    Normalize(mc, ref param_type_name, Report);
                    Type param_type = FindDocumentedType(mc, param_type_name, ds, cref, Report);
                    if (param_type == null)
                    {
                        Report.Warning(1580, 1, mc.Location, "Invalid type for parameter `{0}' in XML comment cref attribute `{1}'",
                                       (i + 1).ToString(), cref);
                        return;
                    }
                    plist.Add(param_type);
                }
                parameter_types = plist.ToArray(typeof(Type)) as Type [];
            }

            Type type = FindDocumentedType(mc, name, ds, cref, Report);

            if (type != null
                // delegate must not be referenced with args
                && (!TypeManager.IsDelegateType(type) ||
                    parameter_types == null))
            {
                string result = GetSignatureForDoc(type)
                                + (brace_pos < 0 ? String.Empty : signature.Substring(brace_pos));
                xref.SetAttribute("cref", "T:" + result);
                return;                 // a type
            }

            int period = name.LastIndexOf('.');

            if (period > 0)
            {
                string typeName    = name.Substring(0, period);
                string member_name = name.Substring(period + 1);
                Normalize(mc, ref member_name, Report);
                type = FindDocumentedType(mc, typeName, ds, cref, Report);
                int warn_result;
                if (type != null)
                {
                    FoundMember fm = FindDocumentedMember(mc, type, member_name, parameter_types, ds, out warn_result, cref, true, name, Report);
                    if (warn_result > 0)
                    {
                        return;
                    }
                    if (!fm.IsEmpty)
                    {
                        MemberInfo mi = fm.Member;
                        // we cannot use 'type' directly
                        // to get its name, since mi
                        // could be from DeclaringType
                        // for nested types.
                        xref.SetAttribute("cref", GetMemberDocHead(mi.MemberType) + GetSignatureForDoc(fm.Type) + "." + member_name + GetParametersFormatted(mi));
                        return;                         // a member of a type
                    }
                }
            }
            else
            {
                int         warn_result;
                FoundMember fm = FindDocumentedMember(mc, ds.TypeBuilder, name, parameter_types, ds, out warn_result, cref, true, name, Report);
                if (warn_result > 0)
                {
                    return;
                }
                if (!fm.IsEmpty)
                {
                    MemberInfo mi = fm.Member;
                    // we cannot use 'type' directly
                    // to get its name, since mi
                    // could be from DeclaringType
                    // for nested types.
                    xref.SetAttribute("cref", GetMemberDocHead(mi.MemberType) + GetSignatureForDoc(fm.Type) + "." + name + GetParametersFormatted(mi));
                    return;                     // local member name
                }
            }

            // It still might be part of namespace name.
            Namespace ns = ds.NamespaceEntry.NS.GetNamespace(name, false);

            if (ns != null)
            {
                xref.SetAttribute("cref", "N:" + ns.GetSignatureForError());
                return;                 // a namespace
            }
            if (GlobalRootNamespace.Instance.IsNamespace(name))
            {
                xref.SetAttribute("cref", "N:" + name);
                return;                 // a namespace
            }

            Report.Warning(1574, 1, mc.Location, "XML comment on `{0}' has cref attribute `{1}' that could not be resolved",
                           mc.GetSignatureForError(), cref);

            xref.SetAttribute("cref", "!:" + name);
        }
Ejemplo n.º 4
0
        protected override Parameters ResolveParameters(EmitContext ec, TypeInferenceContext tic, Type delegateType)
        {
            if (!TypeManager.IsDelegateType(delegateType))
            {
                return(null);
            }

            AParametersCollection d_params = TypeManager.GetDelegateParameters(delegateType);

            if (HasExplicitParameters)
            {
                if (!VerifyExplicitParameters(delegateType, d_params, ec.IsInProbingMode))
                {
                    return(null);
                }

                return(Parameters);
            }

            //
            // If L has an implicitly typed parameter list we make implicit parameters explicit
            // Set each parameter of L is given the type of the corresponding parameter in D
            //
            if (!VerifyParameterCompatibility(delegateType, d_params, ec.IsInProbingMode))
            {
                return(null);
            }

            Type [] ptypes = new Type [Parameters.Count];
            for (int i = 0; i < d_params.Count; i++)
            {
                // D has no ref or out parameters
                if ((d_params.FixedParameters [i].ModFlags & Parameter.Modifier.ISBYREF) != 0)
                {
                    return(null);
                }

                Type d_param = d_params.Types [i];

#if MS_COMPATIBLE
                // Blablabla, because reflection does not work with dynamic types
                if (d_param.IsGenericParameter)
                {
                    d_param = delegateType.GetGenericArguments() [d_param.GenericParameterPosition];
                }
#endif
                //
                // When type inference context exists try to apply inferred type arguments
                //
                if (tic != null)
                {
                    d_param = tic.InflateGenericArgument(d_param);
                }

                ptypes [i] = d_param;
                ((ImplicitLambdaParameter)Parameters.FixedParameters [i]).Type = d_param;
            }

            Parameters.Types = ptypes;
            return(Parameters);
        }