예제 #1
0
        //*********************************** MPObject to Class *********************************
        private object Mp2Cs(IMPObject mpObj)
        {
            if (!mpObj.ContainsKey(CLASS_MARKER_KEY) || !mpObj.ContainsKey(CLASS_FIELDS_KEY))
            {
                throw new Exception("The MPObject passed does not represent any serialized class.");
            }
            string utfString = mpObj.GetUtfString(CLASS_MARKER_KEY);
            Type   type      = Type.GetType(utfString);

            if (type == null)
            {
                throw new Exception("Cannot find type: " + utfString);
            }
            object csObj = Activator.CreateInstance(type);

            if (!(csObj is Serializable))
            {
                throw new Exception(string.Concat("Cannot deserialize object: ", csObj, ", type: ", utfString, " -- It doesn't implement the Serializable interface"));
            }
            ConvertMPObject(mpObj.GetMPArray(CLASS_FIELDS_KEY), csObj, type);
            return(csObj);
        }