Inheritance: IAssemblyResolver
Example #1
0
        public InheritMap(Project project)
        {
            this.project = project;

            // cache for assemblies not in the project
            AssemblyCache cache = new AssemblyCache (project);
            //string[] lPaths = project.
            cache.ExtraFolders.AddRange (project.ExtraPaths);

            foreach (AssemblyInfo info in project) {
                cache.ExtraFolders.Add (System.IO.Path.GetDirectoryName (info.Filename));
                foreach (TypeDefinition type in info.GetAllTypeDefinitions()) {
                    if (type.FullName == "<Module>")
                        continue;

                    TypeKey typeKey = new TypeKey (type);

                    baseTypes [typeKey] = GetBaseTypes (type);

                    int i = 0;
                    int j;

                    MethodKey[] methods = GetVirtualMethods (cache, type);
                    while (i < methods.Length) {
                        MethodGroup group;
                        if (!methodGroups.TryGetValue (methods [i], out group))
                            group = null;

                        for (j = i + 1; j < methods.Length; j++) {
                            if (!MethodsMatch(methods, i, j))
                                continue;

                            // found an override

                            // see if either method is already in a group
                            if (group != null)
                                group = AddToGroup (group, methods [j]);
                            else if (methodGroups.TryGetValue (methods [j], out group))
                                group = AddToGroup (group, methods [i]);
                            else {
                                group = new MethodGroup ();

                                group = AddToGroup (group, methods [i]);
                                group = AddToGroup (group, methods [j]);
                            }

                            // if the group isn't already external, see if it should be
                            Debug.Assert (group != null, "should have a group by now");
                            if (!group.External && !project.Contains (methods [j].TypeKey))
                                group.External = true;
                        }

                        // if the group isn't already external, see if it should be
                        if (group != null && !group.External && !project.Contains (methods [i].TypeKey))
                            group.External = true;

                        // move on to the next thing that doesn't match
                        i++;
                    }
                }
            }
        }
Example #2
0
        void GetVirtualMethods(AssemblyCache cache, HashSet<MethodKey> methods, TypeDefinition type)
        {
            // check the interfaces
            foreach (TypeReference ifaceRef in type.Interfaces) {
                TypeDefinition iface = project.GetTypeDefinition (ifaceRef);

                // if it's not in the project, try to get it via the cache
                if (iface == null)
                    iface = cache.GetTypeDefinition (ifaceRef);

                // search interface
                if (iface != null)
                    GetVirtualMethods (cache, methods, iface);
            }

            // check the base type unless it isn't in the project, or we don't have one
            TypeDefinition baseType = project.GetTypeDefinition (type.BaseType);

            // if it's not in the project, try to get it via the cache
            if (baseType == null)
                baseType = cache.GetTypeDefinition (type.BaseType);

            // search base
            if (baseType != null)
                GetVirtualMethods (cache, methods, baseType);

            foreach (MethodDefinition method in type.Methods) {
                if (method.IsVirtual)
                    methods.Add (new MethodKey (method));
            }
        }
Example #3
0
 MethodKey[] GetVirtualMethods(AssemblyCache cache, TypeDefinition type)
 {
     HashSet<MethodKey> methods = new HashSet<MethodKey> ();
     GetVirtualMethods (cache, methods, type);
     return new List<MethodKey> (methods).ToArray ();
 }
Example #4
0
 MethodKey[] GetVirtualMethods( AssemblyCache cache, TypeDefinition type )
 {
     C5.TreeSet<MethodKey> methods = new C5.TreeSet<MethodKey>( );
     GetVirtualMethods( cache, methods, type );
     return methods.ToArray( );
 }