Ejemplo n.º 1
0
        private static void Process(AssemblyDefinition assembly, string regex, List <Optimization> optimizations)
        {
            Console.WriteLine($"    Processing {assembly.FullName}");

            var processed = new ProcessedData();

            foreach (var module in assembly.Modules)
            {
                Process(module, regex, optimizations, ref processed);
                processed.ModuleCount++;
            }

            Console.WriteLine($"      Processed: {processed.ModuleCount} Modules, {processed.TypeCount} Types, {processed.EventCount} Events, {processed.PropertyCount} Properties, {processed.MethodCount} Methods");
        }
Ejemplo n.º 2
0
        private static void Process(TypeDefinition type, string regex, List <Optimization> optimizations, ref ProcessedData processed)
        {
            foreach (var nestedType in type.NestedTypes)
            {
                Process(nestedType, regex, optimizations, ref processed);
                processed.TypeCount++;
            }

            foreach (var @event in type.Events)
            {
                Process(@event, regex, optimizations, ref processed);
                processed.EventCount++;
            }

            foreach (var property in type.Properties)
            {
                Process(property, regex, optimizations, ref processed);
                processed.PropertyCount++;
            }

            foreach (var method in type.Methods)
            {
                Process(method, regex, optimizations, ref processed);
                processed.MethodCount++;
            }
        }
Ejemplo n.º 3
0
        private static void Process(PropertyDefinition property, string regex, List <Optimization> optimizations, ref ProcessedData processed)
        {
            Process(property.GetMethod, regex, optimizations, ref processed);
            Process(property.SetMethod, regex, optimizations, ref processed);

            processed.MethodCount += 2;

            foreach (var otherMethod in property.OtherMethods)
            {
                Process(otherMethod, regex, optimizations, ref processed);
                processed.MethodCount++;
            }
        }
Ejemplo n.º 4
0
 private static void Process(ModuleDefinition module, string regex, List <Optimization> optimizations, ref ProcessedData processed)
 {
     foreach (var type in module.Types)
     {
         Process(type, regex, optimizations, ref processed);
         processed.TypeCount++;
     }
 }
Ejemplo n.º 5
0
        private static void Process(MethodDefinition method, string regex, List <Optimization> optimizations, ref ProcessedData processed)
        {
            if ((method is null) || ((regex != string.Empty) && (Regex.IsMatch(method.FullName, regex) == false)))
            {
                processed.MethodCount--;
                return;
            }

            for (var index = 0; index < optimizations.Count; index++)
            {
                var optimization = optimizations[index];

                try
                {
                    var result = optimization.OptimizeMethod(method, optimization.Parameter);

                    if (result is null)
                    {
                        optimization.SkippedMethodCount++;
                    }
                    else if (result == true)
                    {
                        optimization.UpdatedMethodCount++;
                    }
                    else
                    {
                        optimization.FailedMethodCount++;
                    }
                }
                catch (Exception e)
                {
                    WriteWarning($"Failed to optimize: {method.FullName}");
                    WriteWarning($"    Exception: {e.Message}");
                    optimization.FailedMethodCount++;
                }
            }
        }
Ejemplo n.º 6
0
        private static void Process(EventDefinition @event, string regex, List <Optimization> optimizations, ref ProcessedData processed)
        {
            Process(@event.AddMethod, regex, optimizations, ref processed);
            Process(@event.InvokeMethod, regex, optimizations, ref processed);
            Process(@event.RemoveMethod, regex, optimizations, ref processed);

            processed.MethodCount += 3;

            foreach (var otherMethod in @event.OtherMethods)
            {
                Process(otherMethod, regex, optimizations, ref processed);
                processed.MethodCount++;
            }
        }