Пример #1
0
        /// <summary>
        /// Gets the invoke method for a delegate type.
        /// </summary>
        /// <remarks>
        /// Returns null if the type is not a delegate type; or if the invoke method could not be found.
        /// </remarks>
        public static IMethod GetDelegateInvokeMethod(this IType type)
        {
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }
            ITypeDefinition def = type.GetDefinition();

            if (def != null && def.ClassType == ClassType.Delegate)
            {
                foreach (IMethod method in def.Methods)
                {
                    if (method.Name == "Invoke")
                    {
                        ParameterizedType pt = type as ParameterizedType;
                        if (pt != null)
                        {
                            SpecializedMethod m = new SpecializedMethod(method);
                            m.SetDeclaringType(pt);
                            var substitution = pt.GetSubstitution();
                            m.SubstituteTypes(t => new SubstitutionTypeReference(t, substitution));
                            return(m);
                        }
                        return(method);
                    }
                }
            }
            return(null);
        }
Пример #2
0
        public IEnumerable <IMethod> GetConstructors(ITypeResolveContext context, Predicate <IMethod> filter = null)
        {
            Substitution   substitution = new Substitution(typeArguments);
            List <IMethod> methods      = genericType.GetConstructors(context, filter).ToList();

            for (int i = 0; i < methods.Count; i++)
            {
                SpecializedMethod m = new SpecializedMethod(methods[i]);
                m.SetDeclaringType(this);
                m.SubstituteTypes(context, substitution);
                methods[i] = m;
            }
            return(methods);
        }
Пример #3
0
        public IEnumerable <IMethod> GetMethods(ITypeResolveContext context, Predicate <IMethod> filter = null)
        {
            Substitution substitution = new Substitution(typeArguments);
            Func <ITypeReference, ITypeReference> substitutionFunc = t => t.Resolve(context).AcceptVisitor(substitution);
            List <IMethod> methods = genericType.GetMethods(context, filter).ToList();

            for (int i = 0; i < methods.Count; i++)
            {
                SpecializedMethod m = new SpecializedMethod(methods[i]);
                m.SetDeclaringType(this);
                m.SubstituteTypes(substitutionFunc);
                methods[i] = m;
            }
            return(methods);
        }
Пример #4
0
        IMember Specialize(IMember member, Func <ITypeReference, ITypeReference> substitution)
        {
            IMethod method = member as IMethod;

            if (method != null)
            {
                SpecializedMethod m = new SpecializedMethod(method);
                m.SetDeclaringType(this);
                m.SubstituteTypes(substitution);
                return(m);
            }
            IProperty property = member as IProperty;

            if (property != null)
            {
                SpecializedProperty p = new SpecializedProperty(property);
                p.SetDeclaringType(this);
                p.SubstituteTypes(substitution);
                return(p);
            }
            IField field = member as IField;

            if (field != null)
            {
                SpecializedField f = new SpecializedField(field);
                f.SetDeclaringType(this);
                f.ReturnType = substitution(f.ReturnType);
                return(f);
            }
            IEvent ev = member as IEvent;

            if (ev != null)
            {
                SpecializedEvent e = new SpecializedEvent(ev);
                e.SetDeclaringType(this);
                e.ReturnType = substitution(e.ReturnType);
                return(e);
            }
            throw new ArgumentException("Unknown member");
        }