Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -78,24 +78,27 @@ public override DifferenceType Diff(IDifferences differences, ITypeDefinition im

public override DifferenceType Diff(IDifferences differences, ITypeDefinitionMember impl, ITypeDefinitionMember contract)
{
var implMethod = impl as IMethodDefinition;
var contractMethod = contract as IMethodDefinition;
if (implMethod == null || contractMethod == null)
if (impl == null || contract == null)
return DifferenceType.Unknown;

bool changed = CheckAttributeDifferences(differences, implMethod, implMethod.Attributes, contractMethod.Attributes);

IParameterDefinition[] method1Params = implMethod.Parameters.ToArray();
IParameterDefinition[] method2Params = contractMethod.Parameters.ToArray();
for (int i = 0; i < implMethod.ParameterCount; i++)
changed |= CheckAttributeDifferences(differences, method1Params[i], method1Params[i].Attributes, method2Params[i].Attributes, member: implMethod);
bool changed = CheckAttributeDifferences(differences, impl, impl.Attributes, contract.Attributes);

if (implMethod.IsGeneric)
var implMethod = impl as IMethodDefinition;
var contractMethod = contract as IMethodDefinition;
if (implMethod != null && contractMethod != null)
{
IGenericParameter[] method1GenParams = implMethod.GenericParameters.ToArray();
IGenericParameter[] method2GenParam = contractMethod.GenericParameters.ToArray();
for (int i = 0; i < implMethod.GenericParameterCount; i++)
changed |= CheckAttributeDifferences(differences, method1GenParams[i], method1GenParams[i].Attributes, method2GenParam[i].Attributes, member: implMethod);
IParameterDefinition[] method1Params = implMethod.Parameters.ToArray();
IParameterDefinition[] method2Params = contractMethod.Parameters.ToArray();
for (int i = 0; i < implMethod.ParameterCount; i++)
changed |= CheckAttributeDifferences(differences, method1Params[i], method1Params[i].Attributes, method2Params[i].Attributes, member: implMethod);

if (implMethod.IsGeneric)
{
IGenericParameter[] method1GenParams = implMethod.GenericParameters.ToArray();
IGenericParameter[] method2GenParam = contractMethod.GenericParameters.ToArray();
for (int i = 0; i < implMethod.GenericParameterCount; i++)
changed |= CheckAttributeDifferences(differences, method1GenParams[i], method1GenParams[i].Attributes, method2GenParam[i].Attributes, member: implMethod);
}
}

return changed ? DifferenceType.Changed : DifferenceType.Unchanged;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@ public void AttributeDifferenceIsFound(ApiCompatFrontend frontend)

Assert.Contains("CannotRemoveAttribute : Attribute 'System.ComponentModel.DesignerAttribute' exists on 'AttributeDifference.AttributeDifferenceClass1' in the implementation but not the contract.", runOutput);
Assert.Contains("CannotRemoveAttribute : Attribute 'AttributeDifference.FooAttribute' exists on 'AttributeDifference.AttributeDifferenceClass1' in the implementation but not the contract.", runOutput);
Assert.Contains("CannotRemoveAttribute : Attribute 'AttributeDifference.FooAttribute' exists on 'AttributeDifference.AttributeDifferenceClass1.PropertyWithAttribute' in the implementation but not the contract.", runOutput);
Assert.Contains("CannotRemoveAttribute : Attribute 'AttributeDifference.FooAttribute' exists on 'AttributeDifference.AttributeDifferenceClass1.EventWithAttribute' in the implementation but not the contract.", runOutput);
Assert.Contains("CannotRemoveAttribute : Attribute 'System.ComponentModel.DefaultValueAttribute' exists on generic param 'T' on member 'AttributeDifference.AttributeDifferenceClass1.GenericMethodWithAttribute<T>()' in the implementation but not the contract.", runOutput);
Assert.Contains("CannotRemoveAttribute : Attribute 'System.ComponentModel.DefaultValueAttribute' exists on generic param 'T' on member 'AttributeDifference.AttributeDifferenceClass1.GenericMethodWithAttribute<T>()' in the implementation but not the contract.", runOutput);
Assert.Contains("CannotRemoveAttribute : Attribute 'AttributeDifference.FooAttribute' exists on 'AttributeDifference.AttributeDifferenceClass1.MethodWithAttribute()' in the implementation but not the contract.", runOutput);
Assert.Contains("CannotRemoveAttribute : Attribute 'AttributeDifference.FooAttribute' exists on parameter 'myParameter' on member 'AttributeDifference.AttributeDifferenceClass1.MethodWithAttribute(System.String, System.Object)' in the implementation but not the contract.", runOutput);
Assert.Contains("CannotRemoveAttribute : Attribute 'System.ComponentModel.DefaultValueAttribute' exists on generic param 'TOne' on member 'AttributeDifference.AttributeDifferenceGenericCLass<TOne, TTwo>' in the implementation but not the contract.", runOutput);
Assert.Contains("Total Issues: 6", runOutput);
Assert.Contains("Total Issues: 8", runOutput);
}

[Theory]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ public class AttributeDifferenceClass1
public string MethodWithAttribute(string myParameter, [DefaultValue("myObject")] object myObject) => throw null;
public T GenericMethodWithAttribute<T>() => throw null;
public void MethodWithAttribute() { }
public string PropertyWithAttribute { get; set; }
public event System.EventHandler EventWithAttribute { add { } remove { } }
}
public class AttributeDifferenceGenericCLass<TOne, [DefaultValue("TTwo")] TTwo>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ public class AttributeDifferenceClass1
public T GenericMethodWithAttribute<[DefaultValue("T")] T>() => default(T);
[Foo]
public void MethodWithAttribute() { }
[Foo]
public string PropertyWithAttribute { get; set; }
[Foo]
public event System.EventHandler EventWithAttribute { add { } remove { } }
}

public class AttributeDifferenceGenericCLass<[DefaultValue("TOne")] TOne, [DefaultValue("TTwo")] TTwo>
Expand Down