Пример #1
0
    public override void Execute()
    {
        var initializeMethodFinder = new HandleMethodFinder
        {
            ModuleDefinition = ModuleDefinition,
            AssemblyResolver = AssemblyResolver
        };

        initializeMethodFinder.Execute();

        var stateMachineFinder = new StateMachineTypesFinder
        {
            ModuleDefinition = ModuleDefinition,
        };

        stateMachineFinder.Execute();

        var methodProcessor = new MethodProcessor
        {
            HandleMethodFinder = initializeMethodFinder,
        };

        foreach (var stateMachine in stateMachineFinder.AllTypes)
        {
            try
            {
                var moveNext = stateMachine.Methods.First(x => x.Name == "MoveNext");
                methodProcessor.Process(moveNext);
            }
            catch (Exception exception)
            {
                throw new Exception($"Failed to process '{stateMachine.FullName}'.", exception);
            }
        }
    }
    public void Execute()
    {
        var initializeMethodFinder = new HandleMethodFinder
            {
                ModuleDefinition = ModuleDefinition,
            };
        initializeMethodFinder.Execute();

        var stateMachineFinder = new StateMachineTypesFinder
            {
                ModuleDefinition = ModuleDefinition,
            };
        stateMachineFinder.Execute();

        var methodProcessor = new MethodProcessor
            {
                HandleMethodFinder = initializeMethodFinder,
            };

        foreach (var stateMachine in stateMachineFinder.AllTypes)
        {
            var moveNext = stateMachine.Methods.First(x => x.Name == "MoveNext");
            methodProcessor.Process(moveNext);
        }

    }
Пример #3
0
    void ProcessAssembly(List <TypeDefinition> types)
    {
        var isDebug = IncludeDebugAssert && DefineConstants.Any(c => c == "DEBUG") && ReferenceFinder.DebugAssertMethod != null;

        var methodProcessor   = new MethodProcessor(ValidationFlags, isDebug);
        var propertyProcessor = new PropertyProcessor(ValidationFlags, isDebug);

        foreach (var type in types)
        {
            if (type.IsInterface || type.ContainsAllowNullAttribute() || type.IsGeneratedCode() || type.HasInterface("Windows.UI.Xaml.Markup.IXamlMetadataProvider"))
            {
                continue;
            }

            foreach (var method in type.MethodsWithBody())
            {
                methodProcessor.Process(method);
            }

            foreach (var property in type.ConcreteProperties())
            {
                propertyProcessor.Process(property);
            }
        }
    }
Пример #4
0
    void ProcessMethod(MethodDefinition method)
    {
        if (method.IsYield())
        {
            if (method.ContainsTimeAttribute())
            {
                LogError("Could not process '" + method.FullName + "' since methods that yield are currently not supported. Please remove the [Time] attribute from that method.");
                return;
            }
            LogInfo("Skipping '" + method.FullName + "' since methods that yield are not supported.");
            return;
        }

        if (method.IsAsync())
        {
            var asyncProcessor = new AsyncMethodProcessor
            {
                ModuleWeaver = this,
                Method = method,
            };

            asyncProcessor.Process();
            return;
        }
        var methodProcessor = new MethodProcessor
        {
            ModuleWeaver = this,
            Method = method,
        };

        methodProcessor.Process();
    }
Пример #5
0
    public void Execute()
    {
        var initializeMethodFinder = new HandleMethodFinder
            {
                ModuleDefinition = ModuleDefinition,
                AssemblyResolver = AssemblyResolver
            };
        initializeMethodFinder.Execute();

        var stateMachineFinder = new StateMachineTypesFinder
            {
                ModuleDefinition = ModuleDefinition,
            };
        stateMachineFinder.Execute();

        var methodProcessor = new MethodProcessor
            {
                HandleMethodFinder = initializeMethodFinder,
            };

        foreach (var stateMachine in stateMachineFinder.AllTypes)
        {
            try
            {
                var moveNext = stateMachine.Methods.First(x => x.Name == "MoveNext");
                methodProcessor.Process(moveNext);
            }
            catch (Exception exception)
            {
                throw new Exception($"Failed to process '{stateMachine.FullName}'.", exception);
            }
        }
    }
    public void Execute()
    {
        var initializeMethodFinder = new HandleMethodFinder
        {
            ModuleDefinition = ModuleDefinition,
            AssemblyResolver = AssemblyResolver
        };

        initializeMethodFinder.Execute();

        var stateMachineFinder = new StateMachineTypesFinder
        {
            ModuleDefinition = ModuleDefinition,
        };

        stateMachineFinder.Execute();

        var methodProcessor = new MethodProcessor
        {
            HandleMethodFinder = initializeMethodFinder,
        };

        foreach (var stateMachine in stateMachineFinder.AllTypes)
        {
            var moveNext = stateMachine.Methods.First(x => x.Name == "MoveNext");
            methodProcessor.Process(moveNext);
        }
    }
Пример #7
0
    void ProcessMethod(MethodDefinition method)
    {
        if (method.IsYield())
        {
            if (method.ContainsTimeAttribute())
            {
                LogError("Could not process '" + method.FullName + "' since methods that yield are currently not supported. Please remove the [Time] attribute from that method.");
                return;
            }
            LogInfo("Skipping '" + method.FullName + "' since methods that yield are not supported.");
            return;
        }


        if (method.IsAsync())
        {
            var asyncProcessor = new AsyncMethodProcessor
            {
                ModuleWeaver = this,
                Method       = method,
            };

            asyncProcessor.Process();
            return;
        }
        var methodProcessor = new MethodProcessor
        {
            ModuleWeaver = this,
            Method       = method,
        };

        methodProcessor.Process();
    }
Пример #8
0
 /// <summary>
 /// Run code on all methods in this code
 /// </summary>
 /// <param name="mp">A delegate to run on each method.</param>
 public void MethodProc(MethodProcessor mp)
 {
     foreach (AS3ClassDef c in this.classes)
     {
         c.MethodProc(mp);
     }
 }
Пример #9
0
        internal ForEach(IEnumerable <T> collection, MethodProcessor <T> method, int initialDegreeOfParallelism, AsyncExceptionHandler <T> exceptionHandler)
        {
            _collection       = collection;
            _method           = method;
            _exceptionHandler = exceptionHandler;

            _gate = new AsyncCounterGate(initialDegreeOfParallelism);
        }
Пример #10
0
        private List <UnitTest> GetAvailableUnitTestsNames(object selectedItem)
        {
            var availableUnitTestsNames = new List <UnitTest>();
            var castedSeletedItems      = selectedItem as CheckedListViewItemCollection;

            foreach (ListViewItem item in castedSeletedItems)
            {
                var processor = new MethodProcessor();
                availableUnitTestsNames.AddRange(processor.ProcessMethod(item.Tag as MethodInfo));
            }
            return(availableUnitTestsNames);
        }
Пример #11
0
        public static MarshalProcessor GetMarshaler(MethodProcessor methodProcessor, MethodReturnType parameter)
        {
            var assemblyProcessor = methodProcessor.TypeContext.ModuleContext.AssemblyContext;

            if (!parameter.HasMarshalInfo && parameter.ReturnType.IsValueType)
            {
                return(null);
            }
            if (!parameter.ReturnType.IsValueType && !parameter.HasMarshalInfo)
            {
                return(null);
            }
            var attribute = parameter.MarshalInfo;

            switch (attribute)
            {
            case CustomMarshalInfo c:
                var managedType        = c.ManagedType.Resolve();
                var interfaces         = managedType.Interfaces;
                var marshalerInterface =
                    assemblyProcessor.ImportAssembly.MainModule.GetType("ImpWiz.Import.Marshalers",
                                                                        "IImpWizMarshaler");
                if (interfaces.Any(x =>
                                   x.InterfaceType.Namespace == "System.Runtime.InteropServices" &&
                                   x.InterfaceType.Name == "ICustomMarshaler"))
                {
                    return(new MarshalProcessor(new MarshalerType(assemblyProcessor.ImportAssembly.MainModule.GetType(typeof(ImpWizCustomMarshaler <>).FullName)
                                                                  .MakeGenericInstanceType(c.ManagedType).Resolve()), methodProcessor, parameter));
                }
                else if (marshalerInterface.IsAssignableFrom(managedType))
                {
                    return(new MarshalProcessor(new MarshalerType(managedType), methodProcessor, parameter));
                }

                break;
            }

            if (assemblyProcessor.SupportedMarshalers.TryGetValue((UnmanagedType)attribute.NativeType, out var marshalers))
            {
                return(new MarshalProcessor(marshalers.First(), methodProcessor, parameter));
            }
            return(null);
        }
Пример #12
0
    public void Execute()
    {
        var msCoreReferenceFinder = new ReferenceFinder
            {
                ModuleDefinition = ModuleDefinition,
                AssemblyResolver = AssemblyResolver
            };
        msCoreReferenceFinder.Execute();

        var interceptorFinder = new InterceptorFinder
            {
                ModuleDefinition = ModuleDefinition
            };
        interceptorFinder.Execute();

        var methodProcessor = new MethodProcessor
            {
                referenceFinder = msCoreReferenceFinder,
                typeSystem = ModuleDefinition.TypeSystem, InterceptorFinder = interceptorFinder,
            };
        foreach (var typeDefinition in ModuleDefinition.GetTypes())
        {
            if (typeDefinition.ContainsTimeAttribute())
            {
                methodProcessor.Process(typeDefinition.Methods.Where(x => !x.IsAbstract));
                continue;
            }
            foreach (var method in typeDefinition.Methods)
            {
                if (method.IsAbstract)
                {
                    continue;
                }
                if (!method.ContainsTimeAttribute())
                {
                    continue;
                }
                methodProcessor.Process(method);
            }
        }
    }
Пример #13
0
        protected MarshalProcessor(MarshalerType marshalerType, MethodProcessor methodProcessor, ParameterDefinition param, MethodReturnType retParam)
        {
            if (param == null && retParam == null)
            {
                throw new ArgumentNullException("either '" + nameof(param) + "' or '" + nameof(retParam) + "' must not be null");
            }
            if (param != null && retParam != null)
            {
                throw new InvalidOperationException("either '" + nameof(param) + "' or '" + nameof(retParam) + "' must be null");
            }
            MethodProcessor = methodProcessor;
            Marshaler       = marshalerType.TypeDefinition;
            ReturnParameter = retParam;
            Parameter       = param;
            PInvokeInfo     = methodProcessor.Method.PInvokeInfo;
            if (param != null)
            {
                UnmanagedType = (UnmanagedType)param.MarshalInfo.NativeType;
            }
            else
            {
                UnmanagedType = (UnmanagedType)retParam.MarshalInfo.NativeType;
            }

            var supportedUnmanagedTypes = new HashSet <UnmanagedType>();

            if (!marshalerType.SupportedUnmanagedTypes.Contains(UnmanagedType))
            {
                throw new NotSupportedException($"UnmanagedType: '{UnmanagedType}' not supported by {Marshaler.FullName} marshaler for {methodProcessor.Method.FullName}.");
            }

            var marshalerBaseClass = GetMarshalerBaseClass(Marshaler);

            NativeType  = marshalerBaseClass.GenericArguments[2].Resolve();
            ManagedType = marshalerBaseClass.GenericArguments[3].Resolve();

            MarshalInfoVariableType = marshalerBaseClass.GenericArguments[1].Resolve();

            MethodDefinition fittingCtor = null;
Пример #14
0
    void ProcessMethod(MethodDefinition method)
    {
        if (method.IsYield())
        {
            if (method.ContainsTimeAttribute())
            {
                WriteError("Could not process '" + method.FullName + "' since methods that yield are currently not supported. Please remove the [Time] attribute from that method.");
                return;
            }

            WriteInfo("Skipping '" + method.FullName + "' since methods that yield are not supported.");
            return;
        }

        var timeAttribute = method.GetTimeAttribute();

        if (timeAttribute != null)
        {
            var format = timeAttribute.ConstructorArguments.FirstOrDefault().Value as string;
            if (!string.IsNullOrWhiteSpace(format))
            {
                var hasErrors = false;

                var logWithMessageMethodUsingLong     = LogWithMessageMethodUsingLong;
                var logWithMessageMethodUsingTimeSpan = LogWithMessageMethodUsingTimeSpan;

                if (logWithMessageMethodUsingLong is null && logWithMessageMethodUsingTimeSpan is null)
                {
                    hasErrors = true;
                    WriteError("Feature with parameter formatting is being used, but no useable log method can be found. Either disable the feature usage or update the logger signature to 'public static void Log(MethodBase methodBase, long milliseconds, string message)' or 'public static void Log(MethodBase methodBase, TimeSpan elapsed, string message)'");
                }

                var info = parameterFormattingProcessor.ParseParameterFormatting(format);
                for (var i = 0; i < info.ParameterNames.Count; i++)
                {
                    var parameterName = info.ParameterNames[i];
                    if (string.Equals(parameterName, "this"))
                    {
                        if (method.IsStatic)
                        {
                            hasErrors = true;
                            WriteError($"Could not process '{method.FullName}' because the format uses 'this' in a static context.");
                        }
                    }
                    else
                    {
                        var containsParameter = method.Parameters.Any(x => x.Name.Equals(parameterName));
                        if (!containsParameter)
                        {
                            hasErrors = true;
                            WriteError($"Could not process '{method.FullName}' because the format uses '{parameterName}' which is not available as method parameter.");
                        }
                    }
                }

                if (hasErrors)
                {
                    return;
                }
            }
        }

        if (method.IsAsync())
        {
            var asyncProcessor = new AsyncMethodProcessor
            {
                ModuleWeaver = this,
                Method       = method,
            };

            asyncProcessor.Process();
            return;
        }

        var methodProcessor = new MethodProcessor
        {
            ModuleWeaver = this,
            Method       = method,
        };

        methodProcessor.Process();
    }
Пример #15
0
 /// <summary>
 /// Run code on all methods in this code
 /// </summary>
 /// <param name="mp">A delegate to run on each method.</param>
 public void MethodProc(MethodProcessor mp)
 {
     foreach (AS3ClassDef c in this.classes)
     {
         c.MethodProc(mp);
     }
 }
Пример #16
0
    void ProcessAssembly(List<TypeDefinition> types)
    {
        var isDebug = IncludeDebugAssert && DefineConstants.Any(c => c == "DEBUG") && ReferenceFinder.DebugAssertMethod != null;

        var methodProcessor = new MethodProcessor(ValidationFlags, isDebug);
        var propertyProcessor = new PropertyProcessor(ValidationFlags, isDebug);

        foreach (var type in types)
        {
            if (type.IsInterface || type.ContainsAllowNullAttribute() || type.IsGeneratedCode() || type.HasInterface("Windows.UI.Xaml.Markup.IXamlMetadataProvider"))
                continue;

            foreach (var method in type.MethodsWithBody())
                methodProcessor.Process(method);

            foreach (var property in type.ConcreteProperties())
                propertyProcessor.Process(property);
        }
    }
Пример #17
0
 Processor GetProcessor()
 {
     var proc = new MethodProcessor();
     if (WwwRootDirectory == null)
     {
         proc.RootDirectory = this.GetType().Assembly.Location;
     }
     else
     {
         proc.RootDirectory = WwwRootDirectory;
     }
     return proc;
 }
Пример #18
0
 public IBuilderWithInitialDegreeOfParallelismWhenException <T> Each(MethodProcessor <T> method)
 {
     Method = method ?? throw new ArgumentNullException(nameof(method));
     return(this);
 }
Пример #19
-1
    void ProcessMethod(MethodDefinition method)
    {
        var asyncAttribute = method.CustomAttributes.FirstOrDefault(_ => _.AttributeType.Name == "AsyncStateMachineAttribute");
        if (asyncAttribute == null)
        {
            var methodProcessor = new MethodProcessor
                {
                    ModuleWeaver = this,
                    TypeSystem = ModuleDefinition.TypeSystem,
                    Method = method,
                };
            methodProcessor.InnerProcess();
            return;
        }
        LogError(string.Format("Could not process '{0}'. async methods are not currently supported. Feel free to submit a pull request if you want this feature.", method.FullName));

        //var fullName = method.FullName;
        //var customAttributeArgument = asyncAttribute.ConstructorArguments.First();
        //var typeReference = (TypeReference) customAttributeArgument.Value;
        //var asyncTypeDefinition = typeReference.Resolve();

        //var methodProcessorAsync = new MethodProcessorAsync
        //    {
        //        ModuleWeaver = this,
        //        TypeSystem = ModuleDefinition.TypeSystem,
        //        AsyncTypeReference = asyncTypeDefinition,
        //        OriginalMethod = method
        //    };
        //methodProcessorAsync.Process();
    }