Beispiel #1
0
        /// <summary>
        ///   C# allows this kind of scenarios:
        ///   interface I { void M (); }
        ///   class X { public void M (); }
        ///   class Y : X, I { }
        ///
        ///   For that case, we create an explicit implementation function
        ///   I.M in Y.
        /// </summary>
        void DefineProxy(Type iface, MethodInfo base_method, MethodInfo iface_method,
                         AParametersCollection param)
        {
            // TODO: Handle nested iface names
            string proxy_name = SimpleName.RemoveGenericArity(iface.FullName) + "." + iface_method.Name;

            MethodBuilder proxy = container.TypeBuilder.DefineMethod(
                proxy_name,
                MethodAttributes.HideBySig |
                MethodAttributes.NewSlot |
                MethodAttributes.CheckAccessOnOverride |
                MethodAttributes.Virtual,
                CallingConventions.Standard | CallingConventions.HasThis,
                base_method.ReturnType, param.GetEmitTypes());

            Type[] gargs = TypeManager.GetGenericArguments(iface_method);
            if (gargs.Length > 0)
            {
                string[] gnames = new string[gargs.Length];
                for (int i = 0; i < gargs.Length; ++i)
                {
                    gnames[i] = gargs[i].Name;
                }

#if GMCS_SOURCE
                proxy.DefineGenericParameters(gnames);
#else
                throw new NotSupportedException();
#endif
            }

            for (int i = 0; i < param.Count; i++)
            {
                string name = param.FixedParameters [i].Name;
                ParameterAttributes attr = ParametersCompiled.GetParameterAttribute(param.FixedParameters [i].ModFlags);
                proxy.DefineParameter(i + 1, attr, name);
            }

            int         top = param.Count;
            ILGenerator ig  = proxy.GetILGenerator();

            for (int i = 0; i <= top; i++)
            {
                ParameterReference.EmitLdArg(ig, i);
            }

            ig.Emit(OpCodes.Call, base_method);
            ig.Emit(OpCodes.Ret);

            container.TypeBuilder.DefineMethodOverride(proxy, iface_method);
        }
Beispiel #2
0
        ///
        /// Used for better error reporting only
        ///
        public Type LookForAnyGenericType(string typeName)
        {
            if (declspaces == null)
            {
                return(null);
            }

            typeName = SimpleName.RemoveGenericArity(typeName);

            foreach (DictionaryEntry de in declspaces)
            {
                string type_item = (string)de.Key;
                int    pos       = type_item.LastIndexOf('`');
                if (pos == typeName.Length && String.Compare(typeName, 0, type_item, 0, pos) == 0)
                {
                    return(((DeclSpace)de.Value).TypeBuilder);
                }
            }
            return(null);
        }
Beispiel #3
0
        public virtual void Error_NamespaceDoesNotExist(DeclSpace ds, Location loc, string name)
        {
            if (name.IndexOf('`') > 0)
            {
                FullNamedExpression retval = Lookup(ds, SimpleName.RemoveGenericArity(name), loc);
                if (retval != null)
                {
                    Error_TypeArgumentsCannotBeUsed(retval, loc);
                    return;
                }
            }
            else
            {
                Type t = LookForAnyGenericType(name);
                if (t != null)
                {
                    Error_InvalidNumberOfTypeArguments(t, loc);
                    return;
                }
            }

            Report.Error(234, loc, "The type or namespace name `{0}' does not exist in the namespace `{1}'. Are you missing an assembly reference?",
                         name, GetSignatureForError());
        }