Ejemplo n.º 1
0
        /// <summary>
        ///     Transforms a value intos its GraphSON representation including type information.
        /// </summary>
        /// <param name="typename">The name of the type.</param>
        /// <param name="value">The value to transform.</param>
        /// <param name="prefix">A namespace prefix for the typename.</param>
        /// <returns>The GraphSON representation including type information.</returns>
        public static Dictionary <string, dynamic> ToTypedValue(string typename, dynamic value, string prefix = "g")
        {
            var typedValue = new Dictionary <string, dynamic>
            {
                { GraphSONTokens.TypeKey, GraphSONUtil.FormatTypeName(prefix, typename) }
            };

            if (value != null)
            {
                typedValue[GraphSONTokens.ValueKey] = value;
            }
            return(typedValue);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Converts a Collection to a representation of g:List or g:Set
        /// </summary>
        internal static Dictionary <string, dynamic> ToCollection(dynamic objectData, IGraphSONWriter writer,
                                                                  string typename)
        {
            var collection = objectData as IEnumerable;

            if (collection == null)
            {
                throw new InvalidOperationException("Object must implement IEnumerable");
            }
            var result = new List <object>();

            foreach (var item in collection)
            {
                result.Add(writer.ToDict(item));
            }
            return(GraphSONUtil.ToTypedValue(typename, result));
        }
Ejemplo n.º 3
0
        public Dictionary <string, dynamic> Dictify(dynamic objectData, IGraphSONWriter writer)
        {
            var map = objectData as IDictionary;

            if (map == null)
            {
                throw new InvalidOperationException("Object must implement IDictionary");
            }
            var result = new object[map.Count * 2];
            var index  = 0;

            foreach (var key in map.Keys)
            {
                result[index++] = writer.ToDict(key);
                result[index++] = writer.ToDict(map[key]);
            }
            return(GraphSONUtil.ToTypedValue("Map", result));
        }
Ejemplo n.º 4
0
        public Dictionary <string, dynamic> Dictify(dynamic objectData, IGraphSONWriter writer)
        {
            TimeSpan value = objectData;

            return(GraphSONUtil.ToTypedValue("Duration", XmlConvert.ToString(value), "gx"));
        }
Ejemplo n.º 5
0
        public Dictionary <string, dynamic> Dictify(dynamic objectData, IGraphSONWriter writer)
        {
            EnumWrapper enumToSerialize = objectData;

            return(GraphSONUtil.ToTypedValue(enumToSerialize.EnumName, enumToSerialize.EnumValue));
        }
        public Dictionary <string, dynamic> Dictify(dynamic objectData, IGraphSONWriter writer)
        {
            BigInteger value = objectData;

            return(GraphSONUtil.ToTypedValue("BigInteger", value.ToString(), "gx"));
        }
Ejemplo n.º 7
0
        public Dictionary <string, dynamic> Dictify(dynamic objectData, IGraphSONWriter writer)
        {
            Guid guid = objectData;

            return(GraphSONUtil.ToTypedValue("UUID", guid));
        }
Ejemplo n.º 8
0
 public Dictionary <string, dynamic> Dictify(dynamic objectData, IGraphSONWriter writer)
 {
     return(GraphSONUtil.ToCollection(objectData, writer, "List"));
 }