Catel.Fody.Weaving.Argument.ArgumentMethodCallWeaverBase.Execute C# (CSharp) Метод

Execute() публичный Метод

public Execute ( Mono.Cecil.TypeDefinition type, Mono.Cecil.MethodDefinition methodDefinition, object parameterDefinitionOrFieldDefinition, CustomAttribute attribute, int instructionIndex ) : bool
type Mono.Cecil.TypeDefinition
methodDefinition Mono.Cecil.MethodDefinition
parameterDefinitionOrFieldDefinition object
attribute Mono.Cecil.CustomAttribute
instructionIndex int
Результат bool
        public bool Execute(TypeDefinition type, MethodDefinition methodDefinition, object parameterDefinitionOrFieldDefinition, CustomAttribute attribute,
            int instructionIndex)
        {
            TypeReference targetType = null;
            MethodDefinition selectedMethod = null;

            var parameterDefinition = parameterDefinitionOrFieldDefinition as ParameterDefinition;
            if (parameterDefinition != null)
            {
                targetType = parameterDefinition.ParameterType;
            }

            var fieldDefinition = parameterDefinitionOrFieldDefinition as FieldDefinition;
            if (fieldDefinition != null)
            {
                targetType = fieldDefinition.FieldType;
            }

            if (targetType != null)
            {
                try
                {
                    SelectMethod(_argumentTypeDefinition, targetType, out selectedMethod);
                }
                catch (Exception ex)
                {
                    var error = $"[{type.FullName}.{methodDefinition.Name}] {ex.Message}";

                    var sequencePoint = methodDefinition.Body.Instructions[instructionIndex].SequencePoint;
                    if (sequencePoint != null)
                    {
                        FodyEnvironment.LogErrorPoint(error, sequencePoint);
                    }
                    else
                    {
                        FodyEnvironment.LogError(error);
                    }

                    return false;
                }
            }

            if (selectedMethod == null)
            {
                return false;
            }

            var moduleDefinition = type.Module;
            var importedMethod = moduleDefinition.Import(selectedMethod);

            var instructions = new List<Instruction>();

            if (parameterDefinition != null)
            {
                BuildInstructions(moduleDefinition, type, methodDefinition, parameterDefinition, attribute, instructions);
            }

            if (fieldDefinition != null)
            {
                BuildInstructions(moduleDefinition, type, methodDefinition, fieldDefinition, attribute, instructions);
            }

            if (importedMethod.HasGenericParameters)
            {
                var genericInstanceMethod = new GenericInstanceMethod(importedMethod);
                genericInstanceMethod.GenericArguments.Add(targetType);
                instructions.Add(Instruction.Create(OpCodes.Call, genericInstanceMethod));
            }
            else
            {
                instructions.Add(Instruction.Create(OpCodes.Call, importedMethod));
            }

            methodDefinition.Body.Instructions.Insert(instructionIndex, instructions);

            return true;
        }