public static Dictionary <string, TValue> GetStringMap <TValue>(Core.PropertyInfo property) { CheckContainerType(property, Core.ContainerType.StringMap); var container = (Core.Container <TValue> .StringMap)property.Container; return(container.Item.ToDictionary(kvp => kvp.Key, kvp => kvp.Value)); }
/// <summary> /// Get the single value in a StaticArray property with exactly one element. /// </summary> /// <typeparam name="TValue">Type of the value to get.</typeparam> /// <param name="property">The property whose value to get.</param> /// <returns>The extracted value.</returns> public static TValue GetStaticArrayPropertyValue <TValue>(Core.PropertyInfo property) { CheckContainerType(property, Core.ContainerType.StaticArray); var container = ((Core.Container <TValue> .StaticArray)property.Container).Item; Assert.IsTrue( container.Length == 1, $"Expected a StaticArray containing exactly one element, but found one with {container.Length} in property {property.Name}."); return(container[0]); }
public static List <TValue> GetListValues <TValue>(Core.PropertyInfo property) { CheckContainerType(property, Core.ContainerType.List); return(((Core.Container <TValue> .List)property.Container).Item.ToList()); }
public static List <TValue> GetDynamicArrayValues <TValue>(Core.PropertyInfo property) { CheckContainerType(property, Core.ContainerType.DynamicArray); return(((Core.Container <TValue> .DynamicArray)property.Container).Item.ToList()); }
/// <summary> /// Asserts that a property has a container of a given type. /// </summary> /// <param name="property">The property whose type to check.</param> /// <param name="expectedContainerType">The expected container type.</param> private static void CheckContainerType(Core.PropertyInfo property, Core.ContainerType expectedContainerType) { Assert.IsTrue( property.ContainerType == expectedContainerType, $"Expected container type {expectedContainerType} but found {property.ContainerType} in property {property.Name}."); }
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); }