本文整理汇总了C#中ISerializable类的典型用法代码示例。如果您正苦于以下问题:C# ISerializable类的具体用法?C# ISerializable怎么用?C# ISerializable使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ISerializable类属于命名空间,在下文中一共展示了ISerializable类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SerializeObject
public static void SerializeObject(String filename, ISerializable objectToSerialize)
{
Stream stream = File.Open(filename, FileMode.Create);
var bFormatter = new BinaryFormatter();
bFormatter.Serialize(stream, objectToSerialize);
stream.Close();
}
示例2: SerializeObject
public void SerializeObject(string name, ISerializable serObject)
{
XElement subElem = new XElement(name);
serObject.Serialize(new XmlSerializer(subElem));
elem.Add(subElem);
}
示例3: LoguearObservaciones
public void LoguearObservaciones( string mensaje, ISerializable serializable )
{
if ( !string.IsNullOrEmpty( mensaje ) )
{
this.Loguear( serializable.Serializar() + "\r\n" + mensaje );
}
}
示例4: Serialize
protected byte[] Serialize(ISerializable obj)
{
MemoryStream memoryStream = new MemoryStream();
this.binaryFormatter.Serialize(memoryStream, obj);
byte[] array = new byte[memoryStream.Length];
Array.Copy(memoryStream.GetBuffer(), array, memoryStream.Length);
return array;
}
示例5: SendMessage
protected void SendMessage(ISerializable request)
{
byte[] array = this.Serialize(request);
LengthRecord obj = new LengthRecord(array.Length);
byte[] array2 = this.Serialize(obj);
D.Assert(array2.Length == 147);
this.WriteBuffer(array2, array2.Length);
this.WriteBuffer(array, array.Length);
}
示例6: SNKeyPairDerivedClone
public SNKeyPairDerived SNKeyPairDerivedClone(ISerializable inter)
{
SerializationInfo info = new SerializationInfo(typeof(StrongNameKeyPair), new FormatterConverter());
StreamingContext context = new StreamingContext();
inter.GetObjectData(info, context);
return new SNKeyPairDerived(info, context);
}
示例7: QueueForIndex
public void QueueForIndex(ISerializable serializable, int size)
{
IndexInfo info;
info.size = size;
info.typeCode = serializable.TypeReference; //For guilds, this will automagically be zero.
info.serial = serializable.SerialIdentity;
this._orderedIndexInfo.Add(info);
}
示例8: Server
internal bool Server(object genericRequest, ref ISerializable reply)
{
if (genericRequest is OpenRequest)
{
OpenRequest openRequest = (OpenRequest)genericRequest;
if (this.foxitViewer != null)
{
reply = new ExceptionMessageRecord("Already open");
return true;
}
try
{
this.foxitViewer = new FoxitViewer(openRequest.filename, openRequest.pageNumber);
reply = new RectangleFRecord(this.foxitViewer.GetPageSize());
bool result = true;
return result;
}
catch (Exception ex)
{
reply = new ExceptionMessageRecord(ex.Message);
bool result = false;
return result;
}
}
if (genericRequest is RenderRequest)
{
RenderRequest renderRequest = (RenderRequest)genericRequest;
if (this.foxitViewer == null)
{
reply = new ExceptionMessageRecord("Not open");
return true;
}
try
{
reply = this.foxitViewer.RenderBytes(renderRequest.outputSize, renderRequest.topLeft, renderRequest.pageSize, renderRequest.transparentBackground);
bool result = true;
return result;
}
catch (Exception ex2)
{
reply = new ExceptionMessageRecord(ex2.Message);
bool result = true;
return result;
}
}
if (genericRequest is QuitRequest)
{
reply = new AckRecord();
return false;
}
reply = new ExceptionMessageRecord("Unrecognized request type " + genericRequest.GetType().ToString());
return true;
}
示例9: TestWrite
private void TestWrite(ISerializable serializable, Action<BinaryReader> check)
{
using (var ms = new MemoryStream())
using (var writer = new BinaryWriter(ms))
{
var serializer = new BinaryWriteSerializer();
serializer.Serialize(serializable, writer);
ms.Seek(0, SeekOrigin.Begin);
using (var reader = new BinaryReader(ms))
{
check(reader);
}
}
}
示例10: SurrogateForISerializable
public SurrogateForISerializable(ISerializable serializable)
{
var serializationInfo = new SerializationInfo(serializable.GetType(), new FormatterConverter());
var streamingContext = new StreamingContext(StreamingContextStates.Clone);
serializable.GetObjectData(serializationInfo, streamingContext);
keys = new string[serializationInfo.MemberCount];
values = new object[serializationInfo.MemberCount];
var i = 0;
foreach(var entry in serializationInfo)
{
keys[i] = entry.Name;
values[i] = entry.Value;
i++;
}
assemblyQualifiedName = serializable.GetType().AssemblyQualifiedName;
}
示例11: serializeFromISerializable
private void serializeFromISerializable(ISerializable data)
{
m_CustomData = new Dictionary<string,CustomTypedEntry>();
var info = new SerializationInfo(data.GetType(), new FormatterConverter());
StreamingContext streamingContext = new StreamingContext(StreamingContextStates.Persistence);
data.GetObjectData(info, streamingContext);
var senum = info.GetEnumerator();
while(senum.MoveNext())
{
var value = new CustomTypedEntry();
value.TypeIndex = MetaType.GetExistingOrNewMetaTypeIndex( m_Document, senum.ObjectType );
value.Data = m_Document.NativeDataToPortableData( senum.Value );
m_CustomData[senum.Name] = value;
}
}
示例12: RobustRPC
public object RobustRPC(ISerializable request)
{
object result;
try
{
this.Establish();
result = this.namedPipeServer.RPC(request);
}
catch (Exception)
{
this.Teardown();
this.Establish();
result = this.namedPipeServer.RPC(request);
}
this.namedPipeServer.childProcess.Refresh();
if (this.namedPipeServer.childProcess.VirtualMemorySize64 > 1073741824L || this.namedPipeServer.childProcess.HandleCount > 512)
{
this.Teardown();
}
return result;
}
示例13: SaveISerializeAbleObjectToFile
public static bool SaveISerializeAbleObjectToFile(String _File, ISerializable _ISerializableObject)
{
String var_Path = _File.Remove(_File.LastIndexOf("/"));
if (CreatePath(var_Path))
{
try
{
Utility.Serializer.SerializeObject(_File, _ISerializableObject);
return true;
}
catch
{
// Error!
}
}
else
{
// Error!
}
return false;
}
示例14: GetMembers
static IObjectMemberInfo[] GetMembers(ISerializable value, Type type)
{
IObjectMemberInfo[] mis = null;
if (value == null)
{
if (serialCache.TryGetValue(type, out mis)) return mis;
// 尝试创建type的实例
value = GetDefaultObject(type) as ISerializable;
}
SerializationInfo info = new SerializationInfo(type, new FormatterConverter());
value.GetObjectData(info, DefaultStreamingContext);
List<IObjectMemberInfo> list = new List<IObjectMemberInfo>();
foreach (SerializationEntry item in info)
{
list.Add(CreateObjectMemberInfo(item.Name, item.ObjectType, item.Value));
}
mis = list.ToArray();
if (!serialCache.ContainsKey(type))
{
lock (serialCache)
{
if (!serialCache.ContainsKey(type)) serialCache.Add(type, mis);
}
}
return mis;
}
示例15: createSIF_Request
// TODO: Implement
/*
private SIF_Request createSIF_Request( ElementDef objectType, String refId, Zone zone )
{
SIF_Request request = new SIF_Request();
request.getHeader().setSIF_MsgId( MSG_GUID );
request.getHeader().setSIF_SourceId( "foo" );
request.setSIF_MaxBufferSize("32768");
request.setSIF_Version( ADK.getSIFVersion().toString() );
Query query = new Query(objectType);
query.addCondition(SifDtd.SIF_REPORTOBJECT_REFID, Condition.EQ, refId);
SIF_Query q = SIFPrimitives.createSIF_Query(query, zone);
SIF_QueryObject sqo = new SIF_QueryObject();
sqo.setObjectName( objectType.name() );
q.setSIF_QueryObject(sqo);
request.setSIF_Query(q);
return request;
}
*/
private SIF_Response createSIF_Response(IElementDef objType, bool storeInRequestCache, ISerializable stateObject)
{
SIF_Request req = createSIF_Request(objType);
if (storeInRequestCache)
{
Query q = new Query(objType);
q.UserData = stateObject;
RequestCache.GetInstance(fAgent).StoreRequestInfo(req, q, fZone);
}
SIF_Response resp = new SIF_Response();
resp.SIF_RequestMsgId = req.Header.SIF_MsgId;
SIF_ObjectData sod = new SIF_ObjectData();
resp.SIF_ObjectData = sod;
Object responseObject = null;
try
{
responseObject = ClassFactory.CreateInstance(objType.FQClassName, false);
}
catch (Exception cfe)
{
throw new AdkException("Unable to create instance of " + objType.Name, fZone, cfe);
}
sod.AddChild((SifElement)responseObject);
return resp;
}