private void buttonOk_Click(object sender, EventArgs e) { paramName = comboBoxParameter.Text; if (radioSelectedElements.Checked) { writerMode = WriterMode.OnlySelected; } if (radioViewElements.Checked) { writerMode = WriterMode.OnCurrentView; } if (radioAllElements.Checked) { writerMode = WriterMode.AllInProject; } if (radioButtonWriteValue.Checked) { sourceMode = SourceMode.FixValue; source = comboBoxValue.Text; } if (radioButtonWriteOtherPAram.Checked) { sourceMode = SourceMode.OtherParameter; source = comboBoxSourceParameter.Text; } this.DialogResult = DialogResult.OK; this.Close(); }
private void EnsureCorrectContext(WriterMode writerContext) { if (_contextStack.Count == 0) { Debug.Fail(String.Format(CultureInfo.CurrentCulture, RazorResources.CodeWriter_NoCurrentContext, GetContextName(writerContext))); throw new InvalidOperationException( String.Format(CultureInfo.CurrentCulture, RazorResources.CodeWriter_NoCurrentContext, GetContextName(writerContext))); } else if (_contextStack.Peek() != writerContext) { Debug.Fail(String.Format(CultureInfo.CurrentCulture, RazorResources.CodeWriter_MismatchedContexts, GetContextName(writerContext), GetContextName(_contextStack.Peek()))); throw new InvalidOperationException( String.Format(CultureInfo.CurrentCulture, RazorResources.CodeWriter_MismatchedContexts, GetContextName(writerContext), GetContextName(_contextStack.Peek()))); } }
public XmlStringWriter(StringWriter stringWriter, WriterMode writerMode) { _stringWriter = stringWriter; _xmlWriter = new XmlTextWriter(_stringWriter); _writerMode = writerMode; if (_writerMode == WriterMode.Managed) { _xmlWriter.WriteStartDocument(); } }
private static void WriteUnion(TextWriter writer, UnionSchema schema, WriterMode mode, string parentNamespace, ISet <string> namedSchemas, bool stripNs) { var i = 0; switch (mode) { case WriterMode.Canonical: writer.Write(@"["); foreach (var item in schema) { if (i++ > 0) { writer.Write(","); } Write(writer, item, mode, parentNamespace, namedSchemas, stripNs); } writer.Write(@"]"); break; case WriterMode.Full: writer.Write(@"["); foreach (var item in schema) { if (i++ > 0) { writer.Write(", "); } Write(writer, item, mode, parentNamespace, namedSchemas, stripNs); } writer.Write(@"]"); break; default: writer.Write(@"["); foreach (var item in schema) { if (i++ > 0) { writer.Write(", "); } Write(writer, item, mode, parentNamespace, namedSchemas, stripNs); } writer.Write(@"]"); break; } }
private static void WriteDecimal(TextWriter writer, DecimalSchema schema, WriterMode mode, string parentNamespace, ISet <string> namedSchemas, bool stripNs) { switch (mode) { case WriterMode.Canonical: writer.Write(@"{""type"":"); Write(writer, schema.Type, mode, parentNamespace, namedSchemas, stripNs); writer.Write(@",""logicalType"":"""); writer.Write(schema.LogicalType); writer.Write(@""""); writer.Write(@",""precision"":"); writer.Write(schema.Precision); writer.Write(@",""scale"":"); writer.Write(schema.Scale); writer.Write(@"}"); break; case WriterMode.Full: writer.Write(@"{ ""type"": "); Write(writer, schema.Type, mode, parentNamespace, namedSchemas, stripNs); writer.Write(@", ""logicalType"": """); writer.Write(schema.LogicalType); writer.Write(@""""); writer.Write(@", ""precision"": "); writer.Write(schema.Precision); writer.Write(@", ""scale"": "); writer.Write(schema.Scale); writer.Write(@" }"); break; default: writer.Write(@"{ ""type"": "); Write(writer, schema.Type, mode, parentNamespace, namedSchemas, stripNs); writer.Write(@", ""logicalType"": """); writer.Write(schema.LogicalType); writer.Write(@""""); writer.Write(@", ""precision"": "); writer.Write(schema.Precision); writer.Write(@", ""scale"": "); writer.Write(schema.Scale); writer.Write(@" }"); break; } }
private static void WriteMap(TextWriter writer, MapSchema schema, WriterMode mode, string parentNamespace, ISet <string> namedSchemas, bool stripNs) { switch (mode) { case WriterMode.Canonical: writer.Write(@"{""type"":""map"",""values"":"); Write(writer, schema.Values, mode, parentNamespace, namedSchemas, stripNs); writer.Write(@"}"); break; case WriterMode.Full: writer.Write(@"{ ""type"": ""map"", ""values"": "); Write(writer, schema.Values, mode, parentNamespace, namedSchemas, stripNs); writer.Write(@" }"); break; default: writer.Write(@"{ ""type"": ""map"", ""values"": "); Write(writer, schema.Values, mode, parentNamespace, namedSchemas, stripNs); writer.Write(@" }"); break; } }
private static void WriteArray(TextWriter writer, ArraySchema schema, WriterMode mode, string parentNamespace, ISet <string> namedSchemas, bool stripNs) { switch (mode) { case WriterMode.Canonical: writer.Write(@"{""type"":""array"",""items"":"); Write(writer, schema.Items, mode, parentNamespace, namedSchemas, stripNs); writer.Write(@"}"); break; case WriterMode.Full: writer.Write(@"{ ""type"": ""array"", ""items"": "); Write(writer, schema.Items, mode, parentNamespace, namedSchemas, stripNs); writer.Write(@" }"); break; default: writer.Write(@"{ ""type"": ""array"", ""items"": "); Write(writer, schema.Items, mode, parentNamespace, namedSchemas, stripNs); writer.Write(@" }"); break; } }
private static void WritePrimitive(TextWriter writer, AvroSchema schema, WriterMode mode) { switch (mode) { case WriterMode.Canonical: writer.Write(@""""); writer.Write(schema.ToString()); writer.Write(@""""); break; case WriterMode.Full: writer.Write(@"{ ""type"": """); writer.Write(schema.ToString()); writer.Write(@""" }"); break; default: writer.Write(@""""); writer.Write(schema.ToString()); writer.Write(@""""); break; } }
private static void WriteTypes(TextWriter writer, IEnumerable <AvroSchema> schemas, WriterMode mode, string parentNamespace, ISet <string> namedSchemas, bool stripNs) { var i = 0; foreach (var schema in schemas) { switch (mode) { case WriterMode.Canonical: if (i > 0) { writer.Write(","); } Write(writer, schema, mode, parentNamespace, namedSchemas, stripNs); break; case WriterMode.Full: if (i > 0) { writer.Write(", "); } Write(writer, schema, mode, parentNamespace, namedSchemas, stripNs); break; default: if (i > 0) { writer.Write(", "); } Write(writer, schema, mode, parentNamespace, namedSchemas, stripNs); break; } i++; } }
private static string GetContextName(WriterMode writerContext) { return RazorResources.ResourceManager.GetString("WriterContext_" + writerContext.ToString()); }
private static void WriteFields(TextWriter writer, IEnumerable <RecordSchema.Field> fields, WriterMode mode, string parentNamespace, ISet <string> namedSchemas, bool stripNs) { var i = 0; foreach (var field in fields) { switch (mode) { case WriterMode.Canonical: if (i++ > 0) { writer.Write(","); } writer.Write("{"); writer.Write(@"""name"":"""); writer.Write(field.Name); writer.Write(@""""); writer.Write(@",""type"":"); Write(writer, field.Type, mode, parentNamespace, namedSchemas, stripNs); if (field.Default != null) { writer.Write(@",""default"":"); writer.Write(field.Default); writer.Write(@""); } writer.Write("}"); break; case WriterMode.Full: if (i++ > 0) { writer.Write(", "); } writer.Write("{"); writer.Write(@" ""name"": """); writer.Write(field.Name); writer.Write(@""""); writer.Write(@", ""type"": "); Write(writer, field.Type, mode, parentNamespace, namedSchemas, stripNs); if (field.Default != null) { writer.Write(@", ""default"": "); writer.Write(field.Default); writer.Write(@""); } writer.Write(@", ""doc"": """); writer.Write(field.Doc); writer.Write(@""""); writer.Write(@", ""aliases"": ["); writer.Write(string.Join(", ", field.Aliases.Select(r => $"\"{r}\""))); writer.Write(@"]"); writer.Write(@", ""order"": """); writer.Write(field.Order ?? "ignore"); writer.Write(@""""); writer.Write(@" }"); break; default: if (i++ > 0) { writer.Write(", "); } writer.Write("{"); writer.Write(@" ""name"": """); writer.Write(field.Name); writer.Write(@""""); writer.Write(@", ""type"": "); Write(writer, field.Type, mode, parentNamespace, namedSchemas, stripNs); if (field.Default != null) { writer.Write(@", ""default"": "); writer.Write(field.Default); writer.Write(@""); } if (!string.IsNullOrEmpty(field.Doc)) { writer.Write(@", ""doc"": """); writer.Write(field.Doc); writer.Write(@""""); } if (field.Aliases.Count > 0) { writer.Write(@", ""aliases"": ["); writer.Write(string.Join(", ", field.Aliases.Select(r => $"\"{r}\""))); writer.Write(@"]"); } if (!string.IsNullOrEmpty(field.Order)) { writer.Write(@", ""order"": """); writer.Write(field.Order); writer.Write(@""""); } writer.Write(@" }"); break; } } }
private static void WriteError(TextWriter writer, ErrorSchema schema, WriterMode mode, string parentNamespace, ISet <string> namedSchemas, bool stripNs) { var ns = parentNamespace; if (!string.IsNullOrEmpty(schema.Namespace)) { ns = schema.Namespace; } if (stripNs && ns == parentNamespace) { ns = null; } switch (mode) { case WriterMode.Canonical: writer.Write(@"{""name"":"""); writer.Write(schema.FullName); writer.Write(@""""); writer.Write(@",""type"":""error"""); writer.Write(@",""fields"":["); WriteFields(writer, schema, mode, parentNamespace, namedSchemas, stripNs); writer.Write(@"]"); writer.Write(@"}"); break; case WriterMode.Full: writer.Write(@"{ ""type"": ""error"""); writer.Write(@", ""name"": """); writer.Write(schema.Name); writer.Write(@""""); writer.Write(@", ""namespace"": """); writer.Write(schema.Namespace); writer.Write(@""""); writer.Write(@", ""doc"": """); writer.Write(schema.Doc); writer.Write(@""""); writer.Write(@", ""aliases"": ["); writer.Write(string.Join(", ", schema.Aliases.Select(r => $"\"{r}\""))); writer.Write(@"]"); writer.Write(@", ""fields"": ["); WriteFields(writer, schema, mode, parentNamespace, namedSchemas, stripNs); writer.Write(@"]"); writer.Write(@" }"); break; default: writer.Write(@"{ ""type"": ""error"""); writer.Write(@", ""name"": """); writer.Write(schema.Name); writer.Write(@""""); if (!string.IsNullOrEmpty(ns)) { writer.Write(@", ""namespace"": """); writer.Write(ns); writer.Write(@""""); } if (!string.IsNullOrEmpty(schema.Doc)) { writer.Write(@", ""doc"": """); writer.Write(schema.Doc); writer.Write(@""""); } if (schema.Aliases.Count > 0) { writer.Write(@", ""aliases"": ["); writer.Write(string.Join(", ", schema.Aliases.Select(r => $"\"{r}\""))); writer.Write(@"]"); } writer.Write(@", ""fields"": ["); WriteFields(writer, schema, mode, parentNamespace, namedSchemas, stripNs); writer.Write(@"]"); writer.Write(@" }"); break; } }
public static void SetWritingMode(WriterMode newMode) { mode = newMode; }
public bool Compile(string currentDir, string inputFile, string outputFile, IFileLookup lookup, Context context, Options options, WriterMode writerMode) { Current.SetContext(context); Current.SetWriterMode(writerMode); Current.SetOptions(options); CompilationTask noop = (List <Block> blocks) => blocks; var tasks = new List <CompilationTask>() { Tasks.Using.Task, References.Task, Charsets.Task, Tasks.Import.Task, Reset.Task, Sprite.Task, Mixin.Task, UnrollNestedMedia.Task, UnrollNestedSelectors.Task, UnrollVerify.Task, Tasks.Media.Task, Includes.Task, ResetIncludes.Task, Evaluate.Task, Important.Task, NoOps.Task, FontFace.Task, ResetReOrder.Task, Verify.Task, Current.Options.HasFlag(Options.Minify) ? Minify.Task : noop, Collapse.Task, WriteSprites.Task, Current.Options.HasFlag(Options.GenerateCacheBreakers) ? CacheBreak.Task : noop, Current.Options.HasFlag(Options.AutomateVendorPrefixes) ? AutoPrefix.Task : noop, Write.Task }; try { Current.SetWorkingDirectory(currentDir); Current.SetFileLookup(lookup); inputFile = Path.IsPathRooted(inputFile) ? inputFile : inputFile.RebaseFile(); Current.SetInitialFile(inputFile); List <Block> blocks; using (var stream = lookup.Find(inputFile)) { blocks = Parse.Task(stream); } using (var output = lookup.OpenWrite(outputFile)) { Current.SetOutputStream(output); if (blocks == null) { return(false); } foreach (var task in tasks) { blocks = task(blocks); if (Current.HasErrors()) { return(false); } } } Current.Dependecies.FileCompiled(inputFile, blocks); return(true); } catch (StoppedCompilingException) { return(false); } }
public bool Compile(string currentDir, string inputFile, string outputFile, IFileLookup lookup, Context context, Options options, WriterMode writerMode) { Current.SetContext(context); Current.SetWriterMode(writerMode); Current.SetOptions(options); CompilationTask noop = (List<Block> blocks) => blocks; var tasks = new List<CompilationTask>() { Tasks.Using.Task, References.Task, Charsets.Task, Tasks.Import.Task, Reset.Task, Sprite.Task, Mixin.Task, Unroll.Task, Tasks.Media.Task, Includes.Task, ResetIncludes.Task, Evaluate.Task, Important.Task, NoOps.Task, FontFace.Task, ResetReOrder.Task, Verify.Task, Current.Options.HasFlag(Options.Minify) ? Minify.Task : noop, Collapse.Task, Write.Task, WriteSprites.Task }; try { Current.SetWorkingDirectory(currentDir); Current.SetFileLookup(lookup); inputFile = inputFile.RebaseFile(); Current.SetInitialFile(inputFile); List<Block> blocks; using (var stream = lookup.Find(inputFile)) { blocks = Parse.Task(stream); } using (var output = lookup.OpenWrite(outputFile)) { Current.SetOutputStream(output); if (blocks == null) return false; foreach (var task in tasks) { blocks = task(blocks); if (Current.HasErrors()) return false; } } return true; } catch (StoppedCompilingException) { return false; } }
private static string GetContextName(WriterMode writerContext) { return(RazorResources.ResourceManager.GetString("WriterContext_" + writerContext.ToString())); }
private static void Write(TextWriter writer, AvroProtocol protocol, WriterMode mode) { var namedSchemas = new HashSet <string>(); switch (mode) { case WriterMode.Canonical: writer.Write(@"{"); writer.Write(@"""protocol"":"""); writer.Write(protocol.FullName); writer.Write(@""""); if (protocol.Types.Count() > 0) { writer.Write(@",""types"":["); WriteTypes(writer, protocol.Types, mode, protocol.Namespace, namedSchemas, true); writer.Write(@"]"); } if (protocol.Messages.Count() > 0) { writer.Write(@",""messages"":{"); WriteMessages(writer, protocol.Messages, mode, protocol.Namespace, namedSchemas, true); writer.Write(@"}"); } writer.Write("}");; break; case WriterMode.Full: writer.Write(@"{ "); writer.Write(@"""namespace"": """); writer.Write(protocol.Namespace); writer.Write(@""", "); writer.Write(@"""protocol"": """); writer.Write(protocol.Name); writer.Write(@""", "); writer.Write(@"""doc"": """); writer.Write(protocol.Doc); writer.Write(@""", "); writer.Write(@"""types"": ["); WriteTypes(writer, protocol.Types, mode, protocol.Namespace, namedSchemas, true); writer.Write(@"], "); writer.Write(@"""messages"": {"); WriteMessages(writer, protocol.Messages, mode, protocol.Namespace, namedSchemas, true); writer.Write("}");; writer.Write(" }");; break; default: writer.Write(@"{ "); if (!string.IsNullOrEmpty(protocol.Namespace)) { writer.Write(@"""namespace"": """); writer.Write(protocol.Namespace); writer.Write(@""", "); } writer.Write(@"""protocol"": """); writer.Write(protocol.Name); writer.Write(@""""); if (!string.IsNullOrEmpty(protocol.Doc)) { writer.Write(@", ""doc"": """); writer.Write(protocol.Doc); writer.Write(@""""); } if (protocol.Types.Count() > 0) { writer.Write(@", ""types"": ["); WriteTypes(writer, protocol.Types, mode, protocol.Namespace, namedSchemas, true); writer.Write(@"]"); } if (protocol.Messages.Count() > 0) { writer.Write(@", ""messages"": {"); WriteMessages(writer, protocol.Messages, mode, protocol.Namespace, namedSchemas, true); writer.Write(@"}"); } writer.Write(" }"); break; } }
private static void Write(TextWriter writer, AvroSchema schema, WriterMode mode, string parentNamespace, ISet <string> namedSchemas, bool stripNs) { var ns = parentNamespace; if (namedSchemas == null) { namedSchemas = new HashSet <string>(); } if (schema is NamedSchema) { var namedSchema = schema as NamedSchema; var name = namedSchema.FullName; if (stripNs && namedSchema.Namespace == parentNamespace) { name = namedSchema.Name; } if (namedSchemas.Contains(namedSchema.FullName)) { writer.Write(@""""); writer.Write(name); writer.Write(@""""); return; } namedSchemas.Add(namedSchema.FullName); ns = namedSchema.Namespace; } switch (schema) { case NullSchema _: case BooleanSchema _: case IntSchema _: case LongSchema _: case FloatSchema _: case DoubleSchema _: case BytesSchema _: case StringSchema _: WritePrimitive(writer, schema, mode); break; case ArraySchema s: WriteArray(writer, s, mode, ns, namedSchemas, stripNs); break; case MapSchema s: WriteMap(writer, s, mode, ns, namedSchemas, stripNs); break; case UnionSchema s: WriteUnion(writer, s, mode, ns, namedSchemas, stripNs); break; case FixedSchema s: WriteFixed(writer, s, ns, mode, stripNs); break; case EnumSchema s: WriteEnum(writer, s, ns, mode, stripNs); break; case ErrorSchema s: WriteError(writer, s, mode, ns, namedSchemas, stripNs); break; case RecordSchema s: WriteRecord(writer, s, mode, ns, namedSchemas, stripNs); break; case DecimalSchema s: WriteDecimal(writer, s, mode, ns, namedSchemas, stripNs); break; case LogicalSchema s: WriteLogicalType(writer, s, mode, ns, namedSchemas, stripNs); break; default: throw new AvroException($"Unknown schema type: '{schema.GetType().FullName}'"); } }
public static void SetWriterMode(WriterMode mode) { WriterMode = mode; }
public void SetMode(WriterMode mode) { writerMode = mode; }
private static void WriteMessages(TextWriter writer, IEnumerable <MessageSchema> messages, WriterMode mode, string parentNamespace, ISet <string> namedSchemas, bool stripNs) { var i = 0; foreach (var message in messages) { switch (mode) { case WriterMode.Canonical: if (i > 0) { writer.Write(","); } writer.Write(@""""); writer.Write(message.Name); writer.Write(@""":"); writer.Write(@"{"); writer.Write(@"""request"":["); WriteParameters(writer, message.RequestParameters, mode, parentNamespace, namedSchemas, stripNs); writer.Write(@"]"); if (message.Response != null) { writer.Write(@",""response"":"); Write(writer, message.Response, mode, parentNamespace, namedSchemas, stripNs); } if (message.Error.Count > 1) { writer.Write(@",""errors"":["); writer.Write(string.Join(",", message.Error.Skip(1).Select(r => $"\"{(r as NamedSchema).FullName}\""))); writer.Write(@"]"); } if (message.Oneway) { writer.Write(@",""one-way"":true"); } writer.Write(@"}"); break; case WriterMode.Full: if (i > 0) { writer.Write(", "); } writer.Write(@""""); writer.Write(message.Name); writer.Write(@""": "); writer.Write(@"{"); writer.Write(@"""doc"": """); writer.Write(message.Doc); writer.Write(@""""); writer.Write(@", ""request"": ["); WriteParameters(writer, message.RequestParameters, mode, parentNamespace, namedSchemas, stripNs); writer.Write(@"], "); writer.Write(@"""response"": "); if (message.Response != null) { Write(writer, message.Response, mode, parentNamespace, namedSchemas, stripNs); } else { writer.Write("null"); } writer.Write(@", ""errors"": ["); writer.Write(string.Join(", ", message.Error.Skip(1).Select(r => $"\"{(r as NamedSchema).FullName}\""))); writer.Write(@"], "); writer.Write(@"""one-way"": "); writer.Write(message.Oneway.ToString().ToLower()); writer.Write(@"}"); break; default: if (i > 0) { writer.Write(", "); } writer.Write(@""""); writer.Write(message.Name); writer.Write(@""": "); writer.Write(@"{"); if (!string.IsNullOrEmpty(message.Doc)) { writer.Write(@"""doc"": """); writer.Write(message.Doc); writer.Write(@""", "); } writer.Write(@"""request"": ["); WriteParameters(writer, message.RequestParameters, mode, parentNamespace, namedSchemas, stripNs); writer.Write(@"]"); if (message.Response != null) { writer.Write(@", ""response"": "); Write(writer, message.Response, mode, parentNamespace, namedSchemas, stripNs); } if (message.Error.Count > 1) { writer.Write(@", ""errors"": ["); writer.Write(string.Join(", ", message.Error.Skip(1).Cast <NamedSchema>().Select(r => $"\"{(stripNs && r.Namespace == parentNamespace ? r.Name : r.FullName)}\""))); writer.Write(@"]"); } if (message.Oneway) { writer.Write(@", ""one-way"": true"); } writer.Write(@"}"); break; } i++; } }
private static void WriteParameters(TextWriter writer, IEnumerable <ParameterSchema> requestParameters, WriterMode mode, string parentNamespace, ISet <string> namedSchemas, bool stripNs) { var i = 0; foreach (var requestParameter in requestParameters) { var ns = parentNamespace; if (!string.IsNullOrEmpty(requestParameter.Type.Namespace)) { ns = requestParameter.Type.Namespace; } if (stripNs && ns == parentNamespace) { ns = null; } var name = ns == null ? requestParameter.Type.Name : $"{ns}.{requestParameter.Type.Name}"; switch (mode) { case WriterMode.Canonical: if (i++ > 0) { writer.Write(","); } writer.Write("{"); writer.Write(@"""name"":"""); writer.Write(requestParameter.Name); writer.Write(@""""); writer.Write(@",""type"":"""); writer.Write(requestParameter.Type.FullName); writer.Write(@"""}"); break; case WriterMode.Full: if (i++ > 0) { writer.Write(", "); } writer.Write("{"); writer.Write(@" ""name"": """); writer.Write(requestParameter.Name); writer.Write(@""""); writer.Write(@", ""type"": """); writer.Write(requestParameter.Type.FullName); writer.Write(@""" }"); break; default: if (i++ > 0) { writer.Write(", "); } writer.Write("{"); writer.Write(@" ""name"": """); writer.Write(requestParameter.Name); writer.Write(@""""); writer.Write(@", ""type"": """); writer.Write(name); writer.Write(@""" }"); break; } } }
public XmlStringWriter(WriterMode writerMode) : this(new StringWriter(), writerMode) { }
private string TryCompile(string text, string fakeFile = null, IFileLookup lookup = null, bool minify = false, WriterMode mode = WriterMode.Minimize, bool cacheBreak = false, bool prefix = false) { if (mode == WriterMode.Minimize) { try { TryCompile(text, null, lookup, minify, WriterMode.Pretty); } catch (Exception e) { Assert.Fail("Pretty writing failed"); } } fakeFile = fakeFile ?? "compiler-fake-file " + Interlocked.Increment(ref TryCompileNumber) + ".more"; Options opts = Options.None; if (minify) { opts |= Options.Minify; } if (cacheBreak) { opts |= Options.GenerateCacheBreakers; } if (prefix) { opts |= Options.AutomateVendorPrefixes; } var fileLookup = new TestLookup(new Dictionary<string, string>() { { fakeFile, text } }, lookup); var compiler = Compiler.Get(); var ctx = new Context(new FileCache()); // it's hard to test minification steps if they all always run, so let's just go for a single pass in the "text comparison" cases // still do the full thing when we're doing our test "pretty pass" elsewhere to make sure it always terminates ctx.DisableMultipleMinificationPasses = mode != WriterMode.Pretty; compiler.Compile(Environment.CurrentDirectory, fakeFile, fakeFile + ".out", fileLookup, ctx, opts, mode); var ret = fileLookup.WriteMap.ElementAt(0).Value; return ret; }
private static void WriteFixed(TextWriter writer, FixedSchema schema, string parentNamespace, WriterMode mode, bool stripNs) { var ns = parentNamespace; if (!string.IsNullOrEmpty(schema.Namespace)) { ns = schema.Namespace; } if (stripNs && ns == parentNamespace) { ns = null; } switch (mode) { case WriterMode.Canonical: writer.Write(@"{""name"":"""); writer.Write(schema.FullName); writer.Write(@""""); writer.Write(@",""type"":""fixed"""); writer.Write(@",""size"":"); writer.Write(schema.Size); writer.Write(@"}"); break; case WriterMode.Full: writer.Write(@"{ ""type"": ""fixed"""); writer.Write(@", ""name"": """); writer.Write(schema.Name); writer.Write(@""""); writer.Write(@", ""namespace"": """); writer.Write(schema.Namespace); writer.Write(@""""); writer.Write(@", ""size"": "); writer.Write(schema.Size); writer.Write(@", ""aliases"": ["); writer.Write(string.Join(", ", schema.Aliases.Select(r => $"\"{r}\""))); writer.Write(@"]"); writer.Write(@" }"); break; default: writer.Write(@"{ ""type"": ""fixed"""); writer.Write(@", ""name"": """); writer.Write(schema.Name); writer.Write(@""""); if (!string.IsNullOrEmpty(ns)) { writer.Write(@", ""namespace"": """); writer.Write(ns); writer.Write(@""""); } writer.Write(@", ""size"": "); writer.Write(schema.Size); if (schema.Aliases.Count() > 0) { writer.Write(@", ""aliases"": ["); writer.Write(string.Join(", ", schema.Aliases.Select(r => $"\"{r}\""))); writer.Write(@"]"); } writer.Write(@" }"); break; } }
public static XmlStringWriter Create(WriterMode writerMode) { return(new XmlStringWriter(writerMode)); }