private static void GetTypePrint(string typeName, Hashtable attributes, StringBuilder printBuilder)
        {
            var t = Type.GetType(typeName);

            if (t == null)
            {
                return;
            }
            var memberAttributes = attributes[t] as Hashtable;

            Debug.Assert(null != memberAttributes);
            var sorter = new StringSorter();

            foreach (string memberName in memberAttributes.Keys)
            {
                sorter.AddString(memberName);
            }
            var sortedMemberNames = sorter.GetOrderedArray();

            foreach (var memberName in sortedMemberNames)
            {
                printBuilder.AppendFormat("**{0}**", memberName);
                Debug.WriteLine("++ Started member thumbprint for type {0}, member:{1}.", typeName, memberName);
                GetXmlAttributesThumbprint(memberAttributes[memberName] as XmlAttributes, printBuilder);
                printBuilder.Append("***");
                Debug.WriteLine("-- Finished member thumbprint for type {0}, member:{1}.", typeName, memberName);
            }
        }
        private static string GetClassThumbprint(XmlAttributeOverrides overrides)
        {
            var types = GetTypesHashtable(overrides);
            // Types are the most significant information
            // in the key ... that why the type info comes first

            // what does the thumbprint of an XmlAttributeOverrides need to
            // consist of?
            // Type names are the key of the outer hashtable
            // The values of the outer hashtable are more hashtables
            // The keys of the inner hashtables are member names. The
            // values of the inner hashtable are XmlAttributes objects.
            // I.e. to create a content-based thumbprint of an
            // XmlAttributeOverrides we need to normalize first the
            // type names, then the member names and finally include the
            // values of each XmlAttributes object in the thumbprint.

            // so my first attempt at a thumbprint looks like this:
            // typeName:memberName:attributes:memberName:attributes:...
            // memberNames are orders alphabetically

            // the complete thumbprint for the XmlAttributeOverrides
            // concatenates the individual thumbrprints for a type in
            // the alphabetical order of the type names.

            var sorter = new StringSorter();

            foreach (Type t in types.Keys)
            {
                sorter.AddString(t.AssemblyQualifiedName);
            }
            var sortedTypeNames = sorter.GetOrderedArray();

            // now we have the types for which we have overriding attributes
            // in alphabetical order

            // Now generate thumbprint for each member of
            // each type
            var printBuilder = new StringBuilder();

            foreach (var typeName in sortedTypeNames)
            {
                Debug.WriteLine(string.Format("+++ Starting thumbprint for type {0}", typeName));
                printBuilder.AppendFormat(">>{0}>>", typeName);
                GetTypePrint(typeName, types, printBuilder);
                printBuilder.Append("<<");
                Debug.WriteLine(string.Format("--- Finished thumbprint for type {0}", typeName));
            }
            return(printBuilder.ToString());
        }
Example #3
0
        public static string GetTypeArraySignature(Type[] types)
        {
            if (null == types || types.Length <= 0)
            {
                return(null);
            }

            // to make sure we don't account for the order
            // of the types in the array, we create one SortedList
            // with the type names, concatenate them and hash that.
            var sorter = new StringSorter();

            foreach (var t in types)
            {
                sorter.AddString(t.AssemblyQualifiedName);
            }
            var thumbPrint = string.Join(":", sorter.GetOrderedArray());

            return(thumbPrint);
        }