public virtual CodeWriter Write(Schema.Type type, Value value) { if (!value.IsValid()) { return(Write("null")); } switch (value.Union) { case Value.Unions.@bool: return(Write(value.@bool)); case Value.Unions.float32: return(Write(value.float32)); case Value.Unions.float64: return(Write(value.float64)); case Value.Unions.int8: return(Write(value.int8)); case Value.Unions.uint8: return(Write(value.uint8)); case Value.Unions.int16: return(Write(value.int16)); case Value.Unions.uint16: return(Write(value.uint16)); case Value.Unions.int32: return(Write(value.int32)); case Value.Unions.uint32: return(Write(value.uint32)); case Value.Unions.int64: return(Write(value.int64)); case Value.Unions.uint64: return(Write(value.uint64)); case Value.Unions.text: return(WriteLiteral(value.text.ToString())); case Value.Unions.@enum: return(WriteEnumLiteral(type, value.@enum)); case Value.Unions.list: return(WriteList(value.list.AsList())); case Value.Unions.@struct: return(this.WriteStruct(type, value.@struct)); } throw new NotSupportedException("Cannot write literal value: " + value.Union); }
private void BeginProperty(Schema.Type type, string name, bool nullable) { WriteLine().Write("public "); Write(Format(type)).Write(" ").Write(Escape(name)); Indent(); }
public override string Format(Schema.Type type, bool nullable = false) { if (!type.IsValid()) { return(null); } ulong typeid = 0; switch (type.Union) { case Schema.Type.Unions.anyPointer: return(Format(typeof(Pointer))); case Schema.Type.Unions.@bool: return(nullable ? "bool?" : "bool"); case Schema.Type.Unions.data: return(Format(typeof(Data))); case Schema.Type.Unions.float32: return(nullable ? "float?" : "float"); case Schema.Type.Unions.float64: return(nullable ? "double?" : "double"); case Schema.Type.Unions.int16: return(nullable ? "short?" : "short"); case Schema.Type.Unions.int32: return(nullable ? "int?" : "int"); case Schema.Type.Unions.int64: return(nullable ? "long?" : "long"); case Schema.Type.Unions.int8: return(nullable ? "sbyte?" : "sbyte"); case Schema.Type.Unions.text: return(Format(typeof(Text))); case Schema.Type.Unions.uint16: return(nullable ? "ushort?" : "ushort"); case Schema.Type.Unions.uint32: return(nullable ? "uint?" : "uint"); case Schema.Type.Unions.uint64: return(nullable ? "ulong?" : "ulong"); case Schema.Type.Unions.uint8: return(nullable ? "byte?" : "byte"); case Schema.Type.Unions.@void: return(Format(typeof(void))); case Schema.Type.Unions.@interface: typeid = [email protected]; break; case Schema.Type.Unions.@struct: typeid = [email protected]; break; case Schema.Type.Unions.@enum: typeid = [email protected]; break; } Schema.Node node; if (typeid != 0 && ((Pointer)(node = Lookup(typeid))).IsValid) { if (nullable) { switch (node.Union) { case Schema.Node.Unions.@enum: return(FullyQualifiedName(node) + "?"); case Schema.Node.Unions.@struct: if (node.IsGroup()) { return(FullyQualifiedName(node) + "?"); } break; } } return(FullyQualifiedName(node)); } if (type.Union == Schema.Type.Unions.list) { string el = Format(type.list.elementType); if (!string.IsNullOrWhiteSpace(el)) { return("global::" + typeof(FixedSizeList <>).Namespace + ".FixedSizeList<" + el + ">"); } } return(null); }
public override CodeWriter WriteEnumLiteral(Schema.Type type, ushort value) { return(Write("(").Write(type).Write(")").Write(value)); }
public virtual CodeWriter Write(Schema.Type type) { return(Write(Format(type))); }
public abstract CodeWriter WriteEnumLiteral(Schema.Type type, ushort value);
public abstract string Format(Schema.Type type, bool nullable = false);
public abstract CodeWriter WriteStruct(Schema.Type structType, Pointer @struct);