private IStructProperty <StructProxy> VisitType( ITypedMemberDescriptor d, TypeTreeParsingContext context) { Type memberType = d.GetMemberType(); if (!typeof(IComponentData).IsAssignableFrom(memberType)) { if (memberType.IsEnum) { // Same hack as below // TODO: this is a hack until we have code gen var propertyType = typeof(EnumPrimitiveProperty <>).MakeGenericType(memberType); return((IStructProperty <StructProxy>)Activator.CreateInstance(propertyType, d)); } if (PrimitiveTypes.Contains(d.GetMemberType())) { var propertyType = typeof(PrimitiveStructProperty <>).MakeGenericType(memberType); return((IStructProperty <StructProxy>)Activator.CreateInstance(propertyType, d)); } if (memberType.IsPrimitive) { throw new NotSupportedException($"Primitive field type {memberType} is not supported"); } } return(new NestedStructProxyProperty(d) { PropertyBag = Parse(memberType, d.Name) }); }
private IPropertyBag DoParse(Type t, TypeTreeParsingContext context, string propertyDisplayName) { if (_propertyBagCache.ContainsKey(t)) { return(_propertyBagCache[t]); } string a = propertyDisplayName; Dictionary <string, IStructProperty <StructProxy> > properties = new Dictionary <string, IStructProperty <StructProxy> >() { { ComponentIdProperty.Name, new TypeIdStructProperty((ref StructProxy c) => a) } }; AddPropertiesFromIterator( new TypeFieldIterator(t).Get(TypeFieldIterator.Specifier.Public | TypeFieldIterator.Specifier.ValueType), context, properties); // TODO: add support for C# auto/non auto properties AddPropertiesFromIterator( new TypePropertyIterator(t).Get(TypePropertyIterator.Specifier.Public | TypePropertyIterator.Specifier.ValueType), context, properties); _propertyBagCache[t] = new StructPropertyBag <StructProxy>(properties.Values.ToList()); return(_propertyBagCache[t]); }
private IPropertyBag DoParse(Type t, TypeTreeParsingContext context) { if (_propertyBagCache.ContainsKey(t)) { return(_propertyBagCache[t]); } Dictionary <string, IStructProperty <StructProxy> > properties = new Dictionary <string, IStructProperty <StructProxy> >() { { ComponentIdProperty.Name, ComponentIdProperty } }; foreach (var member in new TypeFieldIterator(t).Get( TypeFieldIterator.Specifier.Public | TypeFieldIterator.Specifier.ValueType)) { IStructProperty <StructProxy> property = VisitType(member, new TypeTreeParsingContext() { Offset = context.Offset + member.GetOffset() }); if (!properties.ContainsKey(property.Name)) { properties[property.Name] = property; } } foreach (var member in new TypePropertyIterator(t).Get( TypePropertyIterator.Specifier.Public | TypePropertyIterator.Specifier.ValueType)) { try { IStructProperty <StructProxy> property = VisitType(member, new TypeTreeParsingContext() { Offset = context.Offset }); // TODO Unknown types: GameObjects, etc if (property != null) { if (!properties.ContainsKey(property.Name)) { properties[property.Name] = property; } } } catch (Exception) { } } _propertyBagCache[t] = new StructPropertyBag <StructProxy>(properties.Values.ToList()); return(_propertyBagCache[t]); }
private void AddPropertiesFromIterator( IEnumerable <ITypedMemberDescriptor> members, TypeTreeParsingContext context, Dictionary <string, IStructProperty <StructProxy> > properties) { foreach (var member in members) { try { IStructProperty <StructProxy> property = VisitType(member, new TypeTreeParsingContext() { Offset = context.Offset + member.GetOffset() }); if (property != null && !properties.ContainsKey(property.Name)) { properties[property.Name] = property; } } catch (Exception) { } } }