/// <summary> /// Indicates whether this instance and a specified <see cref="MetadataName"/> are equal. /// </summary> /// <param name="other"></param> public bool Equals(MetadataName other) { if (IsDefault) { return(other.IsDefault); } if (other.IsDefault) { return(false); } if (!string.Equals(Name, other.Name, StringComparison.Ordinal)) { return(false); } if (!ContainingTypes.SequenceEqual(other.ContainingTypes, StringComparer.Ordinal)) { return(false); } if (!ContainingNamespaces.SequenceEqual(other.ContainingNamespaces, StringComparer.Ordinal)) { return(false); } return(true); }
/// <summary> /// Returns the hash code for this instance. /// </summary> /// <returns>A 32-bit signed integer that is the hash code for this instance.</returns> public override int GetHashCode() { if (IsDefault) { return(0); } int hashCode = Hash.Create(GetHashCode(Name)); ImmutableArray <string> .Enumerator en = ContainingTypes.GetEnumerator(); if (en.MoveNext()) { while (true) { hashCode = Combine(en.Current); if (en.MoveNext()) { hashCode = Hash.Combine(PlusHashCode, hashCode); } else { break; } } } en = ContainingNamespaces.GetEnumerator(); if (en.MoveNext()) { while (true) { hashCode = Combine(en.Current); if (en.MoveNext()) { hashCode = Hash.Combine(DotHashCode, hashCode); } else { break; } } } return(hashCode); int Combine(string name) { return(Hash.Combine(GetHashCode(name), hashCode)); } }
internal string ToString(SymbolDisplayTypeQualificationStyle typeQualificationStyle) { if (IsDefault) { return(""); } switch (typeQualificationStyle) { case SymbolDisplayTypeQualificationStyle.NameOnly: { return(Name); } case SymbolDisplayTypeQualificationStyle.NameAndContainingTypes: { if (ContainingTypes.Any()) { return(string.Join("+", ContainingTypes) + "+" + Name); } return(Name); } case SymbolDisplayTypeQualificationStyle.NameAndContainingTypesAndNamespaces: { if (ContainingNamespaces.Any()) { string @namespace = string.Join(".", ContainingNamespaces); if (ContainingTypes.Any()) { return(@namespace + "." + string.Join("+", ContainingTypes) + "+" + Name); } else { return(@namespace + "." + Name); } } else if (ContainingTypes.Any()) { return(string.Join("+", ContainingTypes) + "+" + Name); } return(Name); } } throw new ArgumentException($"Unknown enum value '{typeQualificationStyle}'.", nameof(typeQualificationStyle)); }
public AssemblyTypeInfo(Assembly asm) { ContainingAssembly = asm; ContainingTypes.AddRange(asm.GetExportedTypes()); }