/// <summary> /// Create the Entity initialization functions. /// </summary> /// <param name="entities"> /// The entities to initialize. /// </param> /// <returns> /// The <see cref="EntityInitializeFunctions"/>. /// </returns> private static EntityInitializeFunctions MakeEntityInitializeFunctions(DataSet dataSet, Dictionary <Entity, Core.Entity> entities) { EntityInitializeFunctions.GetEntityFromAddressDelegate getEntityByAddress = address => entities.FirstOrDefault(e => e.Value.Address == address).Key; Func <string, Data> getEntityByName = dataSet.GetData; return(new EntityInitializeFunctions( getEntityByAddress, entityLink => DataSetUtils.MakeEntityLink(dataSet, entityLink, getEntityByAddress, getEntityByName))); }
private object ExtractPropertyValue <TRaw, TConverted>(Core.PropertyInfo property, Func <TRaw, TConverted> conversionFunc, Core.ContainerType containerType, uint arraySize) { // Non-array if (containerType == Core.ContainerType.StaticArray && arraySize == 1) { var rawValue = DataSetUtils.GetStaticArrayPropertyValue <TRaw>(property); if (conversionFunc == null) { return(rawValue); } var convertedValue = conversionFunc(rawValue); if (property.Type == Core.PropertyInfoType.EntityLink) { // TODO DataIdentifiers var link = convertedValue as EntityLink; if (link.Entity == null) { this.entityLinks.Add(link); } } if (property.Type == Core.PropertyInfoType.FilePtr || property.Type == Core.PropertyInfoType.Path) { this.desiredFiles.Add(new FilePtrEntry(property.Name, null), convertedValue as string); } return(convertedValue); } // Array if (containerType == Core.ContainerType.StaticArray) { var rawValues = DataSetUtils.GetStaticArrayValues <TRaw>(property); if (conversionFunc == null) { return(rawValues); } var convertedValues = (from rawValue in rawValues select conversionFunc(rawValue)).ToList(); if (property.Type == Core.PropertyInfoType.EntityLink) { foreach (var convertedValue in convertedValues) { // TODO DataIdentifiers var link = convertedValue as EntityLink; if (link.Entity == null) { this.entityLinks.Add(link); } } return(convertedValues); } if (property.Type != Core.PropertyInfoType.FilePtr || property.Type == Core.PropertyInfoType.Path) { return(convertedValues); } for (var i = 0; i < convertedValues.Count; i++) { this.desiredFiles.Add(new FilePtrEntry(property.Name, i), convertedValues[i] as string); } return(convertedValues); } if (containerType == Core.ContainerType.DynamicArray) { var rawValues = DataSetUtils.GetDynamicArrayValues <TRaw>(property); if (conversionFunc == null) { return(rawValues); } var convertedValues = (from rawValue in rawValues select conversionFunc(rawValue)).ToList(); if (property.Type == Core.PropertyInfoType.EntityLink) { foreach (var convertedValue in convertedValues) { // TODO DataIdentifiers var link = convertedValue as EntityLink; if (link.Entity == null) { this.entityLinks.Add(link); } } return(convertedValues); } if (property.Type != Core.PropertyInfoType.FilePtr || property.Type == Core.PropertyInfoType.Path) { return(convertedValues); } for (var i = 0; i < convertedValues.Count; i++) { this.desiredFiles.Add(new FilePtrEntry(property.Name, i), convertedValues[i] as string); } return(convertedValues); } if (containerType == Core.ContainerType.List) { var rawValues = DataSetUtils.GetListValues <TRaw>(property); if (conversionFunc == null) { return(rawValues); } var convertedValues = (from rawValue in rawValues select conversionFunc(rawValue)).ToList(); if (property.Type == Core.PropertyInfoType.EntityLink) { foreach (var convertedValue in convertedValues) { // TODO DataIdentifiers var link = convertedValue as EntityLink; if (link.Entity == null) { this.entityLinks.Add(link); } } return(convertedValues); } if (property.Type != Core.PropertyInfoType.FilePtr || property.Type == Core.PropertyInfoType.Path) { return(convertedValues); } for (var i = 0; i < convertedValues.Count; i++) { this.desiredFiles.Add(new FilePtrEntry(property.Name, i), convertedValues[i] as string); } return(convertedValues); } // StringMap if (containerType == Core.ContainerType.StringMap) { var rawValues = DataSetUtils.GetStringMap <TRaw>(property); if (conversionFunc == null) { return(rawValues); } var convertedValues = rawValues.ToDictionary(item => item.Key, item => conversionFunc(item.Value)); if (property.Type == Core.PropertyInfoType.EntityLink) { foreach (var convertedValue in convertedValues) { // TODO DataIdentifiers var link = convertedValue.Value as EntityLink; if (link.Entity == null) { this.entityLinks.Add(link); } } return(convertedValues); } if (property.Type != Core.PropertyInfoType.FilePtr || property.Type == Core.PropertyInfoType.Path) { return(convertedValues); } foreach (var kvp in convertedValues) { this.desiredFiles.Add(new FilePtrEntry(property.Name, kvp.Key), kvp.Value as string); } return(convertedValues); } Assert.IsTrue(false, $"Unrecognized containerType {containerType}"); return(null); }