Example #1
0
        private IMPObject UnrollDictionary(IDictionary dict)
        {
            IMPObject   obj2       = MPObject.NewInstance();
            IEnumerator enumerator = dict.Keys.GetEnumerator();

            try
            {
                while (enumerator.MoveNext())
                {
                    string        current = (string)enumerator.Current;
                    MPDataWrapper val     = WrapField(dict[current]);
                    if (val == null)
                    {
                        throw new Exception(string.Concat("Cannot serialize field of dictionary with key: ", current, ", ", dict[current], " -- unsupported type!"));
                    }
                    obj2.Put(current, val);
                }
            }
            finally
            {
                IDisposable disposable = enumerator as IDisposable;
                if (disposable != null)
                {
                    disposable.Dispose();
                }
            }
            return(obj2);
        }
Example #2
0
        private void ConvertCsObj(object csObj, IMPObject mpObj)
        {
            Type   type     = csObj.GetType();
            string fullName = type.FullName;

            if (!(mpObj is Serializable))
            {
                throw new Exception(string.Concat("Cannot serialize object: ", csObj, ", type: ", fullName, " -- It doesn't implement the SerializableSFSType interface"));
            }
            IMPArray val = MPArray.NewInstance();

            mpObj.PutUtfString(CLASS_MARKER_KEY, fullName);
            mpObj.PutMPArray(CLASS_FIELDS_KEY, val);
            foreach (FieldInfo info in type.GetFields(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance))
            {
                string        name    = info.Name;
                object        obj2    = info.GetValue(csObj);
                IMPObject     obj3    = MPObject.NewInstance();
                MPDataWrapper wrapper = WrapField(obj2);
                if (wrapper != null)
                {
                    obj3.PutUtfString(FIELD_NAME_KEY, name);
                    obj3.Put(FIELD_VALUE_KEY, wrapper);
                    val.AddMPObject(obj3);
                }
                else
                {
                    throw new Exception(string.Concat("Cannot serialize field of object: ", csObj, ", field: ", name, ", type: ", info.GetType().Name, " -- unsupported type!"));
                }
            }
        }