Пример #1
0
        /// <summary>
        /// Expand this expando with the public members of another object.
        /// </summary>
        /// <param name="other">The other object.</param>
        /// <returns>This expanded FastExpando.</returns>
        public FastExpando Expand(object other)
        {
            if (other == null)
            {
                throw new ArgumentNullException("other");
            }

            return(Expand(FastExpando.FromObject(other)));
        }
Пример #2
0
        /// <summary>
        /// Creates an expando from an object.
        /// </summary>
        /// <param name="value">The object to initialize with.</param>
        /// <returns>A FastExpando containing the public properties and fields of obj.</returns>
        public static FastExpando FromObject(object value)
        {
            // don't bother converting expandos
            FastExpando x = value as FastExpando;

            if (x != null)
            {
                return(x);
            }

            return(ExpandoGenerator.Convert(value));
        }
Пример #3
0
        /// <summary>
        /// Expand this expando with the members of another expando.
        /// </summary>
        /// <param name="expando">The other expando.</param>
        /// <returns>This expanded FastExpando.</returns>
        public FastExpando Expand(FastExpando expando)
        {
            if (expando == null)
            {
                throw new ArgumentNullException("expando");
            }

            foreach (var pair in expando)
            {
                data[pair.Key] = pair.Value;
            }

            return(this);
        }
Пример #4
0
        /// <summary>
        /// Copies the FastExpando while mapping the fields given the map.
        /// </summary>
        /// <param name="map">The map of input fields to output fields.</param>
        /// <returns>A modified copy of the expando.</returns>
        public FastExpando Transform(IDictionary <string, string> map)
        {
            FastExpando other = new FastExpando();

            foreach (var pair in data)
            {
                other.data.Add(pair.Key, pair.Value);
            }

            // mutate the results
            other.Mutate(map);

            return(other);
        }
Пример #5
0
        /// <summary>
        /// Drops the specified field from the expando if it is null.
        /// </summary>
        /// <param name="fields">The name of the field(s) to drop or null to drop all fields.</param>
        /// <returns>A new expando.</returns>
        public FastExpando WithoutNulls(IEnumerable <string> fields = null)
        {
            FastExpando other = new FastExpando();

            foreach (var pair in data)
            {
                if (pair.Value == null && (fields == null || fields.Any(f => String.Compare(pair.Key, f, StringComparison.OrdinalIgnoreCase) == 0)))
                {
                    continue;
                }

                other.data.Add(pair.Key, pair.Value);
            }

            return(other);
        }
 /// <summary>
 /// Converts an object to a FastExpando.
 /// </summary>
 /// <typeparam name="T1">The type of object to merge into.</typeparam>
 /// <typeparam name="T2">The type of object to merge.</typeparam>
 /// <param name="obj1">The object to convert.</param>
 /// <param name="obj2">The other object to merge in.</param>
 /// <returns>A fast expando containing the public properties of the object.</returns>
 public static FastExpando Expand <T1, T2>(this T1 obj1, T2 obj2)
 {
     return(FastExpando.FromObject(obj1).Expand(obj2));
 }
 /// <summary>
 /// Converts an object to a FastExpando.
 /// </summary>
 /// <typeparam name="T">The type of object to convert.</typeparam>
 /// <param name="obj">The object to convert.</param>
 /// <returns>A fast expando containing the public properties of the object.</returns>
 public static FastExpando Expand <T>(this T obj)
 {
     return(FastExpando.FromObject(obj));
 }