Skip to content

Commit

Permalink
Fixing where the flag is checked
Browse files Browse the repository at this point in the history
  • Loading branch information
distantcam committed Mar 11, 2020
1 parent 7e4253d commit 4b6e332
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
22 changes: 16 additions & 6 deletions PropertyChanged.Fody/OnChangedWalker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ OnChangedMethod FindOnChangedMethod(TypeNode notifyNode, string methodName)

if (foundMethod != null)
{
throw new WeavingException($"The type {notifyNode.TypeDefinition.FullName} has multiple valid overloads of a On_PropertyName_Changed method named {methodName}).");}
throw new WeavingException($"The type {notifyNode.TypeDefinition.FullName} has multiple valid overloads of a On_PropertyName_Changed method named {methodName}).");
}

foundMethod = method;
}
Expand All @@ -115,13 +116,19 @@ OnChangedMethod CreateOnChangedMethod(TypeNode notifyNode, MethodDefinition meth
{
if (methodDefinition.IsStatic)
{
EmitConditionalWarning(methodDefinition, $"The type {notifyNode.TypeDefinition.FullName} has a On_PropertyName_Changed method ({methodDefinition.Name}) which is static.");
if (!SuppressOnPropertyNameChangedWarning)
{
EmitConditionalWarning(methodDefinition, $"The type {notifyNode.TypeDefinition.FullName} has a On_PropertyName_Changed method ({methodDefinition.Name}) which is static.");
}
return null;
}

if (methodDefinition.ReturnType.FullName != "System.Void")
{
EmitConditionalWarning(methodDefinition, $"The type {notifyNode.TypeDefinition.FullName} has a On_PropertyName_Changed method ({methodDefinition.Name}) that has a non void return value. Ensure the return type void.");
if (!SuppressOnPropertyNameChangedWarning)
{
EmitConditionalWarning(methodDefinition, $"The type {notifyNode.TypeDefinition.FullName} has a On_PropertyName_Changed method ({methodDefinition.Name}) that has a non void return value. Ensure the return type void.");
}
return null;
}

Expand Down Expand Up @@ -151,7 +158,7 @@ OnChangedMethod CreateOnChangedMethod(TypeNode notifyNode, MethodDefinition meth
};
}

if (!EventInvokerNames.Contains(methodDefinition.Name))
if (!EventInvokerNames.Contains(methodDefinition.Name) && !SuppressOnPropertyNameChangedWarning)
{
EmitConditionalWarning(methodDefinition, $"Unsupported signature for a On_PropertyName_Changed method: {methodDefinition.Name} in {methodDefinition.DeclaringType.FullName}");
}
Expand Down Expand Up @@ -190,6 +197,9 @@ void ValidateOnChangedMethod(TypeNode notifyNode, MethodDefinition method, bool
{
return;
}
EmitConditionalWarning(method, $"Type {method.DeclaringType.FullName} does not contain a {propertyName} property with an injected change notification, and therefore the {method.Name} method will not be called.");
if (!SuppressOnPropertyNameChangedWarning)
{
EmitConditionalWarning(method, $"Type {method.DeclaringType.FullName} does not contain a {propertyName} property with an injected change notification, and therefore the {method.Name} method will not be called.");
}
}
}
}
4 changes: 2 additions & 2 deletions PropertyChanged.Fody/WarningChecker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public void EmitWarning(string message)

public void EmitConditionalWarning(ICustomAttributeProvider member, string message)
{
if (SuppressWarnings || SuppressOnPropertyNameChangedWarning)
if (SuppressWarnings)
{
return;
}
Expand Down Expand Up @@ -109,4 +109,4 @@ public void EmitConditionalWarning(ICustomAttributeProvider member, string messa

WriteWarning($"{message} You can suppress this warning with [SuppressPropertyChangedWarnings].", sequencePoint);
}
}
}

0 comments on commit 4b6e332

Please sign in to comment.