Esempio n. 1
0
            IMethod ReadMethod()
            {
                DefaultMethod m = new DefaultMethod(currentClass, ReadString());

                currentMethod = m;
                ReadMember(m);
                int count = reader.ReadByte();

                for (int i = 0; i < count; i++)
                {
                    m.TypeParameters.Add(new DefaultTypeParameter(m, ReadString(), i));
                }
                if (count > 0)
                {
                    foreach (ITypeParameter typeParameter in m.TypeParameters)
                    {
                        count = reader.ReadInt32();
                        for (int i = 0; i < count; i++)
                        {
                            typeParameter.Constraints.Add(ReadType());
                        }
                    }
                }
                else
                {
                    m.TypeParameters = DefaultTypeParameter.EmptyTypeParameterList;
                }
                m.ReturnType        = ReadType();
                m.IsExtensionMethod = reader.ReadBoolean();
                ReadParameters(m);
                currentMethod = null;
                return(m);
            }
Esempio n. 2
0
            void ReadParameters(DefaultMethod m)
            {
                int count = reader.ReadUInt16();

                if (count > 0)
                {
                    ReadParameters(m.Parameters, count);
                }
                else
                {
                    m.Parameters = DefaultParameter.EmptyParameterList;
                }
            }
Esempio n. 3
0
        public override IMember Clone()
        {
            DefaultMethod p = new DefaultMethod(Name, ReturnType, Modifiers, Region, BodyRegion, DeclaringType);

            p.parameters     = DefaultParameter.Clone(this.Parameters);
            p.typeParameters = new List <ITypeParameter>(this.typeParameters);
            p.CopyDocumentationFrom(this);
            p.isExtensionMethod = this.isExtensionMethod;
            foreach (ExplicitInterfaceImplementation eii in InterfaceImplementations)
            {
                p.InterfaceImplementations.Add(eii.Clone());
            }
            return(p);
        }
Esempio n. 4
0
            void AddMethod(MethodDefinition method)
            {
                if (IsVisible(method.Attributes))
                {
                    DefaultMethod m = new DefaultMethod(this, method.IsConstructor ? "#ctor" : method.Name);

                    if (method.GenericParameters.Count > 0)
                    {
                        foreach (GenericParameter g in method.GenericParameters)
                        {
                            m.TypeParameters.Add(new DefaultTypeParameter(m, g.Name, g.Position));
                        }
                        int i = 0;
                        foreach (GenericParameter g in method.GenericParameters)
                        {
                            AddConstraintsFromType(m.TypeParameters[i++], g);
                        }
                    }

                    if (method.IsConstructor)
                    {
                        m.ReturnType = this.DefaultReturnType;
                    }
                    else
                    {
                        m.ReturnType = CreateType(this.ProjectContent, m, method.ReturnType, method.MethodReturnType);
                    }
                    AddAttributes(CompilationUnit.ProjectContent, m, m.Attributes, method);
                    if (this.ClassType == ClassType.Interface)
                    {
                        m.Modifiers = ModifierEnum.Public | ModifierEnum.Abstract;
                    }
                    else
                    {
                        m.Modifiers = TranslateModifiers(method);
                    }
                    AddParameters(m, method.Parameters);
                    AddExplicitInterfaceImplementations(method.Overrides, m);
                    ReflectionLayer.ReflectionMethod.ApplySpecialsFromAttributes(m);
                    Methods.Add(m);
                }
            }
Esempio n. 5
0
        internal static void AddDefaultDelegateMethod(DefaultClass c, IReturnType returnType, IList <IParameter> parameters)
        {
            ModifierEnum  modifiers    = ModifierEnum.Public | ModifierEnum.Synthetic;
            DefaultMethod invokeMethod = new DefaultMethod("Invoke", returnType, modifiers, c.Region, DomRegion.Empty, c);

            foreach (IParameter par in parameters)
            {
                invokeMethod.Parameters.Add(par);
            }
            c.Methods.Add(invokeMethod);
            invokeMethod = new DefaultMethod("BeginInvoke", c.ProjectContent.SystemTypes.IAsyncResult, modifiers, c.Region, DomRegion.Empty, c);
            foreach (IParameter par in parameters)
            {
                invokeMethod.Parameters.Add(par);
            }
            invokeMethod.Parameters.Add(new DefaultParameter("callback", c.ProjectContent.SystemTypes.AsyncCallback, DomRegion.Empty));
            invokeMethod.Parameters.Add(new DefaultParameter("object", c.ProjectContent.SystemTypes.Object, DomRegion.Empty));
            c.Methods.Add(invokeMethod);
            invokeMethod = new DefaultMethod("EndInvoke", returnType, modifiers, c.Region, DomRegion.Empty, c);
            invokeMethod.Parameters.Add(new DefaultParameter("result", c.ProjectContent.SystemTypes.IAsyncResult, DomRegion.Empty));
            c.Methods.Add(invokeMethod);
        }
Esempio n. 6
0
        public static IList <IMethodOrProperty> FindAllExtensions(LanguageProperties language, IClass callingClass, bool searchInAllNamespaces = false)
        {
            if (language == null)
            {
                throw new ArgumentNullException("language");
            }
            if (callingClass == null)
            {
                throw new ArgumentNullException("callingClass");
            }

            HashSet <IMethodOrProperty> res = new HashSet <IMethodOrProperty>();

            bool supportsExtensionMethods    = language.SupportsExtensionMethods;
            bool supportsExtensionProperties = language.SupportsExtensionProperties;

            if (supportsExtensionMethods || supportsExtensionProperties)
            {
                List <ICompletionEntry> list = new List <ICompletionEntry>();
                IMethod dummyMethod          = new DefaultMethod("dummy", callingClass.ProjectContent.SystemTypes.Void,
                                                                 ModifierEnum.Static, DomRegion.Empty, DomRegion.Empty, callingClass);
                CtrlSpaceResolveHelper.AddContentsFromCalling(list, callingClass, dummyMethod);
                if (searchInAllNamespaces)
                {
                    // search extension methods in all referenced projects, no matter the using section
                    CtrlSpaceResolveHelper.AddReferencedProjectsContents(list, callingClass.CompilationUnit, callingClass);
                }
                else
                {
                    CtrlSpaceResolveHelper.AddImportedNamespaceContents(list, callingClass.CompilationUnit, callingClass);
                }

                bool searchExtensionsInClasses = language.SearchExtensionsInClasses;
                foreach (object o in list)
                {
                    IMethodOrProperty mp = o as IMethodOrProperty;
                    if (mp != null && mp.IsExtensionMethod &&
                        (supportsExtensionMethods && o is IMethod || supportsExtensionProperties && o is IProperty))
                    {
                        res.Add(mp);
                    }
                    else if (searchExtensionsInClasses && o is IClass)
                    {
                        IClass c = o as IClass;
                        if (c.HasExtensionMethods)
                        {
                            if (supportsExtensionProperties)
                            {
                                foreach (IProperty p in c.Properties)
                                {
                                    if (p.IsExtensionMethod)
                                    {
                                        res.Add(p);
                                    }
                                }
                            }
                            if (supportsExtensionMethods)
                            {
                                foreach (IMethod m in c.Methods)
                                {
                                    if (m.IsExtensionMethod)
                                    {
                                        res.Add(m);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return(res.ToList());
        } // FindAllExtensions