public static string UniqueId(this IReference reference) { Contract.Requires(reference != null); ITypeReference type = reference as ITypeReference; if (type != null) { return(type.DocId()); } ITypeMemberReference member = reference as ITypeMemberReference; if (member != null) { return(member.DocId()); } IUnitNamespaceReference ns = reference as IUnitNamespaceReference; if (ns != null) { return(ns.DocId()); } IAssemblyReference assembly = reference as IAssemblyReference; if (assembly != null) { return(assembly.DocId()); } // Include the hash code as well to make it unique so we can use this for a key return("<Unknown Reference Type>" + reference.GetHashCode().ToString()); }
public static string RefDocId(this IReference reference) { Contract.Requires(reference != null); ITypeReference type = reference as ITypeReference; if (type != null) { return(type.DocId()); } ITypeMemberReference member = reference as ITypeMemberReference; if (member != null) { return(member.DocId()); } IUnitNamespaceReference ns = reference as IUnitNamespaceReference; if (ns != null) { return(ns.DocId()); } IAssemblyReference assembly = reference as IAssemblyReference; if (assembly != null) { return(assembly.DocId()); } Contract.Assert(false, string.Format(CultureInfo.CurrentUICulture, LocalizedStrings.FellThroughCasesIn, "DocIdExtensions.RefDocId()", reference.GetType())); return(LocalizedStrings.UnknownReferenceType); }
public static string RefDocId(this IReference reference) { Contract.Requires(reference != null); ITypeReference type = reference as ITypeReference; if (type != null) { return(type.DocId()); } ITypeMemberReference member = reference as ITypeMemberReference; if (member != null) { return(member.DocId()); } IUnitNamespaceReference ns = reference as IUnitNamespaceReference; if (ns != null) { return(ns.DocId()); } IAssemblyReference assembly = reference as IAssemblyReference; if (assembly != null) { return(assembly.DocId()); } Contract.Assert(false, string.Format("Fell through cases in TypeExtensions.RefDocId() Type of reference: {0}", reference.GetType())); return("<Unknown Reference Type>"); }
private bool IncludeTypeReference(ITypeReference type) { // if a generic type and one of the generic arguments are excluded IGenericTypeInstanceReference genericType = type as IGenericTypeInstanceReference; if (genericType != null && genericType.GenericArguments.Any(genArg => _docIds.Contains(genArg.DocId()))) { return(false); } // if the type itself is excluded string typeId = type.DocId(); return(!_docIds.Contains(typeId)); }
private DifferenceType CheckAttributeDifferences(IDifferences differences, IReference target, IEnumerable <ICustomAttribute> implAttributes, IEnumerable <ICustomAttribute> contractAttributes) { DifferenceType difference = DifferenceType.Unchanged; AttributesMapping <IEnumerable <ICustomAttribute> > attributeMapping = new AttributesMapping <IEnumerable <ICustomAttribute> >(_settings); AttributeComparer attributeComparer = new AttributeComparer(); attributeMapping.AddMapping(0, contractAttributes.OrderBy(a => a, attributeComparer)); attributeMapping.AddMapping(1, implAttributes.OrderBy(a => a, attributeComparer)); foreach (var group in attributeMapping.Attributes) { switch (group.Difference) { case DifferenceType.Added: { ITypeReference type = group.Representative.Attributes.First().Type; if (AttributeFilter.ShouldExclude(type.DocId())) { break; } // Allow for additions differences.Add(new Difference("AddedAttribute", $"Attribute '{type.FullName()}' exists on '{target.FullName()}' in the {Implementation} but not the {Contract}.")); break; } case DifferenceType.Changed: { ITypeReference type = group.Representative.Attributes.First().Type; if (AttributeFilter.ShouldExclude(type.DocId())) { break; } string contractKey = attributeComparer.GetKey(group[0].Attributes.First()); string implementationKey = attributeComparer.GetKey(group[1].Attributes.First()); differences.AddIncompatibleDifference("CannotChangeAttribute", $"Attribute '{type.FullName()}' on '{target.FullName()}' changed from '{contractKey}' in the {Contract} to '{implementationKey}' in the {Implementation}."); difference = DifferenceType.Changed; break; } case DifferenceType.Removed: { ITypeReference type = group.Representative.Attributes.First().Type; if (AttributeFilter.ShouldExclude(type.DocId())) { break; } differences.AddIncompatibleDifference("CannotRemoveAttribute", $"Attribute '{type.FullName()}' exists on '{target.FullName()}' in the {Contract} but not the {Implementation}."); // removals of an attribute are considered a "change" of the type difference = DifferenceType.Changed; break; } } } return(difference); }
private bool CheckAttributeDifferences(IDifferences differences, IReference target, IEnumerable <ICustomAttribute> implAttributes, IEnumerable <ICustomAttribute> contractAttributes, IReference member = null) { AttributesMapping <IEnumerable <ICustomAttribute> > attributeMapping = new AttributesMapping <IEnumerable <ICustomAttribute> >(_settings); AttributeComparer attributeComparer = new AttributeComparer(); attributeMapping.AddMapping(0, contractAttributes.OrderBy(a => a, attributeComparer)); attributeMapping.AddMapping(1, implAttributes.OrderBy(a => a, attributeComparer)); string errString = $"'{target.FullName()}'"; if (target is IParameterDefinition || target is IGenericParameter) { errString = target is IGenericParameter ? "generic param" : "parameter"; errString += $" '{target.FullName()}' on member '{member?.FullName()}'"; } bool changed = false; foreach (var group in attributeMapping.Attributes) { switch (group.Difference) { case DifferenceType.Added: { ITypeReference type = group.Representative.Attributes.First().Type; if (AttributeFilter.ShouldExclude(type.DocId())) { break; } // Allow for additions differences.Add(new Difference("AddedAttribute", $"Attribute '{type.FullName()}' exists on {errString} in the {Implementation} but not the {Contract}.")); changed = true; break; } case DifferenceType.Changed: { ITypeReference type = group.Representative.Attributes.First().Type; if (AttributeFilter.ShouldExclude(type.DocId())) { break; } string contractKey = attributeComparer.GetKey(group[0].Attributes.First()); string implementationKey = attributeComparer.GetKey(group[1].Attributes.First()); differences.AddIncompatibleDifference("CannotChangeAttribute", $"Attribute '{type.FullName()}' on {errString} changed from '{contractKey}' in the {Contract} to '{implementationKey}' in the {Implementation}."); changed = true; break; } case DifferenceType.Removed: { ITypeReference type = group.Representative.Attributes.First().Type; if (AttributeFilter.ShouldExclude(type.DocId())) { break; } differences.AddIncompatibleDifference("CannotRemoveAttribute", $"Attribute '{type.FullName()}' exists on {errString} in the {Contract} but not the {Implementation}."); // removals of an attribute are considered a "change" of the type changed = true; break; } } } return(changed); }