Exemple #1
0
 protected void AddTypeRuleForCurrentInclude <T>(
     Delegate @delegate,
     Func <StringBuilder, bool> nullSerializer,
     bool handleNullProperty,
     InternalNodeOptions internalNodeOptions
     )
 {
     AddSerailizer(typeof(T), new SerializerOptions(@delegate, nullSerializer, handleNullProperty, internalNodeOptions));
 }
Exemple #2
0
 public RulesDictionary <TEntity> AddRule <T>(
     Func <StringBuilder, T, bool> func        = null,
     Func <StringBuilder, bool> nullSerializer = null,
     bool?handleNullProperty = null,
     InternalNodeOptions internalNodeOptions = null
     )
 {
     base.AddRuleBase(func, nullSerializer, handleNullProperty, internalNodeOptions);
     return(this);
 }
Exemple #3
0
 public SerializerOptions(
      Delegate serializer,
      Func<StringBuilder, bool> nullSerializer,
      bool handleNullProperty,
      InternalNodeOptions internalNodeOptions)
 {
     Serializer = serializer;
     NullSerializer = nullSerializer;
     HandleNullProperty = handleNullProperty;
     InternalNodeOptions = internalNodeOptions;
 }
Exemple #4
0
        protected void AddRuleBase <T>(
            Func <StringBuilder, T, bool> serializer  = null,
            Func <StringBuilder, bool> nullSerializer = null,
            bool?handleNullProperty = null,
            InternalNodeOptions internalNodeOptions = null
            )
        {
            AddTypeRuleForCurrentInclude <T>(
                serializer,
                nullSerializer ?? this.nullSerializer,
                handleNullProperty ?? this.handleNullProperty,

                internalNodeOptions ?? this.internalNodeOptions);
        }
Exemple #5
0
 public RulesDictionaryBase(
     bool useToString,
     string dateTimeFormat,
     string floatingPointFormat,
     Func <StringBuilder, bool> nullSerializer, bool handleNullProperty, InternalNodeOptions internalNodeOptions,
     Func <LambdaExpression, Delegate> compile
     )
 {
     this.useToString         = useToString;
     this.nullSerializer      = nullSerializer;
     this.handleNullProperty  = handleNullProperty;
     this.internalNodeOptions = internalNodeOptions;
     this.dateTimeFormat      = dateTimeFormat;
     this.floatingPointFormat = floatingPointFormat;
     this.compile             = compile;
 }
Exemple #6
0
        public RulesSubDictionary(
            ChainNode root,
            bool useToString,
            string dateTimeFormat,
            string floatingPointFormat,
            bool stringAsJsonLiteral,
            bool stringJsonEscape,
            Func <StringBuilder, bool> nullSerializer, bool handleNullProperty, InternalNodeOptions internalNodeOptions,
            Func <LambdaExpression, Delegate> compile
            ) : base(useToString, dateTimeFormat, floatingPointFormat, nullSerializer, handleNullProperty, internalNodeOptions, compile
                     )
        {
            this.root = root;

            AddTypeRuleOptimized <bool>((sb, t) => JsonValueStringBuilderExtensions.SerializeBool(sb, t));
            if (stringAsJsonLiteral)
            {
                AddTypeRuleOptimized <string>((sb, t) => JsonValueStringBuilderExtensions.SerializeStringAsJsonLiteral(sb, t));
            }
            else if (!stringJsonEscape)
            {
                AddTypeRuleOptimized <string>((sb, t) => JsonValueStringBuilderExtensions.SerializeString(sb, t));
            }
            else
            {
                AddTypeRuleOptimized <string>((sb, t) => JsonValueStringBuilderExtensions.SerializeEscapeString(sb, t));
            }
            if (dateTimeFormat == null)
            {
                AddTypeRuleOptimized <DateTime>((sb, t) => JsonValueStringBuilderExtensions.SerializeToIso8601WithMs(sb, t));
            }
            else
            {
                AddRuleBase <DateTime>((sb, t) => JsonValueStringBuilderExtensions.SerializeDateTimeDotNet(sb, t, dateTimeFormat));
            }
            if (floatingPointFormat != null)
            {
                AddRuleBase <double>((sb, t) => JsonValueStringBuilderExtensions.SerializeDoubleDotNet(sb, t, floatingPointFormat));
                AddRuleBase <float>((sb, t) => JsonValueStringBuilderExtensions.SerializeFloatDotNet(sb, t, floatingPointFormat));
            }
            AddTypeRuleOptimized <byte[]>((sb, t) => JsonValueStringBuilderExtensions.SerializeBase64(sb, t));
            AddTypeRuleOptimized <decimal>((sb, t) => JsonValueStringBuilderExtensions.SerializePrimitive(sb, t));
        }
Exemple #7
0
        public RulesDictionary <TEntity> SubTree(
            Include <TEntity> include,
            Action <RulesSubDictionary <TEntity> > config = null,
            bool?useToString           = null,
            string dateTimeFormat      = null,
            string floatingPointFormat = null,
            bool?stringAsJsonLiteral   = null,
            bool?stringJsonEscape      = null,
            Func <StringBuilder, bool> nullSerializer = null,
            bool?handleNullProperty = null,
            InternalNodeOptions internalNodeOptions = null
            )
        {
            if (include == null)
            {
                throw new ArgumentNullException(nameof(include), "Serialization for subset can't be configured if subset is defined for the root only include (include is null)");
            }

            var subDictionary = new RulesSubDictionary <TEntity>(
                include.CreateChainNode(),
                useToString ?? this.useToString,
                dateTimeFormat ?? this.dateTimeFormat,
                floatingPointFormat ?? this.floatingPointFormat,
                stringAsJsonLiteral ?? false,
                stringJsonEscape ?? true,
                nullSerializer ?? this.nullSerializer,
                handleNullProperty ?? this.handleNullProperty,
                internalNodeOptions ?? this.internalNodeOptions,
                compile: compile
                );

            config?.Invoke(subDictionary);
            subtrees.Add(subDictionary);

            return(this);
        }