private string ConstructUiElement(ContainedType containedType, string uiElementName, string label, string nestVar, bool newVariable) { var inner = GetUiFieldType(containedType); var builder = new StringBuilder(); if (newVariable) { builder.Append($"var {uiElementName} = "); } else { builder.Append($"{uiElementName} = "); } if (containedType.Category == ValueType.Type) { builder.Append($"new {inner}(\"{label}\", {nestVar} + 1);"); } else { builder.Append($"new {inner}(\"{label}\");"); } return(builder.ToString()); }
private string ContainedTypeToUiFieldUpdate(ContainedType containedType, string uiElementName, string fieldAccessor) { switch (containedType.Category) { case ValueType.Enum: return($"{uiElementName}.value = {fieldAccessor};"); case ValueType.Primitive: var primitiveType = containedType.PrimitiveType.Value; switch (primitiveType) { case PrimitiveType.Int32: case PrimitiveType.Int64: case PrimitiveType.Uint32: case PrimitiveType.Uint64: case PrimitiveType.Sint32: case PrimitiveType.Sint64: case PrimitiveType.Fixed32: case PrimitiveType.Fixed64: case PrimitiveType.Sfixed32: case PrimitiveType.Sfixed64: case PrimitiveType.Float: case PrimitiveType.Double: case PrimitiveType.String: case PrimitiveType.EntityId: case PrimitiveType.Entity: return($"{uiElementName}.value = {fieldAccessor}.ToString();"); case PrimitiveType.Bytes: return($"{uiElementName}.value = global::System.Text.Encoding.Default.GetString({fieldAccessor});"); case PrimitiveType.Bool: return($"{uiElementName}.value = {fieldAccessor};"); case PrimitiveType.Invalid: throw new ArgumentException("Unknown primitive type encountered"); default: throw new ArgumentOutOfRangeException(); } case ValueType.Type: return($"{uiElementName}.Update({fieldAccessor});"); default: throw new ArgumentOutOfRangeException(); } }
private IEnumerable <string> GetFieldInitializer(ContainedType containedType, string uiElementName, string label, string nestVar, bool newVariable = true) { yield return(ConstructUiElement(containedType, uiElementName, label, nestVar, newVariable)); // These lines are part of the func to create an inner list item. if (containedType.Category != ValueType.Type) { yield return($"{uiElementName}.labelElement.ShiftRightMargin({nestVar});"); yield return($"{uiElementName}.SetEnabled(false);"); } if (containedType.Category == ValueType.Enum) { yield return($"{uiElementName}.Init(default({containedType.FqnType}));"); } }
private string GetUiFieldType(ContainedType type) { switch (type.Category) { case ValueType.Enum: return("EnumField"); case ValueType.Primitive: switch (type.PrimitiveType.Value) { case PrimitiveType.Int32: case PrimitiveType.Int64: case PrimitiveType.Uint32: case PrimitiveType.Uint64: case PrimitiveType.Sint32: case PrimitiveType.Sint64: case PrimitiveType.Fixed32: case PrimitiveType.Fixed64: case PrimitiveType.Sfixed32: case PrimitiveType.Sfixed64: case PrimitiveType.Float: case PrimitiveType.Double: case PrimitiveType.String: case PrimitiveType.EntityId: case PrimitiveType.Bytes: case PrimitiveType.Entity: return("TextField"); case PrimitiveType.Bool: return("Toggle"); case PrimitiveType.Invalid: throw new ArgumentException("Unknown primitive type encountered."); default: throw new ArgumentOutOfRangeException(); } case ValueType.Type: return(CalculateRendererFullyQualifiedName(type)); default: throw new ArgumentOutOfRangeException(); } }
// We generate child types inside the parent type (if we don't there will be clashes). // However this means to get the renderer type we can't just grab the FQN, since each intermediate type will // have 'Renderer' appended to it. // // We need to crawl back up the type tree until we find the most-parent type and construct the FQN from // this information. // i.e. - global::{namespace of parent type}.{parent type}Renderer.{child type}Renderer.{child type}Renderer private string CalculateRendererFullyQualifiedName(ContainedType type) { var typeDetails = detailsStore.Types[type.RawType]; var rendererChain = new List <string>(); while (true) { rendererChain.Add($"{typeDetails.Name}Renderer"); if (typeDetails.Parent == null) { break; } typeDetails = typeDetails.Parent; } rendererChain.Reverse(); return($"global::{typeDetails.Namespace}.{string.Join(".", rendererChain)}"); }
private IEnumerable <string> GetFieldInitializer(ContainedType containedType, string uiElementName, string label, bool newVariable = true) { var inner = GetUiFieldType(containedType); if (newVariable) { yield return($"var {uiElementName} = new {inner}(\"{label}\");"); } else { yield return($"{uiElementName} = new {inner}(\"{label}\");"); } // These lines are part of the func to create an inner list item. if (containedType.Category != ValueType.Type) { yield return($"{uiElementName}.SetEnabled(false);"); } if (containedType.Category == ValueType.Enum) { yield return($"{uiElementName}.Init(default({containedType.FqnType}));"); } }
public SingularFieldType(TypeReference innerType, DetailsStore store) { containedType = new ContainedType(innerType); }
public MapFieldType(TypeReference keyType, TypeReference valueType, DetailsStore store) { this.keyType = new ContainedType(keyType); this.valueType = new ContainedType(valueType); }
public OptionFieldType(TypeReference innerType, DetailsStore store) { containedType = new ContainedType(innerType); }
public OptionFieldType(FieldDefinitionRaw.OptionTypeRaw optionTypeRaw, HashSet <string> enumSet) { containedType = new ContainedType(optionTypeRaw.valueType, enumSet); }
public SingularFieldType(TypeReferenceRaw typeReferenceRaw, HashSet <string> enumSet) { containedType = new ContainedType(typeReferenceRaw, enumSet); }
public MapFieldType(FieldDefinitionRaw.MapTypeRaw mapTypeRaw, HashSet <string> enumSet) { keyType = new ContainedType(mapTypeRaw.keyType, enumSet); valueType = new ContainedType(mapTypeRaw.valueType, enumSet); }
public ListFieldType(FieldDefinitionRaw.ListTypeRaw listTypeRaw, HashSet <string> enumSet) { containedType = new ContainedType(listTypeRaw.valueType, enumSet); }
public SingularFieldType(Field.InnerType innerType, DetailsStore store) { containedType = new ContainedType(innerType, store); }
public MapFieldType(Field.InnerType keyType, Field.InnerType valueType, DetailsStore store) { this.keyType = new ContainedType(keyType, store); this.valueType = new ContainedType(valueType, store); }
public OptionFieldType(Field.InnerType innerType, DetailsStore store) { containedType = new ContainedType(innerType, store); }