Esempio n. 1
0
        private string GetPropertyBuilder(D2OProperty property)
        {
            var propertyBuilder = new StringBuilder();

            propertyBuilder
            .Append(JsonConvert.ToString(property.PropertyName))
            .Append(": ")
            .Append(GetFieldValueBuilder(property));

            return(propertyBuilder.ToString());
        }
Esempio n. 2
0
        private string GetFieldValueBuilder(D2OProperty property)
        {
            var propertyValueBuilder = new StringBuilder();

            switch (property.PropertyType)
            {
            case D2ODataType.Vector:
                propertyValueBuilder.Append("[");
                var vectorLength = _reader.ReadValue <int>();

                for (var i = 0; i < vectorLength; i++)
                {
                    propertyValueBuilder
                    .Append(GetFieldValueBuilder(property.InnerProperty))
                    .Append(WriteCommaIfHasMore(vectorLength, i));
                }

                propertyValueBuilder.Append("]");
                break;

            case D2ODataType.Int:
                propertyValueBuilder.Append(_reader.ReadValue <int>());
                break;

            case D2ODataType.UInt:
                propertyValueBuilder.Append(_reader.ReadValue <uint>());
                break;

            case D2ODataType.I18N:
                propertyValueBuilder.Append(_reader.ReadValue <int>());
                break;

            case D2ODataType.String:
                propertyValueBuilder.Append(JsonConvert.ToString(_reader.ReadString(StringType.Utf8)));
                break;

            case D2ODataType.Bool:
                propertyValueBuilder.Append(JsonConvert.ToString(_reader.ReadValue <bool>()));    //in json bool is true/false not True/False
                break;

            case D2ODataType.Double:
                propertyValueBuilder.Append(JsonConvert.ToString(_reader.ReadValue <double>()));    //handling the "," vs "." problem of the culture specifics
                break;

            default:
                if (property.PropertyType > 0)     //if type is an object
                {
                    var classId = _reader.ReadValue <int>();
                    if (_d2OClasses.ContainsKey(classId))
                    {
                        propertyValueBuilder.Append(GetObjectBuilder(classId));
                    }
                }
                else
                {
                    throw new ArgumentException(nameof(property.PropertyType));
                }
                break;
            }
            return(propertyValueBuilder.ToString());
        }