コード例 #1
0
        private static string ConvertDataToString(object data, string contentType)
        {
            if (data is string s)
            {
                return(s);
            }
            switch (contentType)
            {
            case MimeTypes.PlainText:
                return(data.ToString());

            case MimeTypes.Json:
                return(data.ToJson());

            case MimeTypes.Csv:
                return(data.ToCsv());

            case MimeTypes.Jsv:
                return(data.ToJsv());

            case MimeTypes.Xml:
                return(data.ToXml());

            case MimeTypes.FormUrlEncoded:
                WriteComplexTypeDelegate holdQsStrategy = QueryStringStrategy.FormUrlEncoded;
                QueryStringSerializer.ComplexTypeStrategy = QueryStringStrategy.FormUrlEncoded;
                var urlEncodedBody = QueryStringSerializer.SerializeToString(data);
                QueryStringSerializer.ComplexTypeStrategy = holdQsStrategy;
                return(urlEncodedBody);
            }

            throw new NotSupportedException($"Can not serialize to unknown Content-Type '{contentType}'");
        }
コード例 #2
0
            public ConfigScope()
            {
                scope = JsConfig.With(dateHandler: DateHandler.UnixTime,
                                      propertyConvention: PropertyConvention.Lenient,
                                      emitLowercaseUnderscoreNames: true);

                holdQsStrategy = QueryStringSerializer.ComplexTypeStrategy;
                QueryStringSerializer.ComplexTypeStrategy = QueryStringStrategy.FormUrlEncoded;
            }
コード例 #3
0
ファイル: UnitTests.cs プロジェクト: wickdninja/StackApis
        public ConfigScope()
        {
            jsConfigScope = JsConfig.With(dateHandler: DateHandler.UnixTime,
                                          propertyConvention: PropertyConvention.Lenient,
                                          emitLowercaseUnderscoreNames: true,
                                          emitCamelCaseNames: false);

            holdQsStrategy = QueryStringSerializer.ComplexTypeStrategy;
            QueryStringSerializer.ComplexTypeStrategy = QueryStringStrategy.FormUrlEncoded;
        }
コード例 #4
0
        public ConfigScope()
        {
            scope = JsConfig.With(new ServiceStack.Text.Config {
                DateHandler        = DateHandler.UnixTime,
                PropertyConvention = PropertyConvention.Lenient,
                TextCase           = TextCase.SnakeCase,
            });

            holdQsStrategy = QueryStringSerializer.ComplexTypeStrategy;
            QueryStringSerializer.ComplexTypeStrategy = QueryStringStrategy.FormUrlEncoded;
        }
コード例 #5
0
        public ConfigScope()
        {
            scope = JsConfig.With(new ServiceStack.Text.Config {
                DateHandler                  = DateHandler.UnixTime,
                PropertyConvention           = PropertyConvention.Lenient,
                EmitLowercaseUnderscoreNames = true
            });

            holdQsStrategy = QueryStringSerializer.ComplexTypeStrategy;
            QueryStringSerializer.ComplexTypeStrategy = QueryStringStrategy.FormUrlEncoded;
        }
コード例 #6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ConfigScope"/> class.
        /// </summary>
        public ConfigScope()
        {
            var config = Config.Defaults;

            config.DateHandler        = DateHandler.UnixTime;
            config.PropertyConvention = PropertyConvention.Lenient;
            config.TextCase           = TextCase.SnakeCase;
            config.TreatEnumAsInteger = false;
            config.ExcludeTypeInfo    = true;


            JsConfig <RotessaProcessDate> .SerializeFn = date => date.ToString();

            this.jsConfigScope = JsConfig.With(config);

            this.holdQsStrategy = QueryStringSerializer.ComplexTypeStrategy;
            QueryStringSerializer.ComplexTypeStrategy = QueryStringStrategy.FormUrlEncoded;
        }
コード例 #7
0
            public ConfigScope()
            {
                bool?              convertObjectTypesIntoStringDictionary = new bool?();
                bool?              tryToParsePrimitiveTypeValues          = new bool?();
                bool?              tryToParseNumericType            = new bool?();
                ParseAsType?       parsePrimitiveFloatingPointTypes = new ParseAsType?();
                ParseAsType?       parsePrimitiveIntegerTypes       = new ParseAsType?();
                bool?              excludeDefaultValues             = new bool?();
                bool?              includeNullValues = new bool?();
                bool?              includeNullValuesInDictionaries = new bool?();
                bool?              includeDefaultEnums             = new bool?();
                bool?              excludeTypeInfo              = new bool?();
                bool?              includeTypeInfo              = new bool?();
                DateHandler?       nullable1                    = new DateHandler?(DateHandler.UnixTime);
                PropertyConvention?nullable2                    = new PropertyConvention?(PropertyConvention.Lenient);
                bool?              nullable3                    = new bool?(true);
                bool?              emitCamelCaseNames           = new bool?(false);
                bool?              emitLowercaseUnderscoreNames = nullable3;
                DateHandler?       dateHandler                  = nullable1;
                TimeSpanHandler?   timeSpanHandler              = new TimeSpanHandler?();
                PropertyConvention?propertyConvention           = nullable2;
                bool?              preferInterfaces             = new bool?();
                bool?              throwOnDeserializationError  = new bool?();
                // ISSUE: variable of the null type
                // ISSUE: variable of the null type
                // ISSUE: variable of the null type
                bool?treatEnumAsInteger     = new bool?();
                bool?skipDateTimeConversion = new bool?();
                bool?alwaysUseUtc           = new bool?();
                bool?assumeUtc           = new bool?();
                bool?appendUtcOffset     = new bool?();
                bool?escapeUnicode       = new bool?();
                bool?includePublicFields = new bool?();
                int? maxDepth            = new int?();

                // ISSUE: variable of the null type
                // ISSUE: variable of the null type
                this.jsConfigScope  = JsConfig.With(convertObjectTypesIntoStringDictionary, tryToParsePrimitiveTypeValues, tryToParseNumericType, parsePrimitiveFloatingPointTypes, parsePrimitiveIntegerTypes, excludeDefaultValues, includeNullValues, includeNullValuesInDictionaries, includeDefaultEnums, excludeTypeInfo, includeTypeInfo, emitCamelCaseNames, emitLowercaseUnderscoreNames, dateHandler, timeSpanHandler, propertyConvention, preferInterfaces, throwOnDeserializationError, (string)null, null, (Func <Type, string>)null, (Func <string, Type>)null, treatEnumAsInteger, skipDateTimeConversion, alwaysUseUtc, assumeUtc, appendUtcOffset, escapeUnicode, includePublicFields, maxDepth, (EmptyCtorFactoryDelegate)null, (string[])null);
                this.holdQsStrategy = QueryStringSerializer.ComplexTypeStrategy;
                QueryStringSerializer.ComplexTypeStrategy = new WriteComplexTypeDelegate(QueryStringStrategy.FormUrlEncoded);
            }