SerializeComplexTypeProperties() 개인적인 정적인 메소드

private static SerializeComplexTypeProperties ( object value ) : string
value object
리턴 string
예제 #1
0
        public static string SerializeComplexType(object value)
        {
            StringBuilder json = new StringBuilder();

            json.Append("{");
            json.Append(JsonConverter.SerializeComplexTypeProperties(value));
            json.Append("}");
            return(json.ToString());
        }
예제 #2
0
        private static string SerializeComplexTypeProperties(object value)
        {
            Type          type = value.GetType();
            StringBuilder json = new StringBuilder();

            PropertyInfo[] properties = type.GetProperties(BindingFlags.Public | BindingFlags.Instance);
            bool           first      = true;

            for (int i = 0; i < properties.Length; i++)
            {
                PropertyInfo property      = properties[i];
                object       propertyValue = property.GetValue(value, null);
                if (IsConsideredNull(propertyValue))
                {
                    continue;
                }

                if (!first)
                {
                    json.Append(",");
                }
                else
                {
                    first = false;
                }

                if (property.ContainsAttribute <MergePropertiesAttribute>())
                {
                    json.Append(JsonConverter.SerializeComplexTypeProperties(propertyValue));
                }
                else
                {
                    string attributeName = StringUtils.ToCamelCase(property.Name);
                    json.AppendFormat("{0}:{1}", attributeName, JsonConverter.SerializeObject(propertyValue));
                }
            }

            return(json.ToString());
        }