private string GetPropertyTypeName(MetaPropertyAttribute property) { return(property.ValueType switch { BinPropertyType.Container => GetContainerTypeName(property), BinPropertyType.UnorderedContainer => GetContainerTypeName(property), BinPropertyType.Structure => $"{property.ValueType} : {property.OtherClass}", BinPropertyType.Embedded => $"{property.ValueType} : {property.OtherClass}", BinPropertyType.Optional => GetOptionalTypeName(property), BinPropertyType.Map => GetMapTypeName(property), _ => $"{property.ValueType}" });
// ------------ SERIALIZATION ------------ \\ private static BinTreeProperty ConvertPropertyToTreeProperty(MetaEnvironment environment, object metaClassObject, PropertyInfo propertyInfo) { MetaPropertyAttribute metaPropertyAttribute = propertyInfo.GetCustomAttribute(typeof(MetaPropertyAttribute)) as MetaPropertyAttribute; if (metaPropertyAttribute is null) { throw new InvalidOperationException("The specified property does not have a MetaProperty Attribute"); } object value = propertyInfo.GetValue(metaClassObject); return(ConvertObjectToProperty(environment, metaPropertyAttribute.NameHash, value, propertyInfo.PropertyType)); }
public MetaPropertyViewModel(PropertyInfo metaPropertyInfo) { MetaPropertyAttribute attribute = metaPropertyInfo.GetCustomAttribute <MetaPropertyAttribute>(); if (string.IsNullOrEmpty(attribute.Name)) { this.Name = $"0x{attribute.NameHash:X8}"; } else { this.Name = attribute.Name; } this.Type = GetPropertyTypeName(attribute); }
// ------------ DESERIALIZATION ASSIGNMENT ------------ \\ private static void AssignMetaClassProperties(MetaEnvironment environment, object metaClassObject, Type metaClassType, ICollection <BinTreeProperty> treeProperties) { PropertyInfo[] properties = metaClassType.GetProperties(); foreach (PropertyInfo propertyInfo in properties) { MetaPropertyAttribute metaPropertyAttribute = propertyInfo.GetCustomAttribute(typeof(MetaPropertyAttribute)) as MetaPropertyAttribute; // Ignore non-meta properties if (metaPropertyAttribute is null) { continue; } // Find matching tree property BinTreeProperty treeProperty = treeProperties.FirstOrDefault(x => x.NameHash == metaPropertyAttribute.NameHash); if (treeProperty is not null) // Ignore missing properties { // Assign values to properties AssignMetaProperty(environment, metaClassObject, propertyInfo, treeProperty); } } }