Exemplo n.º 1
0
        public JsonProperties GetJsonProperties(object o)
        {
            var props     = o.GetType().GetProperties();
            var fields    = o.GetType().GetFields();
            var jsonProps = new JsonProperties();

            foreach (var field in fields)
            {
                var value = field.GetValue(o);
                jsonProps.AddStringProperty(field.Name, value?.ToString());
            }

            foreach (var prop in props)
            {
                var value = prop.GetValue(o);
                if (value is Header || value is Payload)
                {
                    var res = PutStringProperties(prop.GetValue(o));
                    jsonProps.AddObjectProperty(prop.Name, res);
                    continue;
                }

                jsonProps.AddStringProperty(prop.Name, value?.ToString());
            }

            return(jsonProps);
        }
Exemplo n.º 2
0
        private void AddOneProperty(string name, JsonProperties jsonProperties)
        {
            if (name == null || name == "")
            {
                return;
            }
            var enumerator = jsonProperties.GetStringPropertiesEnumerator();

            if (enumerator.MoveNext() == false)
            {
                return;
            }

            _stringBuilder.AppendFormat("\"{0}\":", name);
            StartWriteObject();

            do
            {
                var current = enumerator.Current;
                AddOneProperty(current.Key, current.Value);
            } while (enumerator.MoveNext());

            EndWriteObject();
            _stringBuilder.Append(',');
        }
Exemplo n.º 3
0
        public JsonWriter(JsonProperties jsonProperties, SerializationOption option)
        {
            _stringBuilder  = new StringBuilder();
            _jsonProperties = jsonProperties;

            isDefault          = SerializationOption.Default == (option & SerializationOption.Default);
            isLeaveNull        = SerializationOption.LeaveNull == (option & SerializationOption.LeaveNull);
            isToLowerCamelCase = SerializationOption.ToLowerCamelCase == (option & SerializationOption.ToLowerCamelCase);
        }
Exemplo n.º 4
0
        private JsonProperties PutStringProperties(object o)
        {
            var jsonProps = new JsonProperties();
            var props     = o.GetType().GetProperties();
            var fields    = o.GetType().GetFields();

            foreach (var prop in props)
            {
                var value = prop.GetValue(o);
                jsonProps.AddStringProperty(prop.Name, value?.ToString());
            }

            foreach (var field in fields)
            {
                var value = field.GetValue(o);
                jsonProps.AddStringProperty(field.Name, value?.ToString());
            }

            return(jsonProps);
        }
Exemplo n.º 5
0
 public void AddObjectProperty(string key, JsonProperties jp)
 {
     _objectProperties.Add(key, jp);
 }