Esempio n. 1
0
 private static void ConvertPoint(GenxyWriter writer, Point point)
 {
     writer.WriteToken(GenxyToken.Point);
     writer.WriteHexInteger(point.X);
     writer.WriteChar('.');
     writer.WriteHexInteger(point.Y);
 }
Esempio n. 2
0
        public static string Serialize(IEnumerable <KeyValuePair <string, object> > value)
        {
            if (value == null)
            {
                return(string.Empty);
            }

            using (var w = new GenxyWriter())
            {
                foreach (var kvp in value)
                {
                    if (!HasValue(kvp.Value))
                    {
                        continue;
                    }

                    w.WriteChar('#');
                    w.WriteString(kvp.Key);
                    w.WriteChar('=');
                    SerializeObject(w, kvp.Value);
                }

                return(w.ToString());
            }
        }
Esempio n. 3
0
 public static string SerializeObject(object value)
 {
     using (var w = new GenxyWriter())
     {
         SerializeObject(w, value);
         return(w.ToString());
     }
 }
Esempio n. 4
0
 private static void ConvertArea(GenxyWriter writer, Area area)
 {
     writer.WriteToken(GenxyToken.Area);
     writer.WriteHexInteger(area.X1);
     writer.WriteChar('.');
     writer.WriteHexInteger(area.Y1);
     writer.WriteChar('.');
     writer.WriteHexInteger(area.X2);
     writer.WriteChar('.');
     writer.WriteHexInteger(area.Y2);
 }
Esempio n. 5
0
 private static void ConvertColor(GenxyWriter writer, Color color)
 {
     writer.WriteToken(GenxyToken.Color);
     writer.WriteHexInteger(color.R);
     writer.WriteChar('.');
     writer.WriteHexInteger(color.G);
     writer.WriteChar('.');
     writer.WriteHexInteger(color.B);
     writer.WriteChar('.');
     writer.WriteHexInteger(color.A);
 }
Esempio n. 6
0
 private static void ConvertDateTime(GenxyWriter writer, DateTime date)
 {
     writer.WriteToken(GenxyToken.Date);
     writer.WriteInteger(date.Year);
     writer.WriteChar('.');
     writer.WriteInteger(date.Month);
     writer.WriteChar('.');
     writer.WriteInteger(date.Day);
     writer.WriteChar('.');
     writer.WriteInteger(date.Hour);
     writer.WriteChar('.');
     writer.WriteInteger(date.Minute);
     writer.WriteChar('.');
     writer.WriteInteger(date.Second);
 }
Esempio n. 7
0
        private static void SerializeObject(GenxyWriter writer, object value)
        {
            if (value == null)
            {
                return;
            }

            switch (value)
            {
            case string s: { ConvertString(writer, s); return; }

            case string[] stringArray: { ConvertStringArray(writer, stringArray); return; }

            case int i: { ConvertInt(writer, i); return; }

            case int[] intArray: { ConvertIntArray(writer, intArray); return; }
            }

            var type = value.GetType();

            if (!_converters.TryGetValue(type, out Converter c))
            {
                if (type.IsEnum)
                {
                    var tc = Convert.GetTypeCode(value);

                    switch (tc)
                    {
                    case TypeCode.Int32:
                        ConvertInt(writer, (int)value);
                        return;

                    case TypeCode.Int64:
                        ConvertLong(writer, (long)value);
                        return;
                    }
                }

                Debug.Assert(false, "unknown type" + type);
            }

            c(writer, value);
        }
Esempio n. 8
0
        private static void ConvertEnumerableStringObject(GenxyWriter writer, IEnumerable <KeyValuePair <string, object> > d)
        {
            writer.WriteToken(GenxyToken.StartProp);

            foreach (var kvp in d)
            {
                if (!HasValue(kvp.Value))
                {
                    continue;
                }

                writer.WriteToken(GenxyToken.Prop);
                writer.WriteString(kvp.Key);
                writer.WriteChar('=');
                SerializeObject(writer, kvp.Value);
            }

            writer.WriteToken(GenxyToken.EndProp);
        }
Esempio n. 9
0
 private static void ConvertPositionArray(GenxyWriter writer, Position[] value)
 {
     writer.WriteToken(GenxyToken.PositionArray);
     writer.WriteArray(value, writer.WritePosition);
 }
Esempio n. 10
0
 private static void ConvertDecimalArray(GenxyWriter writer, decimal[] value)
 {
     writer.WriteToken(GenxyToken.DecimalArray);
     writer.WriteArray(value, writer.WriteDecimal);
 }
Esempio n. 11
0
 private static void ConvertExpandoObject(GenxyWriter writer, ExpandoObject value)
 {
     ConvertEnumerableStringObject(writer, value);
 }
Esempio n. 12
0
 private static void ConvertDecimal(GenxyWriter writer, decimal value)
 {
     writer.WriteToken(GenxyToken.Decimal);
     writer.WriteDecimal(value);
 }
Esempio n. 13
0
 private static void ConvertIntArray(GenxyWriter writer, int[] value)
 {
     writer.WriteToken(GenxyToken.IntegerArray);
     writer.WriteArray(value, writer.WriteHexInteger);
 }
Esempio n. 14
0
 private static void ConvertLongArray(GenxyWriter writer, long[] longArray)
 {
     writer.WriteToken(GenxyToken.LongArray);
     writer.WriteArray(longArray, writer.WriteLong);
 }
Esempio n. 15
0
 public static void ConvertInt(GenxyWriter writer, int value)
 {
     writer.WriteToken(GenxyToken.Integer);
     writer.WriteHexInteger(value);
 }
Esempio n. 16
0
 private static void ConvertString(GenxyWriter writer, string s)
 {
     writer.WriteToken(GenxyToken.String);
     writer.WriteEscapedString(s);
 }
Esempio n. 17
0
 private static void ConvertPosition(GenxyWriter writer, Position position)
 {
     writer.WriteToken(GenxyToken.Position);
     writer.WritePosition(position);
 }
Esempio n. 18
0
 private static void ConvertFloat(GenxyWriter writer, float value)
 {
     writer.WriteToken(GenxyToken.FloatBytes);
     writer.WriteFloatBytes(value);
 }
Esempio n. 19
0
 private static void CreateDoubleConverter(GenxyWriter writer, double value)
 {
     ConvertFloat(writer, (float)value);
 }
Esempio n. 20
0
 private static void ConvertStringArray(GenxyWriter writer, string[] stringArray)
 {
     writer.WriteToken(GenxyToken.StringArray);
     writer.WriteArray(stringArray, writer.WriteEscapedString);
 }
Esempio n. 21
0
 private static void ConvertByteArray(GenxyWriter writer, byte[] value)
 {
     writer.WriteToken(GenxyToken.ByteArray);
     writer.WriteString(BitConverter.ToString(value).Replace("-", ""));
 }
Esempio n. 22
0
 public static void ConvertLong(GenxyWriter writer, long value)
 {
     writer.WriteToken(GenxyToken.Long);
     writer.WriteLong(value);
 }
Esempio n. 23
0
 private static void ConvertGenxyString(GenxyWriter writer, GenxyString value)
 {
     writer.WriteToken(GenxyToken.StartProp);
     writer.WriteString(value.ToString().Replace('#', '|'));
     writer.WriteToken(GenxyToken.EndProp);
 }
Esempio n. 24
0
 private static void ConvertULong(GenxyWriter writer, ulong value)
 {
     writer.WriteToken(GenxyToken.Long);
     writer.WriteULong(value);
 }
Esempio n. 25
0
 private static void ConvertDictionary(GenxyWriter writer, Dictionary <string, object> dictionary)
 {
     ConvertEnumerableStringObject(writer, dictionary);
 }
Esempio n. 26
0
 private static void ConvertIntList(GenxyWriter writer, List <int> value)
 {
     ConvertIntArray(writer, value.ToArray());
 }
Esempio n. 27
0
 private static void ConvertNumber(GenxyWriter writer, object value)
 {
     ConvertInt(writer, Convert.ToInt32(value));
 }