/// <summary> /// Serializes an object into a SerializationInfo object. /// </summary> /// <param name="obj">Object to be serialized.</param> /// <returns></returns> public SerializationInfoContainer SerializeObject(object obj) { SerializationInfoContainer info; if (obj == null) { if (!this._serializationReferences.TryGetValue(NullPlaceholder.Instance, out info)) { info = new SerializationInfoContainer(this._serializationReferences.Count + 1) { TypeName = NullPlaceholder.TypeShortName }; this._serializationReferences.Add(NullPlaceholder.Instance, info); } } else { var thisType = obj.GetType(); //if (thisType.IsSerializable) //{ // throw new InvalidOperationException(string.Format("Object Not Serializable Formatted: {0}", thisType.FullName)); //} var mobile = obj as IMobileObject; if (mobile == null) { throw new InvalidOperationException(string.Format("{0} must implement IMobileObject", thisType.Name)); } if (!this._serializationReferences.TryGetValue(mobile, out info)) { info = new SerializationInfoContainer(this._serializationReferences.Count + 1); this._serializationReferences.Add(mobile, info); info.TypeName = thisType.AssemblyQualifiedName; var context = new SerializationContainerContext(info, this); mobile.SerializeRef(context); context.IsProcessingState = true; mobile.SerializeState(context); } } return(info); }
public void Serialize(Stream serializationStream, object value) { if (SerializationInfoContainer.IsState(value.GetType())) { value = new SysState() { TypeName = value.GetType().AssemblyQualifiedName, Value = value }; } else if (!(value is IMobileObject)) { new BinaryFormatterWrapper().Serialize(serializationStream, value); return; } new MobileFormatter().Serialize(serializationStream, value); }
public bool IsState(Type stateType) { return(SerializationInfoContainer.IsState(stateType)); }
public SerializationContainerContext(SerializationInfoContainer core, MobileFormatter refFormatter) { this._core = core; this._refFormatter = refFormatter; }