private void ConvertCsObj(object csObj, ISFSObject sfsObj) { Type type = csObj.GetType(); string fullName = type.FullName; SerializableSFSType serializableSFSType = csObj as SerializableSFSType; if (serializableSFSType == null) { throw new SFSCodecError(string.Concat("Cannot serialize object: ", csObj, ", type: ", fullName, " -- It doesn't implement the SerializableSFSType interface")); } ISFSArray iSFSArray = SFSArray.NewInstance(); sfsObj.PutUtfString(CLASS_MARKER_KEY, fullName); sfsObj.PutSFSArray(CLASS_FIELDS_KEY, iSFSArray); FieldInfo[] fields = type.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); FieldInfo[] array = fields; foreach (FieldInfo fieldInfo in array) { string name = fieldInfo.Name; object value = fieldInfo.GetValue(csObj); ISFSObject iSFSObject = SFSObject.NewInstance(); SFSDataWrapper sFSDataWrapper = WrapField(value); if (sFSDataWrapper != null) { iSFSObject.PutUtfString(FIELD_NAME_KEY, name); iSFSObject.Put(FIELD_VALUE_KEY, sFSDataWrapper); iSFSArray.AddSFSObject(iSFSObject); continue; } throw new SFSCodecError(string.Concat("Cannot serialize field of object: ", csObj, ", field: ", name, ", type: ", fieldInfo.GetType().Name, " -- unsupported type!")); } }
private ISFSObject UnrollDictionary(Hashtable dict) { ISFSObject iSFSObject = SFSObject.NewInstance(); IEnumerator enumerator = dict.Keys.GetEnumerator(); try { while (enumerator.MoveNext()) { string text = (string)enumerator.Current; SFSDataWrapper sFSDataWrapper = WrapField(dict[text]); if (sFSDataWrapper == null) { throw new SFSCodecError(string.Concat("Cannot serialize field of dictionary with key: ", text, ", ", dict[text], " -- unsupported type!")); } iSFSObject.Put(text, sFSDataWrapper); } return(iSFSObject); } finally { IDisposable disposable; if ((disposable = enumerator as IDisposable) != null) { disposable.Dispose(); } } }
private ISFSObject decodeSFSObject(JsonData jdo) { ISFSObject iSFSObject = SFSObjectLite.NewInstance(); foreach (string key in jdo.Keys) { JsonData jdo2 = jdo[key]; SFSDataWrapper sFSDataWrapper = decodeJsonObject(jdo2); if (sFSDataWrapper != null) { iSFSObject.Put(key, sFSDataWrapper); continue; } throw new InvalidOperationException("JSON > ISFSObject error: could not decode value for key: " + key); } return(iSFSObject); }
internal void send(SmartfoxCommand socketCommands, IDictionary <string, SFSDataWrapper> parameters = null, object[] commandParameters = null, bool useUDP = false) { ISFSObject iSFSObject = SFSObject.NewInstance(); if (parameters != null) { foreach (string key in parameters.Keys) { iSFSObject.Put(key, parameters[key]); } } Room currentRoom = getCurrentRoom(); if (currentRoom != null) { string text = socketCommands.GetCommand(); if (commandParameters != null) { text = string.Format(text, commandParameters); } send(new ExtensionRequest(text, iSFSObject, currentRoom, useUDP && isUDPEstablished)); } }