public FieldContext FieldFromTrip(TripField field) { var fc = new FieldContext( field.Name, (short)field.Identifier, //typeConverter.ConvertToString(field.Type), MangleCSharpMethodName(field.Name), MangleCSharpTypeName(field.Name), field.Required == Required.REQUIRED, typeConverter.ConvertToGenType(field.Type) ); return fc; }
private void BuildSerializeListElement(StringBuilder sb, GenType genType, string iter) { var eField = new FieldContext(iter, genType.ElementType); BuildSerializeField(sb, eField, "", true); }
private void BuildSerializeMapElement(StringBuilder sb, GenType genType, string iter, string map) { var kField = new FieldContext(iter, genType.KeyType); BuildSerializeField(sb, kField, "", true); var vField = new FieldContext(map + "[" + iter + "]", genType.ValueType); BuildSerializeField(sb, vField, "", true); }
private void BuildSerializeField(StringBuilder sb, FieldContext field, string prefix = "", bool isElement = false, bool isPropertyLess = false) { var genType = field.GenType; var name = prefix + (isPropertyLess ? "" : PropertyNameFromField(field)); if (genType.IsStruct) { BuildSerializeStruct(sb, name); } else if (genType.IsContainer) { BuildSerializeContainer(sb, name, genType); } else if (genType.IsBaseType || genType.IsEnum) { sb.Indent(level).Append("oprot."); //string nullableName = !isElement ? name + ".Value" : name; string nullableName = name + ".Value"; if (genType.IsBaseType) { switch (genType.GType) { case GType.Binary: sb.Append("WriteBinary(").Append(name).Append(");"); break; case GType.String: sb.Append("WriteString(").Append(name).Append(");"); break; case GType.Bool: sb.Append("WriteBool(").Append(nullableName).Append(");"); break; case GType.Byte: sb.Append("WriteByte(").Append(nullableName).Append(");"); break; case GType.I16: sb.Append("WriteI16(").Append(nullableName).Append(");"); break; case GType.I32: sb.Append("WriteI32(").Append(nullableName).Append(");"); ; break; case GType.I64: sb.Append("WriteI64(").Append(nullableName).Append(");"); break; case GType.Double: sb.Append("WriteDouble(").Append(nullableName).Append(");"); ; break; default: throw new ArgumentException(string.Format("DO NOT KNOW HOW TO SERIALIZE BASE TYPE {0}", genType.GType)); } } else if (genType.IsEnum) { sb.Append("WriteI32((int)").Append(nullableName).Append(");"); } sb.AppendLine(); } else { throw new ArgumentException(string.Format("DO NOT KNOW HOW TO SERIALIZE {0} TYPE {1}", field.Name, genType.CSharpTypeName)); } }
private string PropertyNameFromField(FieldContext field) { if (field.CSharpPropertyName != null) return field.CSharpPropertyName; return field.Name; }
private string DeclareField(FieldContext field, bool init = false, string prefix = "") { string result = field.GenType.CSharpTypeName + " " + prefix + field.Name; if (init) { var genType = field.GenType; if (genType.IsBaseType) { GType gType = genType.GType; switch (gType) { case GType.String: result += " = null"; break; case GType.Bool: result += " = false"; break; case GType.Byte: case GType.I16: case GType.I32: case GType.I64: result += " = 0"; break; case GType.Double: result += " = (double)0"; break; } } else if (genType.IsEnum) { result += " = (" + genType.CSharpTypeName + ")0"; } else if (genType.IsContainer) { result += " = new " + genType.CSharpTypeName + "()"; } else { result += " = new " + genType.CSharpTypeName + "()"; } } return result + ";"; }
private void BuildDeserializeListElement(StringBuilder sb, GenType listType, string prefix = "") { string elem = Tmp("_elem"); var felem = new FieldContext(elem, listType.ElementType); sb.Indent(level).Append(DeclareField(felem, true)).AppendLine(); BuildDeserializeField(sb, felem); sb.Indent(level).Append(prefix).Append(".Add(").Append(elem).Append(");").AppendLine(); }
private void BuildDeserializeMapElement(StringBuilder sb, GenType mapType, string prefix = "") { string key = Tmp("_key"); string val = Tmp("_val"); var fkey = new FieldContext(key, mapType.KeyType); var fval = new FieldContext(val, mapType.ValueType); sb.Indent(level).Append(DeclareField(fkey)).AppendLine(); sb.Indent(level).Append(DeclareField(fval)).AppendLine(); BuildDeserializeField(sb, fkey); BuildDeserializeField(sb, fval); sb.Indent(level).Append(prefix).Append("[").Append(key).Append("] = ").Append(val).Append(";").AppendLine(); }
public void AddField(FieldContext field) { this.Fields.Add(field); }
private void BuildDeserializeField(StringBuilder sb, FieldContext field, string prefix = "", bool isPropertyless = false) { var genType = field.GenType; string name = prefix + (isPropertyless ? "" : PropertyNameFromField(field)); if (genType.IsStruct) { BuildDeserializeStruct(sb, genType.CSharpTypeName, name); } else if (genType.IsContainer) { BuildDeserializeContainer(sb, genType, name); } else if (genType.IsBaseType || genType.IsEnum) { sb.Indent(level).Append(name).Append(" = "); if (genType.IsEnum) { sb.Append("(").Append(genType.CSharpTypeName).Append(")"); } sb.Append("iprot."); if (genType.IsBaseType) { switch (genType.GType) { case GType.Binary: sb.Append("ReadBinary();"); break; case GType.String: sb.Append("ReadString();"); break; case GType.Bool: sb.Append("ReadBool();"); break; case GType.Byte: sb.Append("ReadByte();"); break; case GType.I16: sb.Append("ReadI16();"); break; case GType.I32: sb.Append("ReadI32();"); break; case GType.I64: sb.Append("ReadI64();"); break; case GType.Double: sb.Append("ReadDouble();"); break; default: throw new ArgumentException(string.Format("DO NOT KNOW HOW TO DESERIALIZE BASE TYPE {0}", genType.GType)); } } else if (genType.IsEnum) { sb.Append("ReadI32();"); } sb.AppendLine(); } else { throw new ArgumentException(string.Format("DO NOT KNOW HOW TO DESERIALIZE FIELD {0} TYPE {1}", field.Name, genType.CSharpTypeName)); } }