当前位置: 首页>>代码示例>>C#>>正文


C# ISerializable类代码示例

本文整理汇总了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();
 }
开发者ID:r0llup,项目名称:ProjectReport,代码行数:7,代码来源:Serializer.cs

示例2: SerializeObject

        public void SerializeObject(string name, ISerializable serObject)
        {
            XElement subElem = new XElement(name);
            serObject.Serialize(new XmlSerializer(subElem));

            elem.Add(subElem);
        }
开发者ID:doanhtdpl,项目名称:boom-game,代码行数:7,代码来源:XmlSerializer.cs

示例3: LoguearObservaciones

 public void LoguearObservaciones( string mensaje, ISerializable serializable )
 {
     if ( !string.IsNullOrEmpty( mensaje ) )
     {
         this.Loguear( serializable.Serializar() + "\r\n" + mensaje );
     }
 }
开发者ID:GonzaloFernandoA,项目名称:FacturacionElectronica,代码行数:7,代码来源:LogueadorFe.cs

示例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;
		}
开发者ID:chharam,项目名称:Capstone_IPM_RV,代码行数:8,代码来源:NamedPipeBase.cs

示例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);
		}
开发者ID:chharam,项目名称:Capstone_IPM_RV,代码行数:9,代码来源:NamedPipeBase.cs

示例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);
        }
开发者ID:dotnet,项目名称:corefx,代码行数:9,代码来源:StrongNameKeyPairTests.netstandard1.7.cs

示例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);
        }
开发者ID:Crome696,项目名称:ServUO,代码行数:11,代码来源:QueuedMemoryWriter.cs

示例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;
		}
开发者ID:mikhp,项目名称:greatmaps,代码行数:53,代码来源:RemoteFoxitServer.cs

示例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);
                }
            }
        }
开发者ID:YAWL,项目名称:YAWL.Serialization,代码行数:16,代码来源:BinaryWriteSerializerTests.cs

示例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;
 }
开发者ID:rogeralsing,项目名称:Migrant,代码行数:16,代码来源:SurrogateForISerializable.cs

示例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;
                    }
                    
                }
开发者ID:vlapchenko,项目名称:nfx,代码行数:18,代码来源:CompositeCustomData.cs

示例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;
		}
开发者ID:mikhp,项目名称:greatmaps,代码行数:21,代码来源:RemoteFoxitStub.cs

示例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;
        }
开发者ID:Gothen111,项目名称:2DWorld,代码行数:22,代码来源:IOManager.cs

示例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;
        }
开发者ID:windygu,项目名称:asxinyunet,代码行数:32,代码来源:ObjectInfo.cs

示例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;
        }
开发者ID:rafidzal,项目名称:OpenADK-csharp,代码行数:53,代码来源:MessageDispatcherTests.cs


注:本文中的ISerializable类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。