示例#1
0
        /// <summary>
        /// Fix the given mscorlib.dll assembly.
        /// </summary>
        internal static void Fix(string assemblyPath)
        {
            var resolver = new AssemblyResolver(new[] { Path.GetDirectoryName(assemblyPath) });
            var assembly = resolver.Resolve(Path.GetFileNameWithoutExtension(assemblyPath), new ReaderParameters(ReadingMode.Immediate) { ReadSymbols = false });

            assembly.Name.Name = "mscorlib";
            assembly.Write(assemblyPath);
        }
示例#2
0
        /// <summary>
        /// Find all API enhancements
        /// </summary>
        internal static void Find(string assemblyPath)
        {
            var resolver = new AssemblyResolver(new[] { Path.GetDirectoryName(assemblyPath) });
            var assembly = resolver.Resolve(Path.GetFileNameWithoutExtension(assemblyPath), new ReaderParameters(ReadingMode.Immediate) { ReadSymbols = false });

            FindListenerInterfaces.Find(assembly);
            FindRunnableArguments.Find(assembly);
        }
示例#3
0
 private static List<TypeDefinition> CollectExceptions(string frameworkFolder)
 {
     var resolver = new AssemblyResolver(new[] { frameworkFolder });
     var assembly = resolver.Resolve("Dot42");
     var list = new List<TypeDefinition>();
     foreach (var type in assembly.MainModule.Types)
     {
         CollectExceptions(type, list);
     }
     return list.Distinct().OrderBy(x => x.FullName).ToList();
 }
        /// <summary>
        /// Check the given dot42.dll wrt forward assemblies.
        /// </summary>
        internal static void Check(string assemblyPath)
        {
            // Load dot42.dll
            var resolver = new AssemblyResolver(new[] { Path.GetDirectoryName(assemblyPath) }) { ShowLoading = false };
            var readerParameters = new ReaderParameters(ReadingMode.Immediate) { ReadSymbols = false, AssemblyResolver = resolver};

            var dot42 = resolver.Resolve(Path.GetFileNameWithoutExtension(assemblyPath), readerParameters);

            // Load forward assemblies
            var fwAssemblies = new List<AssemblyDefinition>();
            var folder = Path.GetDirectoryName(assemblyPath);
            foreach (var path in Directory.GetFiles(folder, "*.dll"))
            {
                var name = Path.GetFileNameWithoutExtension(path);
                if (string.Equals(name, dot42.Name.Name, StringComparison.OrdinalIgnoreCase))
                    continue;

                var fwAssembly = resolver.Resolve(name, readerParameters);
                fwAssemblies.Add(fwAssembly);
            }

            var existingCount = 0;
            var missingCount = 0;
            // Go over all types
            foreach (var type in dot42.MainModule.Types)
            {
                if (!type.IsPublic)
                    continue;
                if (!type.Namespace.StartsWith("System"))
                    continue;
                if (HasForwarder(type, fwAssemblies))
                {
                    existingCount++;
                    continue;
                }

                Console.WriteLine("Missing forwarder for {0}", type.FullName);
                missingCount++;
            }

            Console.WriteLine("{0} forwarders missing, {1} found.", missingCount, existingCount);
        }
示例#5
0
        /// <summary>
        /// Generate the enums
        /// </summary>
        internal static void Generate(string assemblyPath, string outputFolder, string[] enumTypeNames)
        {
            var resolver = new AssemblyResolver(new[] { Path.GetDirectoryName(assemblyPath) });
            var assembly = resolver.Resolve(Path.GetFileNameWithoutExtension(assemblyPath));

            foreach (var name in enumTypeNames)
            {
                var type = assembly.MainModule.GetType(name);
                var values = type.Fields.Where(x => x.IsStatic).Select(x => string.Format("Tuple.Create({0}, \"{1}\")", (int)x.Constant, x.Name));

                var src = Template;
                src = src.Replace("$ns$", type.Namespace);
                src = src.Replace("$name$", type.Name);
                src = src.Replace("$values$", string.Join(",\n", values));

                var outputPath = Path.Combine(outputFolder, type.Name + ".cs");
                var existing = File.Exists(outputPath) ? File.ReadAllText(outputPath) : string.Empty;
                if (src != existing)
                {
                    Directory.CreateDirectory(Path.GetDirectoryName(outputPath));
                    File.WriteAllText(outputPath, src);
                }
            }
        }