public bool MapDestinationPropertyToSource(
            ProfileMap options,
            TypeDetails sourceTypeDetails,
            Type destType,
            Type destMemberType,
            string nameToSearch,
            List <MemberInfo> resolvers,
            IMemberConfiguration parent = null,
            bool isReverseMap           = false
            )
        {
            var matchingMemberInfo = NameMapper.GetMatchingMemberInfo(
                sourceTypeDetails,
                destType,
                destMemberType,
                nameToSearch
                );

            if (matchingMemberInfo != null)
            {
                resolvers.Add(matchingMemberInfo);
                return(true);
            }
            return(nameToSearch.Length == 0);
        }
Beispiel #2
0
 public static IMemberConfiguration <T, TMember> Name <T, TMember>(this IMemberConfiguration <T, TMember> @this,
                                                                   string name)
 {
     @this.AsInternal()
     .Name(name);
     return(@this);
 }
Beispiel #3
0
 public static IMemberConfiguration <T, TMember> Order <T, TMember>(
     this IMemberConfiguration <T, TMember> @this, int order)
 {
     @this.AsInternal()
     .Order(order);
     return(@this);
 }
Beispiel #4
0
 public static IMemberConfiguration <T, TMember> Attribute <T, TMember>(
     this IMemberConfiguration <T, TMember> @this)
 {
     @this.Root.With <MemberFormatExtension>()
     .Registered.Add(((ISource <MemberInfo>)@this).Get());
     return(@this);
 }
Beispiel #5
0
 public static IMemberConfiguration <T, TMember> Register <T, TMember>(this IMemberConfiguration <T, TMember> @this,
                                                                       ISerializer serializer)
 {
     @this.Root.With <CustomSerializationExtension>()
     .Members.Assign(((ISource <MemberInfo>)@this).Get(), serializer);
     return(@this);
 }
        public bool MapDestinationPropertyToSource(IProfileConfiguration options, TypeDetails sourceType, Type destType, Type destMemberType, string nameToSearch, LinkedList<IMemberGetter> resolvers, IMemberConfiguration parent )
        {
            string[] matches = DestinationMemberNamingConvention.SplittingExpression
                .Matches(nameToSearch)
                .Cast<Match>()
                .Select(m => SourceMemberNamingConvention.ReplaceValue(m))
                .ToArray();
            MemberInfo matchingMemberInfo = null;
            for (int i = 1; i <= matches.Length; i++)
            {
                NameSnippet snippet = CreateNameSnippet(matches, i);

                matchingMemberInfo = parent.NameMapper.GetMatchingMemberInfo(sourceType, destType, destMemberType, snippet.First);

                if (matchingMemberInfo != null)
                {
                    resolvers.AddLast(matchingMemberInfo.ToMemberGetter());

                    var details = new TypeDetails(matchingMemberInfo.GetMemberType(), options);
                    var foundMatch = parent.MapDestinationPropertyToSource(options, details, destType, destMemberType, snippet.Second, resolvers);

                    if (!foundMatch)
                        resolvers.RemoveLast();
                    else
                        break;
                }
            }
            return matchingMemberInfo != null;
        }
 public BreezeValueProvider(IValueProvider dynamicValueProvider, IMemberConfiguration memberConfiguration)
 {
     this.serializeFunc       = memberConfiguration.SerializeFunc;
     this.deserializeFunc     = memberConfiguration.DeserializeFunc;
     this.valueProvider       = dynamicValueProvider;
     this.memberConfiguration = memberConfiguration;
 }
Beispiel #8
0
 public static IMemberConfiguration <T, TMember> Unregister <T, TMember>(
     this IMemberConfiguration <T, TMember> @this)
 {
     @this.Root.With <CustomSerializationExtension>()
     .Members.Remove(((ISource <MemberInfo>)@this).Get());
     return(@this);
 }
 private IMemberConfiguration MergeMemberConfiguration(IMemberConfiguration member, IMemberConfiguration mergedMember = null)
 {
     mergedMember = mergedMember ?? new MemberConfiguration(member.MemberInfo);
     foreach (var data in member.Data)
     {
         mergedMember.Data[data.Key] = data.Value;
     }
     mergedMember.Converter                  = member.Converter ?? mergedMember.Converter;
     mergedMember.DefaultValueHandling       = member.DefaultValueHandling ?? mergedMember.DefaultValueHandling;
     mergedMember.DefaultValue               = member.DefaultValue ?? mergedMember.DefaultValue;
     mergedMember.SerializeFunc              = member.SerializeFunc ?? mergedMember.SerializeFunc;
     mergedMember.ShouldSerializePredicate   = member.ShouldSerializePredicate ?? mergedMember.ShouldSerializePredicate;
     mergedMember.ShouldDeserializePredicate = member.ShouldDeserializePredicate ?? mergedMember.ShouldDeserializePredicate;
     mergedMember.Ignored = member.Ignored ?? mergedMember.Ignored;
     if (mergedMember.Ignored.GetValueOrDefault())
     {
     }
     mergedMember.Writable       = member.Writable ?? mergedMember.Writable;
     mergedMember.Readable       = member.Readable ?? mergedMember.Readable;
     mergedMember.SerializedName = member.SerializedName ?? mergedMember.SerializedName;
     mergedMember.MemberType     = member.MemberType ?? mergedMember.MemberType;
     mergedMember.Order          = member.Order ?? mergedMember.Order;
     mergedMember.LazyLoad       = member.LazyLoad ?? mergedMember.LazyLoad;
     return(mergedMember);
 }
Beispiel #10
0
 public BreezeValueProvider(IValueProvider dynamicValueProvider, IMemberConfiguration memberConfiguration)
 {
     _serializeFunc       = memberConfiguration.SerializeFunc;
     _deserializeFunc     = memberConfiguration.DeserializeFunc;
     _valueProvider       = dynamicValueProvider;
     _memberConfiguration = memberConfiguration;
 }
 /// <summary>
 /// Configures a member configuration to only emit when a condition of its containing instance is met.  This is useful
 /// for when a data value from another member in another part of the containing instance is needed to determine
 /// whether or not to emit the (currently) configured member.
 /// </summary>
 /// <typeparam name="T">The containing type of the member.</typeparam>
 /// <typeparam name="TMember">The member type.</typeparam>
 /// <param name="this">The member to configure.</param>
 /// <param name="specification"></param>
 /// <returns>The configured member.</returns>
 public static IMemberConfiguration <T, TMember> EmitWhenInstance <T, TMember>(
     this IMemberConfiguration <T, TMember> @this,
     Func <T, bool> specification)
 {
     @this.Root.Find <AllowedMemberValuesExtension>()
     .Instances[@this.GetMember()] = new DelegatedSpecification <T>(specification).AdaptForNull();
     return(@this);
 }
 public static IMemberConfiguration <T, TMember> EmitWhen <T, TMember>(this IMemberConfiguration <T, TMember> @this,
                                                                       Func <TMember, bool> specification)
 {
     @this.Root.Find <AllowedMemberValuesExtension>()
     .Specifications[((ISource <MemberInfo>)@this).Get()] =
         new AllowedValueSpecification(new DelegatedSpecification <TMember>(specification).AdaptForNull());
     return(@this);
 }
 public static IMemberConfiguration <T> EmitWhen <T>(this IMemberConfiguration <T> @this,
                                                     Func <object, bool> specification)
 {
     @this.Root.Find <AllowedMemberValuesExtension>()
     .Specifications[@this.GetMember()] =
         new AllowedValueSpecification(new DelegatedSpecification <object>(specification).AdaptForNull());
     return(@this);
 }
Beispiel #14
0
 public static IMemberConfiguration <T, TMember> Attribute <T, TMember>(
     this IMemberConfiguration <T, TMember> @this, Func <TMember, bool> when)
 {
     @this.Root.With <MemberFormatExtension>()
     .Specifications[((ISource <MemberInfo>)@this).Get()] =
         new AttributeSpecification(new DelegatedSpecification <TMember>(when).Adapt());
     return(@this.Attribute());
 }
Beispiel #15
0
 public static IMemberConfiguration <T, TMember> Alter <T, TMember>(this IMemberConfiguration <T, TMember> @this,
                                                                    IAlteration <TMember> read,
                                                                    IAlteration <TMember> write)
 {
     @this.Root.With <AlteredContentExtension>()
     .Members.Assign(@this.GetMember(), new ContentAlteration(read.Adapt(), write.Adapt()));
     return(@this);
 }
Beispiel #16
0
 public static IMemberConfiguration <T, TMember> Identity <T, TMember>(this IMemberConfiguration <T, TMember> @this)
 {
     @this.Attribute().Root
     .EnableReferences()
     .With <ReferencesExtension>()
     .Assign(@this.Parent.AsValid <ITypeConfigurationContext>()
             .Get(), ((ISource <MemberInfo>)@this).Get());
     return(@this);
 }
Beispiel #17
0
        public bool MapDestinationPropertyToSource(ProfileMap options, TypeDetails sourceType, Type destType, Type destMemberType, string nameToSearch, LinkedList<MemberInfo> resolvers, IMemberConfiguration parent = null)
        {
            if (string.IsNullOrEmpty(nameToSearch))
                return true;
            var matchingMemberInfo = NameMapper.GetMatchingMemberInfo(sourceType, destType, destMemberType, nameToSearch);

            if (matchingMemberInfo != null)
                resolvers.AddLast(matchingMemberInfo);
            return matchingMemberInfo != null;
        }
        protected virtual void ConfigureProperty(JsonProperty property, IMemberConfiguration memberConfiguration)
        {
            var predicate = memberConfiguration.ShouldSerializePredicate;

            if (predicate != null) //Can be the function defined in this.CreateProperty (check NHibernate initialized property) or a custom one
            {
                if (property.ShouldSerialize != null)
                {
                    property.ShouldSerialize =
                        instance => property.ShouldSerialize(instance) && predicate(instance); //first check if property is initialized
                }
                else
                {
                    property.ShouldSerialize = predicate;
                }
            }
            var predicate2 = memberConfiguration.ShouldDeserializePredicate;

            if (predicate2 != null)
            {
                if (property.ShouldDeserialize != null)
                {
                    property.ShouldDeserialize =
                        instance => property.ShouldDeserialize(instance) && predicate2(instance);
                }
                else
                {
                    property.ShouldDeserialize = predicate2;
                }
            }
            property.DefaultValueHandling = memberConfiguration.DefaultValueHandling;
            property.DefaultValue         = memberConfiguration.DefaultValue;
            if (!string.IsNullOrEmpty(memberConfiguration.SerializedName))
            {
                property.PropertyName = memberConfiguration.SerializedName;
            }
            property.Converter     = memberConfiguration.Converter;
            property.Ignored       = memberConfiguration.Ignored.HasValue && memberConfiguration.Ignored.Value;
            property.Writable      = memberConfiguration.Writable ?? property.Writable;
            property.Readable      = memberConfiguration.Readable ?? property.Readable;
            property.ValueProvider = new BreezeValueProvider(property.ValueProvider, memberConfiguration);
            property.Order         = memberConfiguration.Order ?? property.Order;
        }
 protected virtual JsonProperty CreateCustomProperty(IMemberConfiguration member)
 {
     return(new JsonProperty
     {
         PropertyType = member.MemberType,
         DeclaringType = member.DeclaringType,
         ValueProvider = new CustomMemberValueProvider(member),
         Writable = member.Writable.HasValue && member.Writable.Value,
         Readable = !member.Writable.HasValue || member.Writable.Value,
         ShouldSerialize = member.ShouldSerializePredicate,
         DefaultValueHandling = member.DefaultValueHandling,
         DefaultValue = member.DefaultValue,
         PropertyName = member.SerializedName,
         Converter = member.Converter,
         Ignored = member.Ignored.HasValue && member.Ignored.Value,
         ShouldDeserialize = member.ShouldDeserializePredicate,
         Order = member.Order
     });
 }
Beispiel #20
0
 public AttachedPropertyConfiguration(IMemberConfiguration configuration)
     : base(configuration, ((ISource <MemberInfo>)configuration).Get())
 {
 }
Beispiel #21
0
 public bool MapDestinationPropertyToSource(ProfileMap options, TypeDetails sourceType, Type destType, Type destMemberType, string nameToSearch, LinkedList <MemberInfo> resolvers, IMemberConfiguration parent)
 {
     if (map.TryGetValue(new TypePair(sourceType.Type, destType), out var properties))
     {
         foreach (var property in properties)
         {
             resolvers.AddLast(property);
             var memberType = options.CreateTypeDetails(property.PropertyType);
             if (parent.MapDestinationPropertyToSource(options, memberType, destType, destMemberType, nameToSearch, resolvers))
             {
                 return(true);
             }
             resolvers.RemoveLast();
         }
     }
     return(false);
 }
Beispiel #22
0
 public static IMemberConfiguration <T, TMember> Alter <T, TMember>(this IMemberConfiguration <T, TMember> @this,
                                                                    Func <TMember, TMember> read,
                                                                    Func <TMember, TMember> write)
 => @this.Alter(new DelegatedAlteration <TMember>(read), new DelegatedAlteration <TMember>(write));
Beispiel #23
0
 public static IMemberConfiguration <T, TMember> Alter <T, TMember>(this IMemberConfiguration <T, TMember> @this,
                                                                    Func <TMember, TMember> write)
 => Alter(@this, Self <TMember> .Default.Get, write);
Beispiel #24
0
 public static IMemberConfiguration <T, string> Verbatim <T>(this IMemberConfiguration <T, string> @this) =>
 @this.Register(VerbatimContentSerializer.Default);
Beispiel #25
0
 public static IMemberConfiguration <T, string> WithValidCharacters <T>(this IMemberConfiguration <T, string> @this)
 => @this.Alter(ValidContentCharacters.Default.Get);
        public bool MapDestinationPropertyToSource(IProfileConfiguration options, TypeDetails sourceType, Type destType, Type destMemberType, string nameToSearch, LinkedList <IMemberGetter> resolvers, IMemberConfiguration parent = null)
        {
            if (string.IsNullOrEmpty(nameToSearch))
            {
                return(true);
            }
            var matchingMemberInfo = NameMapper.GetMatchingMemberInfo(sourceType, destType, destMemberType, nameToSearch);

            if (matchingMemberInfo != null)
            {
                resolvers.AddLast(matchingMemberInfo.ToMemberGetter());
            }
            return(matchingMemberInfo != null);
        }
Beispiel #27
0
 public static IMemberConfiguration <T, TMember> Register <T, TMember>(this IMemberConfiguration <T, TMember> @this,
                                                                       ISerializer <TMember> serializer) =>
 Register(@this, serializer.Adapt());
Beispiel #28
0
 public static IMemberConfiguration <T, TMember> Register <T, TMember>(this IMemberConfiguration <T, TMember> @this,
                                                                       Type serializerType)
 => @this.Register(new ActivatedSerializer(serializerType, Support <TMember> .Key));
Beispiel #29
0
 public static MemberInfo GetMember(this IMemberConfiguration @this) => @this.To <ISource <MemberInfo> >()
 .Get();
Beispiel #30
0
 public static IInternalMemberConfiguration AsInternal(this IMemberConfiguration @this)
 {
     return((IInternalMemberConfiguration)@this);
 }
 /// <summary>
 /// Create a new instance.
 /// </summary>
 /// <param name="member">The member configuration to configure.</param>
 public MemberSerializationRegistrationContext(IMemberConfiguration <T, TMember> member) => _member = member;
Beispiel #32
0
        public bool MapDestinationPropertyToSource(
            ProfileMap options,
            TypeDetails sourceType,
            Type destType,
            Type destMemberType,
            string nameToSearch,
            List <MemberInfo> resolvers,
            IMemberConfiguration parent,
            bool isReverseMap
            )
        {
            var destinationMemberNamingConvention = isReverseMap
                ? SourceMemberNamingConvention
                : DestinationMemberNamingConvention;
            var sourceMemberNamingConvention = isReverseMap
                ? DestinationMemberNamingConvention
                : SourceMemberNamingConvention;

            var matches =
                destinationMemberNamingConvention.SplittingExpression
                ?.Matches(nameToSearch)
                .Cast <Match>()
                .Select(m => sourceMemberNamingConvention.ReplaceValue(m))
                .ToArray() ?? Array.Empty <string>();

            MemberInfo matchingMemberInfo = null;

            for (var i = 1; i <= matches.Length; i++)
            {
                var first = string.Join(
                    sourceMemberNamingConvention.SeparatorCharacter,
                    matches.Take(i).Select(SplitMembers)
                    );
                var second = string.Join(
                    sourceMemberNamingConvention.SeparatorCharacter,
                    matches.Skip(i).Select(SplitMembers)
                    );

                matchingMemberInfo = parent.NameMapper.GetMatchingMemberInfo(
                    sourceType,
                    destType,
                    destMemberType,
                    first
                    );

                if (matchingMemberInfo != null)
                {
                    resolvers.Add(matchingMemberInfo);

                    var details    = options.CreateTypeDetails(matchingMemberInfo.GetMemberType());
                    var foundMatch = parent.MapDestinationPropertyToSource(
                        options,
                        details,
                        destType,
                        destMemberType,
                        second,
                        resolvers,
                        isReverseMap
                        );

                    if (!foundMatch)
                    {
                        resolvers.RemoveAt(resolvers.Count - 1);
                    }
                    else
                    {
                        break;
                    }
                }
            }
            return(matchingMemberInfo != null);

            string SplitMembers(string value) =>
            sourceMemberNamingConvention.SplittingExpression.Replace(
                value,
                sourceMemberNamingConvention.ReplaceValue
                );
        }