Пример #1
0
        public Instruction GetActionInvocation(LambdaExpression methodSelector)
        {
            if (methodSelector == null)
            {
                Globals.Loggers.File.Error("[InstructionBuilders].[Type].[GetActionInvocation] is throwing exception ([methodSelector] == [null]).");
                throw new ArgumentNullException("methodSelector");
            }

            var methodName = methodSelector.GetMethodInfo().Name;
            var methodDefinition = TypeDefinition.Methods.FirstOrDefault(m => m.Name == methodName);
            var methodReference = Processor.Body.Method.Module.Import(methodDefinition);

            if (methodDefinition == null)
            {
                Globals.Loggers.File.Error("[InstructionBuilders].[Type].[GetActionInvocation] is throwing exception ([methodDefinition] == [null]).");
                throw new ArgumentException("[methodSelector] has returned non existing method name.");
            }

            var result = Processor.Create(OpCodes.Callvirt, methodReference);
            return result;
        }