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