Пример #1
0
 /// <summary>
 /// Gets the write function.
 /// </summary>
 /// <param name="type">The type.</param>
 /// <returns>WriteObjectDelegate.</returns>
 public WriteObjectDelegate GetWriteFn(Type type) => JsvWriter.GetWriteFn(type);
Пример #2
0
        public static void WriteComplexQueryStringProperties(string typeName, TextWriter writer, object instance)
        {
            var i = 0;

            if (PropertyWriters != null)
            {
                var typedInstance = (T)instance;
                var len           = PropertyWriters.Length;
                for (var index = 0; index < len; index++)
                {
                    var propertyWriter = PropertyWriters[index];
                    if (propertyWriter.shouldSerialize != null && !propertyWriter.shouldSerialize(typedInstance))
                    {
                        continue;
                    }

                    var propertyValue = instance != null?propertyWriter.GetterFn(typedInstance) : null;

                    if (propertyWriter.propertySuppressDefaultAttribute && Equals(propertyWriter.DefaultValue, propertyValue))
                    {
                        continue;
                    }

                    if ((propertyValue == null ||
                         propertyWriter.propertySuppressDefaultConfig && Equals(propertyWriter.DefaultValue, propertyValue)) &&
                        !Serializer.IncludeNullValues)
                    {
                        continue;
                    }

                    if (JsConfig.ExcludePropertyReferences != null &&
                        JsConfig.ExcludePropertyReferences.Contains(propertyWriter.propertyReferenceName))
                    {
                        continue;
                    }

                    if (i++ > 0)
                    {
                        writer.Write('&');
                    }

                    var propertyValueType = propertyValue?.GetType();
                    if (propertyValueType != null &&
                        propertyValueType.IsUserType() &&
                        !propertyValueType.HasInterface(typeof(IEnumerable)))
                    {
                        //Nested Complex Type: legal_entity[dob][day]=1
                        var prefix = "{0}[{1}]".Fmt(typeName, propertyWriter.PropertyName);
                        var props  = propertyValueType.GetSerializableProperties();
                        for (int j = 0; j < props.Length; j++)
                        {
                            var pi     = props[j];
                            var pValue = pi.GetValue(propertyValue, TypeConstants.EmptyObjectArray);
                            if (pValue == null && !Serializer.IncludeNullValues)
                            {
                                continue;
                            }

                            if (j > 0)
                            {
                                writer.Write('&');
                            }

                            writer.Write(prefix);
                            writer.Write('[');
                            writer.Write(GetPropertyName(pi.Name));
                            writer.Write("]=");

                            if (pValue == null)
                            {
                                writer.Write(JsonUtils.Null);
                            }
                            else
                            {
                                JsvWriter.GetWriteFn(pValue.GetType())(writer, pValue);
                            }
                        }
                    }
                    else
                    {
                        writer.Write(typeName);
                        writer.Write('[');
                        writer.Write(propertyWriter.PropertyName);
                        writer.Write("]=");

                        if (propertyValue == null)
                        {
                            writer.Write(JsonUtils.Null);
                        }
                        else
                        {
                            propertyWriter.WriteFn(writer, propertyValue);
                        }
                    }
                }
            }
        }
Пример #3
0
 /// <summary>
 /// Gets the write function.
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <returns>WriteObjectDelegate.</returns>
 public WriteObjectDelegate GetWriteFn <T>() => JsvWriter <T> .WriteFn();