private static void Append(this HashAlgorithm algorithm, Type value, AttributeBehavior attributeBehavior, bool isFinalAppend = false) { algorithm.Append(TypePrefix); if (value.IsGenericType) { algorithm.Append(ExplicitTrue); } else { algorithm.Append(ExplicitFalse); } if (value.IsGenericTypeDefinition) { algorithm.Append(ExplicitTrue); } else { algorithm.Append(ExplicitFalse); } // TODO Add more explicit type info for generic versions if (value.IsGenericParameter) { algorithm.Append(ExplicitTrue); } else { algorithm.Append(ExplicitFalse); } if (value.ContainsGenericParameters) { algorithm.Append(ExplicitTrue); } else { algorithm.Append(ExplicitFalse); } if (value.IsArray) { algorithm.Append(ExplicitTrue); algorithm.AppendType(value.GetElementType()); } else { algorithm.Append(ExplicitFalse); } algorithm.AppendMemberInfo(value, attributeBehavior, isFinalAppend); }
private static void AppendMemberInfo(this HashAlgorithm algorithm, MemberInfo value, AttributeBehavior attributeBehavior, bool isFinalAppend = false) { algorithm.Append((int)value.MemberType); int attributeCount = 0; if (attributeBehavior == AttributeBehavior.Include) { foreach (var a in value.GetCustomAttributes <Attribute>()) { algorithm.Append(a); ++attributeCount; } } // Always add the attribute count. This way a type without any attributes hashes the same no matter what the parameter says algorithm.Append(attributeCount); algorithm.Append(value.Name, isFinalAppend); }