Exemplo n.º 1
0
        /// <summary>
        ///     Mappage d'un DTO polymorphe sérialisable au format JSON.
        /// </summary>
        /// <typeparam name="TProperty">Type de DTO base.</typeparam>
        /// <typeparam name="TKey">Type de clef utilisée.</typeparam>
        /// <param name="property">Propriété mappée.</param>
        /// <param name="types">Liste des types supportés.</param>
        /// <param name="configuration">Actions de configuration.</param>
        protected void PropertyJsonGeneric <TProperty, TKey>(Expression <Func <TEntity, TProperty> > property, Action <GenericJsonTypeConfiguration <TProperty, TKey> > types, Action <IPropertyMapper> configuration = null)
            where TProperty : IGenericPersistedDTO
            where TKey : struct, IConvertible
        {
            Property(
                property,
                mapper =>
            {
                // Création de la configuration
                var inner = new GenericJsonTypeConfiguration <TProperty, TKey>();
                types(inner);

                // Référencement
                GenericJsonTypeIndex.AddConfiguration <TKey, TProperty>(inner);

                // Création de l'enveloppe
                var wrapper = new GenericJsonTypeWrapper <TProperty, TKey>(inner);

                // Paramétrage
                mapper.Type <GenericJsonType <TProperty, TKey> >(wrapper);
                mapper.Columns(
                    type =>
                {
                    type.Name(
                        string.Concat(
                            (property.Body as MemberExpression).Member.Name,
                            "_type"));
                },
                    dto =>
                {
                    dto.Name(
                        string.Concat(
                            (property.Body as MemberExpression).Member.Name,
                            "_data"));
                });

                configuration?.Invoke(mapper);
            });
        }
Exemplo n.º 2
0
 /// <summary>
 ///     Constructeur.
 /// </summary>
 public GenericJsonType()
 {
     Configuration = new GenericJsonTypeConfiguration <TBase, TKey>();
 }
Exemplo n.º 3
0
 /// <summary>
 ///     Constructeur par source.
 /// </summary>
 /// <param name="source">Configuration source.</param>
 public GenericJsonTypeWrapper(GenericJsonTypeConfiguration <TBase, TKey> source)
 {
     Data   = JsonConvert.SerializeObject(source);
     Source = source;
 }
Exemplo n.º 4
0
 /// <summary>
 ///     Constructeur par flux.
 /// </summary>
 /// <param name="data">Données sources.</param>
 public GenericJsonTypeWrapper(string data)
 {
     Data   = data;
     Source = JsonConvert.DeserializeObject <GenericJsonTypeConfiguration <TBase, TKey> >(data);
 }
Exemplo n.º 5
0
 /// <summary>
 ///     <see cref="IParameterizedType.SetParameterValues(IDictionary{string, string})" />
 /// </summary>
 public void SetParameterValues(IDictionary <string, string> parameters)
 {
     Configuration = new GenericJsonTypeWrapper <TBase, TKey>(parameters["Data"]).Source;
 }