Example #1
0
        /// <summary>
        /// Export to marshalling hash
        /// </summary>
        /// <returns>marshalling hash</returns>
        public MarshallingHash ExportToHash()
        {
            MarshallingHash hash = new MarshallingHash(this.Get("name"));

            this.Copy(false, hash);
            return(hash);
        }
Example #2
0
        /// <summary>
        /// Import an object
        /// </summary>
        /// <param name="hash">from hash</param>
        /// <returns>master object</returns>
        public static T Import <T>(MarshallingHash hash) where T : PersistentDataObject, new()
        {
            T t = new T();

            t.Set("name", hash.Name);
            hash.Copy(false, t);
            return(t);
        }
 /// <summary>
 /// Construct for a list with a list of value
 /// </summary>
 /// <param name="name">name of the value</param>
 /// <param name="keyValues">values</param>
 public MarshallingList(string name, IEnumerable <dynamic> keyValues)
 {
     this.Set(nameName, name);
     for (int index = 0; index < keyValues.Count(); ++index)
     {
         dynamic element = keyValues.ElementAt(index);
         if (element is bool)
         {
             MarshallingBoolValue b = new MarshallingBoolValue(index.ToString(), element);
             this.Set(index.ToString(), b);
         }
         else if (element is string)
         {
             MarshallingRegexValue r = new MarshallingRegexValue(index.ToString(), element, "^.*$");
             this.Set(index.ToString(), r);
         }
         else if (element is long || element is int || element is uint)
         {
             MarshallingIntValue i = new MarshallingIntValue(index.ToString(), Convert.ToInt32(element));
             this.Set(index.ToString(), i);
         }
         else if (element is double)
         {
             MarshallingDoubleValue d = new MarshallingDoubleValue(index.ToString(), element);
             this.Set(index.ToString(), d);
         }
         else if (element is IMarshalling)
         {
             this.Set(index.ToString(), element);
         }
         else if (element is IEnumerable <dynamic> )
         {
             MarshallingList ml = new MarshallingList(index.ToString(), element as IEnumerable <dynamic>);
             this.Set(index.ToString(), ml);
         }
         else if (element is IDictionary <string, dynamic> )
         {
             MarshallingHash mh = new MarshallingHash(index.ToString(), element as IDictionary <string, dynamic>);
             this.Set(index.ToString(), mh);
         }
         else
         {
             MarshallingObjectValue o = new MarshallingObjectValue(index.ToString(), element);
             this.Set(index.ToString(), o);
         }
     }
 }
 /// <summary>
 /// Construction for a hash
 /// </summary>
 /// <param name="name">name of value</param>
 /// <param name="keyValues">dictionary</param>
 public MarshallingHash(string name, IDictionary <string, dynamic> keyValues)
 {
     this.Set(nameName, name);
     foreach (KeyValuePair <string, dynamic> kv in keyValues)
     {
         if (kv.Value is bool)
         {
             MarshallingBoolValue b = new MarshallingBoolValue(kv.Key, kv.Value);
             this.Set(kv.Key, b);
         }
         else if (kv.Value is string)
         {
             MarshallingRegexValue r = new MarshallingRegexValue(kv.Key, kv.Value, "^.*$");
             this.Set(kv.Key, r);
         }
         else if (kv.Value is long || kv.Value is int || kv.Value is uint)
         {
             MarshallingIntValue i = new MarshallingIntValue(kv.Key, Convert.ToInt32(kv.Value));
             this.Set(kv.Key, i);
         }
         else if (kv.Value is double || kv.Value is float)
         {
             MarshallingDoubleValue d = new MarshallingDoubleValue(kv.Key, kv.Value);
             this.Set(kv.Key, d);
         }
         else if (kv.Value is IMarshalling)
         {
             this.Set(kv.Key, kv.Value);
         }
         else if (kv.Value is IEnumerable <dynamic> )
         {
             MarshallingList ml = new MarshallingList(kv.Key, kv.Value as IEnumerable <dynamic>);
             this.Set(kv.Key, ml);
         }
         else if (kv.Value is IDictionary <string, dynamic> )
         {
             MarshallingHash mh = new MarshallingHash(kv.Key, kv.Value as IDictionary <string, dynamic>);
             this.Set(kv.Key, mh);
         }
         else
         {
             MarshallingObjectValue o = new MarshallingObjectValue(kv.Key, kv.Value);
             this.Set(kv.Key, o);
         }
     }
 }
        /// <summary>
        /// Export to hash
        /// </summary>
        /// <returns>hash</returns>
        public MarshallingHash ExportToHash()
        {
            MarshallingHash hash = new MarshallingHash(this.Name, this.Entries);

            return(hash);
        }