Пример #1
0
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            var instance = existingValue as ContentTemplateSerializationFormat;

            if (instance == null)
            {
                instance = new ContentTemplateSerializationFormat();
            }

            JObject obj = serializer.Deserialize <JObject>(reader);

            instance.TemplateId           = Read <int>(obj, "TemplateId");
            instance.PrettyName           = Read <string>(obj, "PrettyName") ?? "";
            instance.DefaultDataInstances = new List <Data.IData>();

            JArray dataInstances = obj["DefaultDataInstances"].ToObject <JArray>(serializer);

            foreach (JObject dataInstance in dataInstances)
            {
                Type       dataType = dataInstance["DataType"].ToObject <Type>(serializer);
                Data.IData data     = TryReadData(dataInstance, serializer, "Data", dataType);
                instance.DefaultDataInstances.Add(data);
            }

            return(instance);
        }
Пример #2
0
        /// <summary>
        /// Initializes the ContentTemplate with data from the given ContentTemplate.
        /// </summary>
        public void Initialize(ContentTemplateSerializationFormat template)
        {
            TemplateId = template.TemplateId;
            PrettyName = template.PrettyName;

            foreach (Data.IData data in template.DefaultDataInstances)
            {
                _defaultDataInstances[DataAccessorFactory.GetId(data)] = data;
            }
        }