示例#1
0
文件: JSON.cs 项目: huycn/json4uwp
 public static string Stringify(object value, StringifyOptions options = StringifyOptions.None)
 {
     if (value != null)
     {
         var buffer = new StringBuilder();
         GetSerializer(value.GetType())(buffer, value, options);
         return(buffer.ToString());
     }
     return("null");
 }
示例#2
0
文件: JSON.cs 项目: huycn/json4uwp
 static void WriteString(StringBuilder output, object value, StringifyOptions options)
 {
     if (value == null)
     {
         output.Append("null");
     }
     else
     {
         DoWriteString(output, (string)value);
     }
 }
示例#3
0
文件: JSON.cs 项目: huycn/json4uwp
 static void WriteDynamicObject(StringBuilder output, object value, StringifyOptions options)
 {
     if (value == null)
     {
         output.Append("null");
     }
     else
     {
         var realType = value.GetType();
         if (realType != typeof(object))
         {
             GetSerializer(realType)(output, value, options);
         }
         else
         {
             output.Append("{}");
         }
     }
 }
示例#4
0
文件: JSON.cs 项目: huycn/json4uwp
 public void Serializer(StringBuilder output, object value, StringifyOptions options)
 {
     if (value == null)
     {
         output.Append("null");
     }
     else
     {
         output.Append('{');
         int oldLength = output.Length;
         WriteContent(output, value, options);
         int newLength = output.Length;
         if (oldLength != newLength)
         {
             output[newLength - 1] = '}';
         }
         else
         {
             output.Append('}');
         }
     }
 }
示例#5
0
        /// <summary>
        /// Returns the text representation of the given sequence of moves in
        /// algebraic notation.
        /// </summary>
        /// <param name="position">The position on which the sequence of moves are to be played.</param>
        /// <param name="moves">The sequence of moves to identify.</param>
        /// <param name="options">The identification option specifying whether to be absolutely proper.</param>
        /// <returns>The text representation of the given sequence of moves in algebraic notation</returns>
        public static String MovesAlgebraically(Position position, List <Int32> moves, StringifyOptions options = StringifyOptions.None)
        {
            if (moves.Count == 0)
            {
                return("");
            }

            StringBuilder sb        = new StringBuilder();
            Int32         halfMoves = 0;

            if (options == StringifyOptions.Proper)
            {
                halfMoves = position.HalfMoves;
                if (position.SideToMove == ColourClass.Black)
                {
                    sb.Append(halfMoves / 2 + 1);
                    sb.Append("... ");
                }
            }

            foreach (Int32 move in moves)
            {
                if ((halfMoves++ % 2) == 0)
                {
                    sb.Append(halfMoves / 2 + 1);
                    sb.Append('.');
                    if (options == StringifyOptions.Proper)
                    {
                        sb.Append(' ');
                    }
                }
                sb.Append(MoveAlgebraically(position, move));
                sb.Append(' ');
                position.Make(move);
            }
            for (Int32 i = moves.Count - 1; i >= 0; i--)
            {
                position.Unmake(moves[i]);
            }

            return(sb.ToString(0, sb.Length - 1));
        }
示例#6
0
文件: JSON.cs 项目: huycn/json4uwp
 static void DoWriteObject(StringBuilder output, object obj, PropertySerializer[] props, StringifyOptions options)
 {
     if (props.Length > 0)
     {
         output.Append('{');
         foreach (var entry in props)
         {
             DoWriteString(output, (options & StringifyOptions.LowerCamelCase) != 0 ? ToLowerCamelCase(entry.Key) : entry.Key);
             output.Append(':');
             entry.WriteValue(output, obj, options);
             output.Append(',');
         }
         output[output.Length - 1] = '}';
     }
     else
     {
         output.Append("{}");
     }
 }
示例#7
0
文件: JSON.cs 项目: huycn/json4uwp
 static void WriteDateTime(StringBuilder output, object value, StringifyOptions options)
 {
     output.Append(((DateTime)value).ToUniversalTime().ToString(DATETIME_FORMAT, CultureInfo.InvariantCulture));
 }
示例#8
0
文件: JSON.cs 项目: huycn/json4uwp
 static void WritePrimitive(StringBuilder output, object value, StringifyOptions options)
 {
     output.Append(Convert.ToString(value, CultureInfo.InvariantCulture));
 }
示例#9
0
文件: JSON.cs 项目: huycn/json4uwp
 static void WriteBoolean(StringBuilder output, object value, StringifyOptions options)
 {
     output.Append((bool)value ? "true" : "false");
 }
示例#10
0
文件: JSON.cs 项目: huycn/json4uwp
 static void WriteJsonValue(StringBuilder output, object value, StringifyOptions options)
 {
     output.Append(((IJsonValue)value).Stringify());
 }