コード例 #1
0
        public void SmElement(XlfEventArgs args)
        {
            if (!args.NodeType.Equals("EndElement"))
            {
                object parent = stack.Peek();
                switch (parent)
                {
                case Segment s:
                    //SmElement smElement = new SmElement();
                    SmElement smElement = mapper.Map <SmElement>(args);
                    //smElement.Attributes = args.Attributes;
                    if (args.sourceOrTarget.Equals("source"))
                    {
                        s.Source.Add(smElement);
                    }
                    else
                    {
                        s.Target.Add(smElement);
                    }

                    break;

                default:
                    break;
                }
            }
        }
コード例 #2
0
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue,
                                        JsonSerializer serializer)
        {
            var jobject = JObject.Load(reader);

            object resolvedType = null;

            var kind = jobject["kind"]?.Value <string>();

            if (kind != null)
            {
                switch (kind)
                {
                case "ec":
                    resolvedType = new EcElement();
                    break;

                case "em":
                    resolvedType = new EmElement();
                    break;

                case "ph":
                    resolvedType = new PhElement();
                    break;

                case "sc":
                    resolvedType = new ScElement();
                    break;

                case "sm":
                    resolvedType = new SmElement();
                    break;
                }
            }
            else
            {
                resolvedType = new TextElement();
            }


            serializer.Populate(jobject.CreateReader(), resolvedType);

            return(resolvedType);
        }