public IPreparationProcessBuilder WithMappingStep(IMappingTable mappingTable)
        {
            var step = new MappingStep(mappingTable);

            _steps.Add(step);
            return(this);
        }
        /// <summary>
        /// Reads the JSON representation of the object.
        /// </summary>
        /// <param name="reader">The <see cref="T:Newtonsoft.Json.JsonReader" /> to read from.</param>
        /// <param name="objectType">Type of the object.</param>
        /// <param name="existingValue">The existing value of object being read.</param>
        /// <param name="serializer">The calling serializer.</param>
        /// <returns>The object value.</returns>
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            IMappingTable table = null;
            bool?         caseSensitive = false, valueUnique = false;
            JArray        items     = null;
            Type          valueType = null;

            while (reader.Read())
            {
                if (reader.Value != null)
                {
                    switch (reader.Value)
                    {
                    case propertyName_CaseSensitive:
                        caseSensitive = reader.ReadAsBoolean();
                        break;

                    case propertyName_ValueUnique:
                        valueUnique = reader.ReadAsBoolean();
                        break;

                    case propertyName_Items:
                        reader.Read();
                        items = reader.ReadAsArray();
                        break;

                    default:
                        break;
                    }
                }
            }

            if (caseSensitive.HasValue && items != null)
            {
                if (objectType == typeof(MappingTable))
                {
                    table     = Activator.CreateInstance(objectType, valueUnique, caseSensitive) as IMappingTable;
                    valueType = typeof(string);
                }
                else if (objectType.EqualsByUnderplyingGenericType(typeof(MappingTable <>)))
                {
                    table     = Activator.CreateInstance(objectType, valueUnique, caseSensitive, null) as IMappingTable;
                    valueType = objectType.GetGenericArguments().SafeFirstOrDefault();
                }

                if (table != null && valueType != null)
                {
                    foreach (var item in items)
                    {
                        var key   = item.Value <string>(propertyName_Source);
                        var value = item.SelectToken(propertyName_Mapping).ToObject(valueType);
                        table.Add(key, value);
                    }
                }
            }

            return(table);
        }
예제 #3
0
 public MappingStep(IMappingTable table)
 {
     _table = table;
 }