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

            setter.ApplyAdaptAttribute(attr);
            return(settings);
        }
Example #2
0
 public static TSetter ApplyAdaptAttribute <TSetter>(this TSetter setter, BaseAdaptAttribute attr) where TSetter : TypeAdapterSetter
 {
     if (attr.IgnoreAttributes != null)
     {
         setter.IgnoreAttribute(attr.IgnoreAttributes);
     }
     if (attr.IgnoreNoAttributes != null)
     {
         setter.IgnoreMember((member, _) => !member.GetCustomAttributesData()
                             .Select(it => it.GetAttributeType())
                             .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.MaxDepth > 0)
     {
         setter.MaxDepth(attr.MaxDepth);
     }
     if (attr.GetBooleanSettingValues(nameof(attr.IgnoreNullValues)) != null)
     {
         setter.IgnoreNullValues(attr.IgnoreNullValues);
     }
     if (attr.GetBooleanSettingValues(nameof(attr.MapToConstructor)) != null)
     {
         setter.MapToConstructor(attr.MapToConstructor);
     }
     if (attr.GetBooleanSettingValues(nameof(attr.PreserveReference)) != null)
     {
         setter.PreserveReference(attr.PreserveReference);
     }
     if (attr.GetBooleanSettingValues(nameof(attr.ShallowCopyForSameType)) != null)
     {
         setter.ShallowCopyForSameType(attr.ShallowCopyForSameType);
     }
     if (attr.GetBooleanSettingValues(nameof(attr.RequireDestinationMemberSource)) != null)
     {
         setter.RequireDestinationMemberSource(attr.RequireDestinationMemberSource);
     }
     return(setter);
 }
Example #3
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);
        }
Example #4
0
 public AdaptAttributeBuilder(BaseAdaptAttribute attribute)
 {
     this.Attribute = attribute;
 }