예제 #1
0
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            JObject jObject = JObject.Load(reader);

            var typeId = Convert.ToByte(jObject.Property("Type").Value.ToString());
            var type   = (ViewTypes)typeId;

            object target = null;

            switch (type)
            {
            case ViewTypes.Textfield:
                target = new Textfield();
                break;

            case ViewTypes.Numberfield:
                target = new Numberfield();
                break;

            case ViewTypes.Datefield:
                target = new Datefield();
                break;

            case ViewTypes.Enumfield:
                target = new Enumfield();
                break;

            case ViewTypes.Filefield:
                target = new Filefield();
                break;

            case ViewTypes.Htmlfield:
                target = new Htmlfield();
                break;

            default:
                target = new ViewField();
                break;
            }

            serializer.Populate(jObject.CreateReader(), target);
            return(target);
        }
예제 #2
0
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            JObject jObject = JObject.Load(reader);

            var typeId = Convert.ToByte(jObject.Property("Type").Value.ToString());
            var type = (ViewTypes)typeId;

            object target = null;
            switch (type)
            {
                case ViewTypes.Textfield:
                    target = new Textfield();
                    break;
                case ViewTypes.Numberfield:
                    target = new Numberfield();
                    break;
                case ViewTypes.Datefield:
                    target = new Datefield();
                    break;
                case ViewTypes.Enumfield:
                    target = new Enumfield();
                    break;
                case ViewTypes.Filefield:
                    target = new Filefield();
                    break;
                case ViewTypes.Htmlfield:
                    target = new Htmlfield();
                    break;
                default:
                    target = new ViewField();
                    break;
            }

            serializer.Populate(jObject.CreateReader(), target);
            return target;
        }