public DetailsStore(SchemaBundle bundle, List <string> serializationOverrides, IFileTree fileTree) { FileTree = fileTree; this.bundle = bundle; var overrideMap = serializationOverrides.Select(@override => { var parts = @override.Split(";"); if (parts.Length != 2) { throw new ArgumentException($"Serialization override malformed: {@override}"); } return(parts[0], parts[1]); }).ToDictionary(pair => pair.Item1, pair => pair.Item2); PopulateBlittableMaps(); BlittableSet = ImmutableHashSet.CreateRange(blittableMap.Where(kv => kv.Value).Select(kv => kv.Key)); var enums = new Dictionary <string, UnityEnumDetails>(); var types = new Dictionary <string, UnityTypeDetails>(); var components = new Dictionary <string, UnityComponentDetails>(); foreach (var file in bundle.SchemaFiles) { foreach (var enumm in file.Enums) { enums.Add(enumm.QualifiedName, new UnityEnumDetails(file.Package.Name, enumm)); } foreach (var type in file.Types) { var typeDetails = new UnityTypeDetails(file.Package.Name, type); if (overrideMap.TryGetValue(typeDetails.FullyQualifiedTypeName, out var staticClassFqn)) { typeDetails.SerializationOverride = new SerializationOverride(staticClassFqn); } types.Add(type.QualifiedName, typeDetails); } foreach (var component in file.Components) { components.Add(component.QualifiedName, new UnityComponentDetails(file.Package.Name, component, this)); } } Enums = new ReadOnlyDictionary <string, UnityEnumDetails>(enums); Types = new ReadOnlyDictionary <string, UnityTypeDetails>(types); Components = new ReadOnlyDictionary <string, UnityComponentDetails>(components); SchemaFiles = bundle.SchemaFiles .Select(file => file.CanonicalPath) .ToList().AsReadOnly(); foreach (var kv in Types) { kv.Value.Populate(this); } foreach (var kv in Components) { kv.Value.PopulateFields(this); } RemoveRecursiveOptions(); }
public DetailsStore(SchemaBundle bundle, IEnumerable <string> serializationOverrides, IFileTree fileTree) { this.bundle = bundle; FileTree = fileTree; Logger.Trace("Loading serialization overrides."); var overrideMap = serializationOverrides.Select(@override => { var parts = @override.Split(";"); if (parts.Length != 2) { throw new ArgumentException($"Serialization override malformed: {@override}"); } Logger.Info($"Found serialization override {parts[1]} for {parts[0]}."); return(parts[0], parts[1]); }).ToDictionary(pair => pair.Item1, pair => pair.Item2); Logger.Trace($"Found {overrideMap.Count} serialization {(overrideMap.Count == 1 ? "override" : "overrides")}."); PopulateBlittableMaps(); BlittableSet = ImmutableHashSet.CreateRange(blittableMap.Where(kv => kv.Value).Select(kv => kv.Key)); var enums = new Dictionary <string, UnityEnumDetails>(); var types = new Dictionary <string, UnityTypeDetails>(); var components = new Dictionary <string, UnityComponentDetails>(); Logger.Trace("Processing schema files."); foreach (var file in bundle.SchemaFiles) { Logger.Trace($"Initialising details from {file.CanonicalPath}."); foreach (var rawEnum in file.Enums) { enums.Add(rawEnum.QualifiedName, new UnityEnumDetails(file.Package.Name, rawEnum)); } foreach (var type in file.Types) { var typeDetails = new UnityTypeDetails(file.Package.Name, type); if (overrideMap.TryGetValue(typeDetails.FullyQualifiedName, out var staticClassFqn)) { typeDetails.SerializationOverride = new SerializationOverride(staticClassFqn); Logger.Trace($"Adding serialization override {staticClassFqn} for {typeDetails.QualifiedName}."); } types.Add(type.QualifiedName, typeDetails); } foreach (var component in file.Components) { components.Add(component.QualifiedName, new UnityComponentDetails(file.Package.Name, component, this)); } Logger.Trace($"Enums added: {file.Enums.Count}."); Logger.Trace($"Types added: {file.Types.Count}."); Logger.Trace($"Components added: {file.Components.Count}."); } Logger.Info($"Processed {bundle.SchemaFiles.Count} schema files."); Enums = new ReadOnlyDictionary <string, UnityEnumDetails>(enums); Types = new ReadOnlyDictionary <string, UnityTypeDetails>(types); Components = new ReadOnlyDictionary <string, UnityComponentDetails>(components); SchemaFiles = bundle.SchemaFiles .Select(file => file.CanonicalPath) .ToList().AsReadOnly(); Logger.Trace($"Retrieved canonical paths of {SchemaFiles.Count} schema files."); Logger.Trace("Populating all type details."); foreach (var kv in Types) { kv.Value.Populate(this); } Logger.Trace($"Populated details of {Types.Count} types."); Logger.Trace($"Populating all component field details."); foreach (var kv in Components) { kv.Value.PopulateFields(this); } Logger.Trace($"Populated field details of {Components.Count} components."); Logger.Trace("Removing all recursive options."); var numFieldsRemoved = RemoveRecursiveOptions(); if (numFieldsRemoved > 0) { Logger.Trace($"Removed {numFieldsRemoved} recursive options."); } }