public void Metaitem(XlfEventArgs args) { if (args.IsEndElement) { //stack.Pop(); } else { object parent = stack.Peek(); switch (parent) { case MetaGroup mg: Metaitem mi = mapper.Map <Metaitem>(args); mg.Meta.Add(mi); //stack.Push(mg); break; } } }
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { var jobject = JObject.Load(reader); object resolvedType = null; var h = jobject["meta"]; if (h != null) { resolvedType = new MetaGroup(); } else { resolvedType = new Metaitem(); } serializer.Populate(jobject.CreateReader(), resolvedType); return(resolvedType); }
public void RoundtripExample3() { var unit1 = new Unit("1"); var unit2 = new Unit("2"); var segment1 = new Segment( new TextElement("Quetzal"), new TextElement("Quetzal")); var segment2 = new Segment( new TextElement("An application to manipulate and process XLIFF documents"), new TextElement("XLIFF 文書を編集、または処理 するアプリケーションです。")); var grp = new MetaGroup(); unit1.Subunits.Add(segment1); unit2.Subunits.Add(segment2); var md = new Metadata(); md.Id = "md14"; unit1.Metadata = md; var breakfast = new Metaitem("breakfast", "eggs"); var phase = new Metaitem("phase", "draft"); var version = new Metaitem("version", "3"); var grp2 = new MetaGroup(); grp2.Meta.Add(breakfast); var grp1 = new MetaGroup(); grp1.Meta.Add(version); grp1.Meta.Add(phase); grp1.Meta.Add(grp2); md.Groups.Add(grp1); var model = new JliffDocument("en-US", "ja-JP"); model.Files.Add(new Localization.Jliff.Graph.File("f1")); var test = new Metaitem("key", "value"); var test1 = new MetaGroup(); test1.Meta.Add(test); var list = new List <MetaGroup>(); list.Add(test1); model.Files[0].Metadata = list; model.Files[0].Skeleton = new Skeleton("Graphic Example.psd.skl"); model.Files[0].Subfiles = new List <ISubfile> { unit1, unit2 }; var dllPath = Assembly.GetAssembly(typeof(ModelTests)).Location; var dllName = Assembly.GetAssembly(typeof(ModelTests)).GetName().Name; var outputPath = dllPath.Replace(dllName + ".dll", ""); Converter.Serialize(Path.Combine(outputPath, "example3.json"), model); Converter.Deserialize(new FileInfo(Path.Combine(outputPath, "example3.json"))); JsonSchema schema = JsonSchema.Parse(schemaDef); var obGraph = JObject.FromObject(model); Assert.IsTrue(obGraph.IsValid(schema)); }