private void FixVoidReturns(TLSchema schema) { foreach (var method in schema.Methods.Where(method => !schema.Types.Contains(method.Type))) { method.Type = _tlTypesCache["void"]; } }
private void SetBuiltInTypeNames(TLSchema schema) { foreach (TLCombinatorParameter parameter in schema.Constructors.SelectMany(constructor => constructor.Parameters)) { FixType(parameter.Type, schema); } }
public static string CompileFromJson(string json, string defaultNamespace) { var compiler = new TLSchemaCompiler(defaultNamespace); TLSchema schema = compiler.GetTLSchemaFromJson(json); return(compiler.Compile(schema)); }
public static string CompileFromTL(string tl, string defaultNamespace) { var compiler = new TLSchemaCompiler(defaultNamespace); TLSchema schema = compiler.GetTLSchemaFromTL(tl); return(compiler.Compile(schema)); }
protected string Compile(TLSchema schema) { SetBuiltInTypeNames(schema); FixVoidReturns(schema); var template = new SharpTLDefaultTemplate(new TemplateVars { Schema = schema, Namespace = _defaultNamespace }); return(template.TransformText()); }
public TLSchema GetTLSchemaFromJson(string json) { JsonObject tlSchemaJsonObject = JsonObject.Parse(json); List <TLCombinator> constructors = CreateConstructorsFromJsonArrayObjects(tlSchemaJsonObject.ArrayObjects("constructors")); List <TLCombinator> methods = CreateMethodsFromJsonArrayObjects(tlSchemaJsonObject.ArrayObjects("methods")); List <TLType> types = UpdateAndGetTLTypes(constructors); var schema = new TLSchema { Constructors = constructors, Methods = methods, Types = types }; return(schema); }
public static string CompileFromJson(string json, CompilationParams compilationParams) { TLSchema schema = FromJson(json); return(schema.Compile(compilationParams)); }
private void FixType(TLType type, TLSchema schema) { List <TLCombinator> constructors = schema.Constructors; string typeName = type.OriginalName; // Vector. Match match = VectorRegex.Match(typeName); if (match.Success) { TLType itemsType = GetTLType(match.Groups["ItemsType"].Value); FixType(itemsType, schema); type.Name = string.Format("System.Collections.Generic.List<{0}>", itemsType.Name); if (match.Groups["Bare"].Success) { type.SerializationModeOverride = TLSerializationMode.Bare; } return; } // int. match = Int32Regex.Match(typeName); if (match.Success) { type.Name = typeof(UInt32).FullName; return; } // long. match = Int64Regex.Match(typeName); if (match.Success) { type.Name = typeof(UInt64).FullName; return; } // int128. match = Int128Regex.Match(typeName); if (match.Success) { type.Name = typeof(Int128).FullName; return; } // int256. match = Int256Regex.Match(typeName); if (match.Success) { type.Name = typeof(Int256).FullName; return; } // bytes. match = TLBytesRegex.Match(typeName); if (match.Success) { type.Name = typeof(byte[]).FullName; return; } // % bare types. match = BareTypeRegex.Match(typeName); if (match.Success) { typeName = match.Groups["Type"].Value; type.Name = constructors.Where(combinator => combinator.Type.Name == typeName).Select(combinator => combinator.Name).SingleOrDefault() ?? typeName; type.SerializationModeOverride = TLSerializationMode.Bare; } }
public static string CompileFromTL(string tlSchemaText, CompilationParams compilationParams) { TLSchema schema = FromTL(tlSchemaText); return(schema.Compile(compilationParams)); }