Beispiel #1
0
        private TypeAdapterSettings CreateSettings(BaseAdaptAttribute attr)
        {
            var settings = new TypeAdapterSettings();
            var setter   = new TypeAdapterSetter(settings, this);

            setter.ApplyAdaptAttribute(attr);
            return(settings);
        }
        public TwoWaysTypeAdapterSetter(TypeAdapterConfig config)
        {
            SourceToDestinationSetter = config.ForType <TSource, TDestination>();
            DestinationToSourceSetter = config.ForType <TDestination, TSource>();

            DestinationToSourceSetter.Unflattening(true);
            DestinationToSourceSetter.Settings.SkipDestinationMemberCheck = true;
        }
Beispiel #3
0
 public TypeAdapterConfig()
 {
     this.Rules   = RulesTemplate.ToList();
     this.Default = new TypeAdapterSetter(new TypeAdapterSettings(), this);
     this.Rules.Add(new TypeAdapterRule
     {
         Priority = (sourceType, destinationType, mapType) => - 100,
         Settings = this.Default.Settings,
     });
 }
Beispiel #4
0
        private TypeAdapterSettings CreateSettings(BaseAdaptAttribute attr)
        {
            var settings = new TypeAdapterSettings();
            var setter   = new TypeAdapterSetter(settings, this);

            if (attr.IgnoreAttributes != null)
            {
                setter.IgnoreAttribute(attr.IgnoreAttributes);
            }
            if (attr.IgnoreNoAttributes != null)
            {
                setter.IgnoreMember((member, _) => !member.GetCustomAttributes(true)
                                    .Select(it => it.GetType())
                                    .Intersect(attr.IgnoreNoAttributes)
                                    .Any());
            }
            if (attr.IgnoreNamespaces != null)
            {
                foreach (var ns in attr.IgnoreNamespaces)
                {
                    setter.IgnoreMember((member, _) => member.Type.Namespace?.StartsWith(ns) == true);
                }
            }
            if (attr.IgnoreNullValues)
            {
                setter.IgnoreNullValues(attr.IgnoreNullValues);
            }
            if (attr.MapToConstructor)
            {
                setter.MapToConstructor(attr.MapToConstructor);
            }
            if (attr.MaxDepth > 0)
            {
                setter.MaxDepth(attr.MaxDepth);
            }
            if (attr.PreserveReference)
            {
                setter.PreserveReference(attr.PreserveReference);
            }
            if (attr.ShallowCopyForSameType)
            {
                setter.ShallowCopyForSameType(attr.ShallowCopyForSameType);
            }
            return(settings);
        }
Beispiel #5
0
 /// <summary>
 /// Store aggregate domain Events to persistent object.
 /// </summary>
 /// <typeparam name="TAggregateRoot"><see cref="IAggregateRoot"/></typeparam>
 /// <typeparam name="TPersistentObject"><see cref="IPersistentObject"/></typeparam>
 public static TypeAdapterSetter <TAggregateRoot, TPersistentObject> MapDomainEvent <TAggregateRoot, TPersistentObject>(this TypeAdapterSetter <TAggregateRoot, TPersistentObject> setter)
     where TAggregateRoot : IAggregateRoot
     where TPersistentObject : IPersistentObject
 {
     return(setter.AfterMapping((s, d) => d.AddDomainEvents(s.GetDomainEvents())));
 }
 /// <summary>
 /// Store aggregate domain Events to persistent object.
 /// </summary>
 /// <typeparam name="TEntity"><see cref="IEntity"/></typeparam>
 /// <typeparam name="TPersistentObject"><see cref="IPersistentObject"/></typeparam>
 public static TypeAdapterSetter <TEntity, TPersistentObject> MapDomainEvent <TEntity, TPersistentObject>(this TypeAdapterSetter <TEntity, TPersistentObject> setter)
     where TEntity : IEntity
     where TPersistentObject : IPersistentObject
 {
     return(setter.AfterMapping((s, d) => d.AddDomainEvents(s.GetDomainEvents())));
 }