コード例 #1
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);
        }
コード例 #2
0
        public void EcElement(XlfEventArgs args)
        {
            object parent = stack.Peek();

            switch (parent)
            {
            case Segment s:
                EcElement ecElement = new EcElement();
                ecElement.Attributes = args.Attributes;
                if (args.sourceOrTarget.Equals("source"))
                {
                    s.Source.Add(ecElement);
                }
                else
                {
                    s.Target.Add(ecElement);
                }

                break;

            default:
                break;
            }
        }