private static JsonCaseInsensitiveStringDictionary <TValue> StringDictionaryUnion <TValue>( JsonCaseInsensitiveStringDictionary <TValue> thisStringDict, JsonCaseInsensitiveStringDictionary <TValue> thatStringDict, Func <TValue, TValue, object> valueUnionizer = null) where TValue : ICloneable { if (thatStringDict == null) { return(thisStringDict); } if (thisStringDict == null) { return((JsonCaseInsensitiveStringDictionary <TValue>)thatStringDict.Clone()); } foreach (KeyValuePair <string, TValue> item in thatStringDict) { if (!thisStringDict.ContainsKey(item.Key)) { thisStringDict.Add(item.Key, item.Value); continue; } if (valueUnionizer != null) { thisStringDict[item.Key] = (TValue)valueUnionizer(thisStringDict[item.Key], item.Value); } } return(thisStringDict); }
/// <summary> /// Collate an AssemblyData object for a single assembly. /// </summary> /// <param name="asm">the assembly to collect data on.</param> /// <returns>A pair of the name and data of the given assembly.</returns> public static KeyValuePair <string, AssemblyData> AssembleAssembly(Assembly asm) { AssemblyName asmName = asm.GetName(); var asmNameData = new AssemblyNameData() { Name = asmName.Name, Version = asmName.Version, Culture = string.IsNullOrEmpty(asmName.CultureName) ? null : asmName.CultureName, PublicKeyToken = asmName.GetPublicKeyToken(), }; Type[] types = asm.GetTypes(); JsonCaseInsensitiveStringDictionary <JsonCaseInsensitiveStringDictionary <TypeData> > namespacedTypes = null; if (types.Any()) { namespacedTypes = new JsonCaseInsensitiveStringDictionary <JsonCaseInsensitiveStringDictionary <TypeData> >(); foreach (Type type in asm.GetTypes()) { if (!type.IsPublic) { continue; } // Some types don't have a namespace, but we still want to file them string typeNamespace = type.Namespace ?? ""; if (!namespacedTypes.ContainsKey(typeNamespace)) { namespacedTypes.Add(typeNamespace, new JsonCaseInsensitiveStringDictionary <TypeData>()); } TypeData typeData = AssembleType(type); namespacedTypes[typeNamespace][type.Name] = typeData; } } var asmData = new AssemblyData() { AssemblyName = asmNameData, Types = namespacedTypes }; return(new KeyValuePair <string, AssemblyData>(asmName.Name, asmData)); }