private DifferenceType DiffConstraints(IDifferences differences, IReference target, IEnumerable <IGenericParameter> implGenericParams, IEnumerable <IGenericParameter> contractGenericParams) { int beforeCount = differences.Count(); IGenericParameter[] implParams = implGenericParams.ToArray(); IGenericParameter[] contractParams = contractGenericParams.ToArray(); // We shoudn't hit this because the types/members shouldn't be matched up if they have different generic argument lists if (implParams.Length != contractParams.Length) { return(DifferenceType.Changed); } for (int i = 0; i < implParams.Length; i++) { IGenericParameter implParam = implParams[i]; IGenericParameter contractParam = contractParams[i]; if (contractParam.Variance != TypeParameterVariance.NonVariant && contractParam.Variance != implParam.Variance) { differences.AddIncompatibleDifference("CannotChangeVariance", "Variance on generic parameter '{0}' for '{1}' is '{2}' in the implementation but '{3}' in the contract.", implParam.FullName(), target.FullName(), implParam.Variance, contractParam.Variance); } string implConstraints = string.Join(",", GetConstraints(implParam).OrderBy(s => s, StringComparer.OrdinalIgnoreCase)); string contractConstraints = string.Join(",", GetConstraints(contractParam).OrderBy(s => s, StringComparer.OrdinalIgnoreCase)); if (!string.Equals(implConstraints, contractConstraints)) { differences.AddIncompatibleDifference("CannotChangeGenericConstraints", "Constraints for generic parameter '{0}' for '{1}' is '{2}' in the implementation but '{3}' in the contract.", implParam.FullName(), target.FullName(), implConstraints, contractConstraints); } } if (differences.Count() != beforeCount) { return(DifferenceType.Changed); } return(DifferenceType.Unknown); }
private DifferenceType DiffConstraints(IDifferences differences, IReference target, IEnumerable<IGenericParameter> implGenericParams, IEnumerable<IGenericParameter> contractGenericParams) { int beforeCount = differences.Count(); IGenericParameter[] implParams = implGenericParams.ToArray(); IGenericParameter[] contractParams = contractGenericParams.ToArray(); // We shoudn't hit this because the types/members shouldn't be matched up if they have different generic argument lists if (implParams.Length != contractParams.Length) return DifferenceType.Changed; for (int i = 0; i < implParams.Length; i++) { IGenericParameter implParam = implParams[i]; IGenericParameter contractParam = contractParams[i]; if (contractParam.Variance != TypeParameterVariance.NonVariant && contractParam.Variance != implParam.Variance) { differences.AddIncompatibleDifference("CannotChangeVariance", "Variance on generic parameter '{0}' for '{1}' is '{2}' in the implementation but '{3}' in the contract.", implParam.FullName(), target.FullName(), implParam.Variance, contractParam.Variance); } string implConstraints = string.Join(",", GetConstraints(implParam).OrderBy(s => s)); string contractConstraints = string.Join(",", GetConstraints(contractParam).OrderBy(s => s)); if (!string.Equals(implConstraints, contractConstraints)) { differences.AddIncompatibleDifference("CannotChangeGenericConstraints", "Constraints for generic parameter '{0}' for '{1}' is '{2}' in the implementation but '{3}' in the contract.", implParam.FullName(), target.FullName(), implConstraints, contractConstraints); } } if (differences.Count() != beforeCount) return DifferenceType.Changed; return DifferenceType.Unknown; }