public override DifferenceType Diff(IDifferences differences, ITypeDefinition impl, ITypeDefinition contract) { if (impl == null || contract == null) { return(DifferenceType.Unknown); } if (!impl.IsEnum || !contract.IsEnum) { return(DifferenceType.Unknown); } ITypeReference implType = impl.GetEnumType(); ITypeReference contractType = contract.GetEnumType(); if (!_typeComparer.Equals(implType, contractType)) { differences.AddTypeMismatchDifference(this, implType, contractType, "Enum type for '{0}' is '{1}' in implementation but '{2}' in the contract.", impl.FullName(), implType.FullName(), contractType.FullName()); return(DifferenceType.Changed); } return(DifferenceType.Unknown); }
private bool ParamNamesAndTypesMatch(IDifferences differences, IMethodDefinition implMethod, IMethodDefinition contractMethod) { int paramCount = implMethod.ParameterCount; Debug.Assert(paramCount == contractMethod.ParameterCount); IParameterDefinition[] implParams = implMethod.Parameters.ToArray(); IParameterDefinition[] contractParams = contractMethod.Parameters.ToArray(); bool match = true; for (int i = 0; i < paramCount; i++) { IParameterDefinition implParam = implParams[i]; IParameterDefinition contractParam = contractParams[i]; if (!implParam.Name.Value.Equals(contractParam.Name.Value)) { differences.AddIncompatibleDifference("DelegateParamNameMustMatch", $"Parameter name on delegate '{implMethod.ContainingType.FullName()}' is '{implParam.Name.Value}' in the {Implementation} but '{contractParam.Name.Value}' in the {Contract}."); match = false; } if (!_typeComparer.Equals(implParam.Type, contractParam.Type)) { differences.AddTypeMismatchDifference("DelegateParamTypeMustMatch", implParam.Type, contractParam.Type, $"Type for parameter '{implParam.Name.Value}' on delegate '{implMethod.ContainingType.FullName()}' is '{implParam.Type.FullName()}' in the {Implementation} but '{contractParam.Type.FullName()}' in the {Contract}."); match = false; } } return(match); }
private bool ParamNamesAndTypesMatch(IDifferences differences, IMethodDefinition implMethod, IMethodDefinition contractMethod) { int paramCount = implMethod.ParameterCount; Contract.Assert(paramCount == contractMethod.ParameterCount); IParameterDefinition[] implParams = implMethod.Parameters.ToArray(); IParameterDefinition[] contractParams = contractMethod.Parameters.ToArray(); bool match = true; for (int i = 0; i < paramCount; i++) { IParameterDefinition implParam = implParams[i]; IParameterDefinition contractParam = contractParams[i]; if (!implParam.Name.Value.Equals(contractParam.Name.Value)) { differences.AddIncompatibleDifference("DelegateParamNameMustMatch", "Parameter name on delegate '{0}' is '{1}' in the implementation but '{2}' in the contract.", implMethod.ContainingType.FullName(), implParam.Name.Value, contractParam.Name.Value); match = false; } if (!_typeComparer.Equals(implParam.Type, contractParam.Type)) { differences.AddTypeMismatchDifference("DelegateParamTypeMustMatch", implParam.Type, contractParam.Type, "Type for parameter '{0}' on delegate '{1}' is '{2}' in the implementation but '{3}' in the contract.", implParam.Name.Value, implMethod.ContainingType.FullName(), implParam.Type.FullName(), contractParam.Type.FullName()); match = false; } } return match; }
private bool ReturnTypesMatch(IDifferences differences, IMethodDefinition implMethod, IMethodDefinition contractMethod) { ITypeReference implReturnType = implMethod.GetReturnType(); ITypeReference contractReturnType = contractMethod.GetReturnType(); if (implReturnType == null || contractReturnType == null) return true; if (!_typeComparer.Equals(implReturnType, contractReturnType)) { differences.AddTypeMismatchDifference("DelegateReturnTypesMustMatch", implReturnType, contractReturnType, "Return type on delegate '{0}' is '{1}' in the implementation but '{2}' in the contract.", implMethod.ContainingType.FullName(), implReturnType.FullName(), contractReturnType.FullName()); return false; } return true; }
private bool ReturnTypesMatch(IDifferences differences, IMethodDefinition implMethod, IMethodDefinition contractMethod) { ITypeReference implReturnType = implMethod.GetReturnType(); ITypeReference contractReturnType = contractMethod.GetReturnType(); if (implReturnType == null || contractReturnType == null) { return(true); } if (!_typeComparer.Equals(implReturnType, contractReturnType)) { differences.AddTypeMismatchDifference("DelegateReturnTypesMustMatch", implReturnType, contractReturnType, $"Return type on delegate '{implMethod.ContainingType.FullName()}' is '{implReturnType.FullName()}' in the {Implementation} but '{contractReturnType.FullName()}' in the {Contract}."); return(false); } return(true); }
public override DifferenceType Diff(IDifferences differences, ITypeDefinition impl, ITypeDefinition contract) { if (impl == null || contract == null) return DifferenceType.Unknown; if (!impl.IsEnum || !contract.IsEnum) return DifferenceType.Unknown; ITypeReference implType = impl.GetEnumType(); ITypeReference contractType = contract.GetEnumType(); if (!_typeComparer.Equals(implType, contractType)) { differences.AddTypeMismatchDifference(this, implType, contractType, "Enum type for '{0}' is '{1}' in implementation but '{2}' in the contract.", impl.FullName(), implType.FullName(), contractType.FullName()); return DifferenceType.Changed; } return DifferenceType.Unknown; }