예제 #1
0
 // to create, use FromXml
 private AssemblyInfo(Project project)
 {
     this.project = project;
 }
예제 #2
0
        public static AssemblyInfo FromXml(Project project, XmlReader reader, Variables vars)
        {
            Debug.Assert(reader.NodeType == XmlNodeType.Element && reader.Name == "Module");

            AssemblyInfo info = new AssemblyInfo(project);

            // pull out the file attribute, but don't process anything empty
            string val = Helper.GetAttribute(reader, "file", vars);

            if (val.Length > 0)
            {
                info.LoadAssembly(val);

                if (AssemblyIsSigned(info.Definition) && project.Settings.KeyFile == null)
                {
                    throw new ApplicationException("Obfuscating a signed assembly would result in an invalid assembly:  " + info.Name + "; use the KeyFile property to set a key to use");
                }
            }
            else
            {
                throw new InvalidOperationException("Need valid file attribute.");
            }

            if (!reader.IsEmptyElement)
            {
                while (reader.Read())
                {
                    if (reader.NodeType == XmlNodeType.Element)
                    {
                        string name = Helper.GetAttribute(reader, "name", vars);

                        string rxStr = Helper.GetAttribute(reader, "rx");
                        Regex  rx    = null;
                        if (!string.IsNullOrEmpty(rxStr))
                        {
                            rx = new Regex(rxStr);
                        }

                        string isStaticStr = Helper.GetAttribute(reader, "static", vars);
                        bool?  isStatic    = null;
                        if (!string.IsNullOrEmpty(isStaticStr))
                        {
                            isStatic = XmlConvert.ToBoolean(isStaticStr);
                        }

                        string isSerializableStr = Helper.GetAttribute(reader, "serializable", vars);
                        bool?  isSerializable    = null;
                        if (!string.IsNullOrEmpty(isSerializableStr))
                        {
                            isSerializable = XmlConvert.ToBoolean(isSerializableStr);
                        }

                        string attrib     = Helper.GetAttribute(reader, "attrib", vars);
                        string inherits   = Helper.GetAttribute(reader, "typeinherits", vars);
                        string type       = Helper.GetAttribute(reader, "type", vars);
                        string typeattrib = Helper.GetAttribute(reader, "typeattrib", vars);

                        switch (reader.Name)
                        {
                        case "SkipNamespace":
                            if (rx != null)
                            {
                                info.skipNamespaces.Add(new NamespaceTester(rx));
                            }
                            else
                            {
                                info.skipNamespaces.Add(new NamespaceTester(name));
                            }
                            break;

                        case "SkipType":
                            TypeSkipFlags skipFlags = TypeSkipFlags.SkipNone;

                            val = Helper.GetAttribute(reader, "skipMethods", vars);
                            if (val.Length > 0 && XmlConvert.ToBoolean(val))
                            {
                                skipFlags |= TypeSkipFlags.SkipMethod;
                            }

                            val = Helper.GetAttribute(reader, "skipStringHiding", vars);
                            if (val.Length > 0 && XmlConvert.ToBoolean(val))
                            {
                                skipFlags |= TypeSkipFlags.SkipStringHiding;
                            }

                            val = Helper.GetAttribute(reader, "skipFields", vars);
                            if (val.Length > 0 && XmlConvert.ToBoolean(val))
                            {
                                skipFlags |= TypeSkipFlags.SkipField;
                            }

                            val = Helper.GetAttribute(reader, "skipProperties", vars);
                            if (val.Length > 0 && XmlConvert.ToBoolean(val))
                            {
                                skipFlags |= TypeSkipFlags.SkipProperty;
                            }

                            val = Helper.GetAttribute(reader, "skipEvents", vars);
                            if (val.Length > 0 && XmlConvert.ToBoolean(val))
                            {
                                skipFlags |= TypeSkipFlags.SkipEvent;
                            }

                            if (rx != null)
                            {
                                info.skipTypes.Add(new TypeTester(rx, skipFlags, attrib, inherits, isStatic, isSerializable));
                            }
                            else
                            {
                                info.skipTypes.Add(new TypeTester(name, skipFlags, attrib, inherits, isStatic, isSerializable));
                            }
                            break;

                        case "SkipMethod":
                            if (rx != null)
                            {
                                info.skipMethods.Add(new MethodTester(rx, type, attrib, typeattrib, inherits, isStatic));
                            }
                            else
                            {
                                info.skipMethods.Add(new MethodTester(name, type, attrib, typeattrib, inherits, isStatic));
                            }
                            break;

                        case "SkipStringHiding":
                            if (rx != null)
                            {
                                info.skipStringHiding.Add(new MethodTester(rx, type, attrib, typeattrib));
                            }
                            else
                            {
                                info.skipStringHiding.Add(new MethodTester(name, type, attrib, typeattrib));
                            }
                            break;

                        case "SkipField":
                            string decorator = Helper.GetAttribute(reader, "decorator", vars);

                            if (rx != null)
                            {
                                info.skipFields.Add(new FieldTester(rx, type, attrib, typeattrib, inherits, decorator, isStatic, isSerializable));
                            }
                            else
                            {
                                info.skipFields.Add(new FieldTester(name, type, attrib, typeattrib, inherits, decorator, isStatic, isSerializable));
                            }
                            break;

                        case "SkipProperty":
                            if (rx != null)
                            {
                                info.skipProperties.Add(new PropertyTester(rx, type, attrib, typeattrib));
                            }
                            else
                            {
                                info.skipProperties.Add(new PropertyTester(name, type, attrib, typeattrib));
                            }
                            break;

                        case "SkipEvent":
                            if (rx != null)
                            {
                                info.skipEvents.Add(new EventTester(rx, type, attrib, typeattrib));
                            }
                            else
                            {
                                info.skipEvents.Add(new EventTester(name, type, attrib, typeattrib));
                            }
                            break;
                        }
                    }
                    else if (reader.NodeType == XmlNodeType.EndElement && reader.Name == "Module")
                    {
                        // hit end of module element...stop reading
                        break;
                    }
                }
            }

            return(info);
        }
예제 #3
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++;
                    }
                }
            }
        }