public string CheckForWarning(PropertyData propertyData, InvokerTypes invokerType) { var propertyDefinition = propertyData.PropertyDefinition; var setMethod = propertyDefinition.SetMethod; if (setMethod.Name == "set_Item" && setMethod.Parameters.Count == 2 && setMethod.Parameters[1].Name == "value") { return("Property is an indexer."); } if (setMethod.Parameters.Count > 1) { return("Property takes more than one parameter."); } if (setMethod.IsAbstract) { return("Property is abstract."); } if (propertyData.BackingFieldReference == null && propertyDefinition.GetMethod == null) { return("Property has no field set logic or it contains multiple sets and the names cannot be mapped to a property."); } if (invokerType == InvokerTypes.BeforeAfter && propertyDefinition.GetMethod == null) { return("When using a before/after invoker the property have a 'get'."); } return(null); }
public string CheckForWarning(PropertyData propertyData, InvokerTypes invokerType) { var propertyDefinition = propertyData.PropertyDefinition; var setMethod = propertyDefinition.SetMethod; if (setMethod.Name == "set_Item" && setMethod.Parameters.Count == 2 && setMethod.Parameters[1].Name == "value") { return "Property is an indexer."; } if (setMethod.Parameters.Count > 1) { return "Property takes more than one parameter."; } if (setMethod.IsAbstract) { return "Property is abstract."; } if ((propertyData.BackingFieldReference == null) && (propertyDefinition.GetMethod == null)) { return "Property has no field set logic or it contains multiple sets and the names cannot be mapped to a property."; } if (invokerType == InvokerTypes.BeforeAfter && (propertyDefinition.GetMethod == null)) { return "When using a before/after invoker the property have a 'get'."; } return null; }
public static IActionInvokerWrapper CreateInvoker(object target, MethodInfo method) { if (method.ReturnType == typeof(void)) { return(CreateReturnVoidInvoker(target, method)); } var parameterTypes = new List <Type>(); parameterTypes.AddRange(method.GetParameters().Select(x => x.ParameterType)); parameterTypes.Add(method.ReturnType); var invokerType = InvokerTypes.SingleOrDefault(x => x.GetGenericArguments().Length == parameterTypes.Count); if (invokerType == null) { throw new ArgumentException(string.Format("Could not create an invoker for the method '{0}'. This type of method is not supported. Try reducing the number of arguments in action.", method)); } invokerType = invokerType.MakeGenericType(parameterTypes.ToArray()); var invokerWrapperType = InvokerWrapperTypes.SingleOrDefault(x => x.GetGenericArguments().Length == parameterTypes.Count); if (invokerWrapperType == null) { throw new ArgumentException(string.Format("Could not create an invoker for the method '{0}'. This type of method is not supported. Try reducing the number of arguments in action.", method)); } invokerWrapperType = invokerWrapperType.MakeGenericType(parameterTypes.ToArray()); var invoker = Delegate.CreateDelegate(invokerType, target, method); var wrapper = Activator.CreateInstance(invokerWrapperType, invoker); return((IActionInvokerWrapper)wrapper); }
void SearchForMethod(TypeDefinition typeDefinition) { var methodDefinition = typeDefinition.Methods.FirstOrDefault(x => x.Name == "Intercept"); if (methodDefinition == null) { throw new WeavingException(string.Format("Found Type '{0}' but could not find a method named 'Intercept'.", typeDefinition.FullName)); } if (!methodDefinition.IsStatic) { throw new WeavingException(string.Format("Found Type '{0}.Intercept' but it is not static.", typeDefinition.FullName)); } if (!methodDefinition.IsPublic) { throw new WeavingException(string.Format("Found Type '{0}.Intercept' but it is not public.", typeDefinition.FullName)); } if (IsSingleStringInterceptionMethod(methodDefinition)) { FoundInterceptor = true; InterceptMethod = methodDefinition; InterceptorType = InvokerTypes.String; return; } if (IsBeforeAfterInterceptionMethod(methodDefinition)) { FoundInterceptor = true; InterceptMethod = methodDefinition; InterceptorType = InvokerTypes.BeforeAfter; return; } var message = string.Format( @"Found '{0}.Intercept' But the signature is not correct. It needs to be either. Intercept(object target, Action firePropertyChanged, string propertyName) or Intercept(object target, Action firePropertyChanged, string propertyName, object before, object after)", typeDefinition.FullName); throw new WeavingException(message); }
void SearchForMethod(TypeDefinition typeDefinition) { var methodDefinition = typeDefinition.Methods.FirstOrDefault(x => x.Name == "Intercept"); if (methodDefinition == null) { throw new WeavingException(string.Format("Found Type '{0}' but could not find a method named 'Intercept'.", typeDefinition.FullName)); } if (!methodDefinition.IsStatic) { throw new WeavingException(string.Format("Found Type '{0}.Intercept' but it is not static.", typeDefinition.FullName)); } if (!methodDefinition.IsPublic) { throw new WeavingException(string.Format("Found Type '{0}.Intercept' but it is not public.", typeDefinition.FullName)); } if (IsSingleStringInterceptionMethod(methodDefinition)) { FoundInterceptor = true; InterceptMethod = methodDefinition; InterceptorType = InvokerTypes.String; return; } if (IsBeforeInterceptionMethod(methodDefinition)) { FoundInterceptor = true; InterceptMethod = methodDefinition; InterceptorType = InvokerTypes.Before; return; } var message = string.Format( @"Found '{0}.Intercept' But the signature is not correct. It needs to be either. Intercept(object target, Action firePropertyChanging, string propertyName) or Intercept(object target, Action firePropertyChanging, string propertyName, object before)", typeDefinition.FullName); throw new WeavingException(message); }