Beispiel #1
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));
        }
 public IJsonRootPropertyAppender AddStringProperty(string name, string value)
 {
     properties.Add(name, (sb) => JsonValueStringBuilderExtensions.SerializeEscapeString(sb, value));
     return(this);
 }
 public IJsonRootPropertyAppender AddNumberProperty(string name, double value)
 {
     properties.Add(name, (sb) => JsonValueStringBuilderExtensions.SerializeValueToString(sb, value));
     return(this);
 }