MethodInjector.AddOnPropertyChangedMethod C# (CSharp) Метод

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

public AddOnPropertyChangedMethod ( TypeDefinition targetType ) : EventInvokerMethod,
targetType TypeDefinition
Результат EventInvokerMethod,
    public EventInvokerMethod AddOnPropertyChangedMethod(TypeDefinition targetType)
    {
        var propertyChangedField = FindPropertyChangedField(targetType);
        if (propertyChangedField == null)
        {
            return null;
        }
        if (interceptorFinder.Found)
        {
            var methodDefinition = GetMethodDefinition(targetType, propertyChangedField);

            return new EventInvokerMethod
                       {
                           MethodReference = InjectInterceptedMethod(targetType, methodDefinition).GetGeneric(),
                           IsBeforeAfter = interceptorFinder.IsBeforeAfter,
                       };
        }
        return new EventInvokerMethod
                   {
                       MethodReference = InjectMethod(targetType, eventInvokerNameResolver.EventInvokerNames.First(), propertyChangedField).GetGeneric(),
                       IsBeforeAfter = false,
                   };
    }

Usage Example

Пример #1
0
    public void Execute()
    {
        foreach (var notifyNode in typeNodeBuilder.NotifyNodes)
        {
            var eventInvoker = RecursiveFindMethod(notifyNode.TypeDefinition);
            if (eventInvoker == null)
            {
                eventInvoker = methodInjector.AddOnPropertyChangedMethod(notifyNode.TypeDefinition);
                if (eventInvoker == null)
                {
                    logger.LogWarning(string.Format(
                                          "\tCould not derive or inject '{0}' into '{1}'. It is possible you are inheriting from a base class and have not correctly set 'WeavingTask.EventInvokerName' or you are using a explicit PropertyChanged event and the event field is not visible to this instance. Please either correct 'WeavingTask.EventInvokerName' or implement your own EventInvoker on this class. No derived types will be processed. If you want to supress this message place a [DoNotNotifyAttribute] on {1}.", string.Join(", ", eventInvokerNameResolver.EventInvokerNames), notifyNode.TypeDefinition.Name));
                    continue;
                }
            }

            notifyNode.EventInvoker = eventInvoker;

            foreach (var childNode in notifyNode.Nodes)
            {
                ProcessChildNode(childNode, eventInvoker);
            }
        }
    }