Exemplo n.º 1
0
        /// <summary>
        /// Called by project to finish initializing the assembly.
        /// </summary>
        internal void Init( )
        {
            unrenamedReferences = new List <MemberReference>( );
            foreach (MemberReference member in definition.MainModule.MemberReferences)
            {
                if (project.Contains(member.DeclaringType))
                {
                    unrenamedReferences.Add(member);
                }
            }

            unrenamedTypeReferences = new List <TypeReference>( );
            foreach (TypeReference type in definition.MainModule.TypeReferences)
            {
                if (type.FullName == "<Module>")
                {
                    continue;
                }

                if (project.Contains(type))
                {
                    unrenamedTypeReferences.Add(type);
                }
            }

            initialized = true;
        }
Exemplo n.º 2
0
 private void MatchPropertyGroup(PropertyDefinition property, PropertyGroup newGroup, Project project)
 {
     foreach (var baseProperty in type.TypeDefinition.Properties)
     {
         if (PropertyKey.PropertyMatch(baseProperty, property) ||
             PropertyKey.PropertyMatch(property, baseProperty))
         {
             newGroup.Properties.Add(new PropertyKey(type, baseProperty));
             newGroup.External |= !project.Contains(type);
         }
     }
 }
Exemplo n.º 3
0
 private void MatchMethodGroup(MethodDefinition method, MethodGroup newGroup, Project project)
 {
     foreach (var baseMethod in type.TypeDefinition.Methods)
     {
         if (MethodKey.MethodMatch(baseMethod, method) ||
             MethodKey.MethodMatch(method, baseMethod))
         {
             newGroup.Methods.Add(new MethodKey(baseMethod));
             newGroup.External |= !project.Contains(type);
         }
     }
 }
Exemplo n.º 4
0
        /// <summary>
        /// Called by project to finish initializing the assembly.
        /// </summary>
        internal void Init()
        {
            unrenamedReferences = new List <MemberReference>();
            var items = getMemberReferences();

            foreach (MemberReference member in items)
            {
                // FIXME: Figure out why these exist if they are never used.
                // MethodReference mr = member as MethodReference;
                // FieldReference fr = member as FieldReference;
                if (project.Contains(member.DeclaringType))
                {
                    unrenamedReferences.Add(member);
                }
            }

            HashSet <TypeReference> typerefs = new HashSet <TypeReference>();

            foreach (TypeReference type in definition.MainModule.GetTypeReferences())
            {
                if (type.FullName == "<Module>")
                {
                    continue;
                }

                if (project.Contains(type))
                {
                    typerefs.Add(type);
                }
            }

            // Type references in CustomAttributes
            List <CustomAttribute> customattributes = new List <CustomAttribute>();

            customattributes.AddRange(this.Definition.CustomAttributes);
            foreach (TypeDefinition type in GetAllTypeDefinitions())
            {
                customattributes.AddRange(type.CustomAttributes);
                foreach (MethodDefinition methoddef in type.Methods)
                {
                    customattributes.AddRange(methoddef.CustomAttributes);
                }
                foreach (FieldDefinition fielddef in type.Fields)
                {
                    customattributes.AddRange(fielddef.CustomAttributes);
                }
                foreach (EventDefinition eventdef in type.Events)
                {
                    customattributes.AddRange(eventdef.CustomAttributes);
                }
                foreach (PropertyDefinition propertydef in type.Properties)
                {
                    customattributes.AddRange(propertydef.CustomAttributes);
                }

                foreach (CustomAttribute customattribute in customattributes)
                {
                    // Check Constructor and named parameter for argument of type "System.Type". i.e. typeof()
                    List <CustomAttributeArgument> customattributearguments = new List <CustomAttributeArgument>();
                    customattributearguments.AddRange(customattribute.ConstructorArguments);
                    foreach (CustomAttributeNamedArgument namedargument in customattribute.Properties)
                    {
                        customattributearguments.Add(namedargument.Argument);
                    }

                    foreach (CustomAttributeArgument ca in customattributearguments)
                    {
                        if (ca.Type.FullName == "System.Type" && ca.Value != null)
                        {
                            typerefs.Add((TypeReference)ca.Value);
                        }
                    }
                }
                customattributes.Clear();
            }

            unrenamedTypeReferences = new List <TypeReference>(typerefs);

            initialized = true;
        }
Exemplo n.º 5
0
        public InheritMap(Project project)
        {
            this.project = project;

            // cache for assemblies not in the project
            project.Cache = new AssemblyCache(project);

            foreach (AssemblyInfo info in project)
            {
                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(project.Cache, type);
                    while (i < methods.Length)
                    {
                        MethodGroup group;
                        var         left = methods[i];
                        if (!methodGroups.TryGetValue(left, out group))
                        {
                            group = null;
                        }

                        for (j = i + 1; j < methods.Length; j++)
                        {
                            var right = methods[j];
                            if (!MethodsMatch(left, right))
                            {
                                continue;
                            }

                            // found an override

                            // see if either method is already in a group
                            if (group != null)
                            {
                                group = AddToGroup(group, right);
                            }
                            else if (methodGroups.TryGetValue(right, out group))
                            {
                                group = AddToGroup(group, left);
                            }
                            else
                            {
                                group = new MethodGroup();

                                group = AddToGroup(group, left);
                                group = AddToGroup(group, right);
                            }

                            // 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(right.TypeKey))
                            {
                                group.External = true;
                            }
                        }

                        // if the group isn't already external, see if it should be
                        if (group != null && !group.External && !project.Contains(left.TypeKey))
                        {
                            group.External = true;
                        }

                        // move on to the next thing that doesn't match
                        i++;
                    }
                }
            }
        }
Exemplo n.º 6
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++;
                    }
                }
            }
        }