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


C# ISerializer.Serialize方法代码示例

本文整理汇总了C#中ISerializer.Serialize方法的典型用法代码示例。如果您正苦于以下问题:C# ISerializer.Serialize方法的具体用法?C# ISerializer.Serialize怎么用?C# ISerializer.Serialize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ISerializer的用法示例。


在下文中一共展示了ISerializer.Serialize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Serialize

 public void Serialize(ISerializer serializer)
 {
     serializer.Serialize(() => Name, v => Name = v);
     serializer.Serialize(() => Age, v => Age = v);
     serializer.Serialize(() => IsEmployed, v => IsEmployed = v);
     serializer.Serialize(() => Paychecks, v => Paychecks = v);
     serializer.Serialize(() => Related, v => Related = v);
 }
开发者ID:YAWL,项目名称:YAWL.Serialization,代码行数:8,代码来源:Person.cs

示例2: ToString

 public string ToString(ISerializer serializer)
 {
     var serialize = serializer.Serialize(this);
     var envelope = new Envelope
     {
         Type = GetType(),
         Content = serialize
     };
     return serializer.Serialize(envelope);
 }
开发者ID:FerdinandOlivier,项目名称:Warewolf-ESB,代码行数:10,代码来源:Memo.cs

示例3: TestSerializer

        // generic test for any serializer implementation
        private void TestSerializer(ISerializer<LogEntry<TestOperation>> serializer)
        {
            var testMessage = new TestOperation
            {
                StringValue = "STRING",
                BoolValue = true,
                IntValue = 42,
                ArrayValue = new int[] { 2, 4, 6, 8 }
            };
            var testEntry = new LogEntry<TestOperation>(new LogEntryId(1, 2), testMessage);
            using (var stream = new MemoryStream())
            {
                stream.Position.Should().Be(0);
                stream.Length.Should().Be(0);

                // write the object to the stream
                serializer.Serialize(testEntry, stream);

                stream.Position.Should().NotBe(0);
                stream.Length.Should().NotBe(0);

                // read the object from the stream
                stream.Position = 0;
                var clone = serializer.Deserialize(stream);

                stream.Position.Should().NotBe(0);
                clone.Should().NotBeNull();
                clone.Id.Term.Should().Be(1);
                clone.Id.Index.Should().Be(2);
                clone.Operation.Should().NotBeNull();
                clone.Operation.StringValue.Should().Be("STRING");
                clone.Operation.BoolValue.Should().BeTrue();
                clone.Operation.IntValue.Should().Be(42);
                clone.Operation.ArrayValue.Should().HaveCount(4);

                // write the clone to the stream (as a second entry)
                clone.Operation.StringValue = "MODIFIED";
                serializer.Serialize(clone, stream);

                // read the stream back, we expect to find 2 entries
                // reading beyond the end of the stream will result in nulls
                stream.Position = 0;
                var clone1 = serializer.Deserialize(stream);
                var clone2 = serializer.Deserialize(stream);
                var clone3 = serializer.Deserialize(stream);
                clone1.Operation.Should().NotBeNull();
                clone2.Operation.Should().NotBeNull();
                clone3.Operation.Should().BeNull();

                clone1.Operation.StringValue.Should().Be("STRING");
                clone2.Operation.StringValue.Should().Be("MODIFIED");
            }

        }
开发者ID:OrleansContrib,项目名称:Orleans.Consensus,代码行数:55,代码来源:SerializerTests.cs

示例4: Save

        /// <summary>
        /// Sauvegarde le modèle dans le fichier spécifié avec le sérialiseur donné
        /// </summary>
        /// <param name="model">modèle à sauvegarder</param>
        /// <param name="filename">nom du fichier de destination</param>
        /// <param name="serializer">sérialiseur utilisé</param>
        public static void Save(IDocumentData model, string filename, ISerializer serializer)
        {            
            /*IControlData[] controls = new IControlData[model.ControlsDictionary.Count()];

            for(int i=0; i<model.ControlsDictionary.Count(); i++)
            {
                string key = model.ControlsDictionary.Keys[i];
                IControlData control = model.ControlsDictionary[key];
                controls[i] = control;
            }
            string serialization = serializer.Serialize(controls);*/
            string[][] test = new string[model.ControlsDictionary.Count][];
            ControlDataWrapper[] controls = new ControlDataWrapper[model.ControlsDictionary.Count];
            for(int indexControl=0; indexControl<model.ControlsDictionary.Count; indexControl++)
            {
                string key = model.ControlsDictionary.Keys[indexControl];
                SortedList<string, string> properties = model.ControlsDictionary[key].Properties;
                PropertyDataWrapper[] listproperties = new PropertyDataWrapper[properties.Count];
                test[indexControl] = new string[properties.Count];
                for(int indexProperty=0; indexProperty<properties.Count(); indexProperty++)
                {
                    string property = properties.Keys[indexProperty];
                    string value = properties[property];
                    listproperties[indexProperty] = new PropertyDataWrapper(property, value);
                }
                string controlName = model.ControlsDictionary[key].Name;
                string controlType = model.ControlsDictionary[key].Type;
                controls[indexControl] = new ControlDataWrapper(controlName, controlType, listproperties);
            }

            string serialization = serializer.Serialize(controls);
            ControlDataWrapper[] final = serializer.UnSerialize(serialization);

            SaveFile(filename, serialization);
        }
开发者ID:NicolasR,项目名称:Composants,代码行数:41,代码来源:FileSerializer.cs

示例5: TestSerialization

        void TestSerialization(ISerializer serializer)
        {
            DummSerializableClass dummyTestClass = new DummSerializableClass();
            dummyTestClass.BoolProperty = true;
            dummyTestClass.IntProperty = 5;
            dummyTestClass.LongProperty = (long)int.MaxValue * 2;
            dummyTestClass.DecimalProperty = (decimal)5.1;
            dummyTestClass.DoubleProperty = 5.3;
            dummyTestClass.StringProperty = "test";
            dummyTestClass.SubClassProperty = new DummySubClass() { Id = 15, Name = "test name" };
            dummyTestClass.ListProperty = new List<DummySubClass>();
            dummyTestClass.ListProperty.Add(new DummySubClass() { Id = 200, Name = "child 1 test name" });
            dummyTestClass.ListProperty.Add(new DummySubClass() { Id = 201, Name = "child 2 test name" });

            DummSerializableClass deserialized = (DummSerializableClass)serializer.Deserialize(serializer.Serialize(dummyTestClass));
            Assert.AreNotEqual(dummyTestClass, deserialized);
            Assert.AreEqual(dummyTestClass.BoolProperty, deserialized.BoolProperty);
            Assert.AreEqual(dummyTestClass.IntProperty, deserialized.IntProperty);
            Assert.AreEqual(dummyTestClass.LongProperty, deserialized.LongProperty);
            Assert.AreEqual(dummyTestClass.DecimalProperty, deserialized.DecimalProperty);
            Assert.AreEqual(dummyTestClass.DoubleProperty, deserialized.DoubleProperty);
            Assert.AreEqual(dummyTestClass.StringProperty, deserialized.StringProperty);
            Assert.AreEqual(dummyTestClass.SubClassProperty.Name, deserialized.SubClassProperty.Name);
            Assert.AreEqual(dummyTestClass.SubClassProperty.Id, deserialized.SubClassProperty.Id);
            Assert.AreEqual(dummyTestClass.ListProperty.Count(), deserialized.ListProperty.Count());
            Assert.AreEqual(dummyTestClass.ListProperty[0].Id, deserialized.ListProperty[0].Id);
            Assert.AreEqual(dummyTestClass.ListProperty[0].Name, deserialized.ListProperty[0].Name);
            Assert.AreEqual(dummyTestClass.ListProperty[1].Id, deserialized.ListProperty[1].Id);
            Assert.AreEqual(dummyTestClass.ListProperty[1].Name, deserialized.ListProperty[1].Name);
        }
开发者ID:arumata,项目名称:Thingie.Tracking,代码行数:30,代码来源:SerializerTests.cs

示例6: WriteResponseDto

 private static void WriteResponseDto(HttpListenerResponse response, ISerializer serializer, MyDummyResponse responseDto)
 {
     using (var writer = new StreamWriter(response.OutputStream, Encoding.UTF8))
     {
         serializer.Serialize(writer, responseDto);
     }
 }
开发者ID:andreasetti,项目名称:TestFirst.Net,代码行数:7,代码来源:SerializerRequestProcessor.cs

示例7: Save

        /// <summary>
        /// Saves the specified model to the stream using the serializer.
        /// </summary>
        /// <param name="model">The model.</param>
        /// <param name="stream">The stream.</param>
        /// <param name="serializer">The serializer.</param>
        public static void Save(this ModelBase model, Stream stream, ISerializer serializer)
        {
            Argument.IsNotNull("model", model);
            Argument.IsNotNull("stream", stream);
            Argument.IsNotNull("serializer", serializer);

            serializer.Serialize(model, stream);
        }
开发者ID:matthijskoopman,项目名称:Catel,代码行数:14,代码来源:ModelBaseExtensions.serialization.cs

示例8: CreateResponse

 private static Response CreateResponse(dynamic model, ISerializer serializer)
 {
     return new Response
     {
         Contents = stream => serializer.Serialize("application/xml", model, stream),
         ContentType = "application/xml",
         StatusCode = HttpStatusCode.OK
     };
 }
开发者ID:jbattermann,项目名称:Nancy,代码行数:9,代码来源:XmlProcessor.cs

示例9: WriteResponse

        /// <summary>
        /// 처리 결과를 Http Response에 쓴다.
        /// </summary>
        /// <param name="response"></param>
        /// <param name="xdsResponse"></param>
        /// <param name="serializer"></param>
        internal static void WriteResponse(HttpResponse response, XdsResponseDocument xdsResponse, ISerializer serializer) {
            response.Clear();
            response.Buffer = true;
            response.Expires = -1;
            response.ContentEncoding = XmlTool.XmlEncoding;
            response.ContentType = "text/xml";

            var responseBytes = serializer.Serialize(xdsResponse.ConvertToBytes());

            response.OutputStream.Write(responseBytes, 0, responseBytes.Length);

            // XmlTool.Serialize(xdsResponse, response.OutputStream);
        }
开发者ID:debop,项目名称:NFramework,代码行数:19,代码来源:XmlDataServiceFacade.cs

示例10: DoCommit

 private static void DoCommit(Uri commitUri, ExecutionConfiguration executionConfiguration, ISerializer serializer)
 {
     Request.With(executionConfiguration)
        .Post(commitUri.AddPath("commit"))
        .WithJsonContent(serializer.Serialize(new CypherStatementList()))
        .WithExpectedStatusCodes(HttpStatusCode.OK)
        .Execute();
 }
开发者ID:KodrAus,项目名称:Neo4jClient,代码行数:8,代码来源:Neo4jTransaction.cs

示例11: SetBodyParameters

 /// <summary>
 /// 将参数序列化并写入为Body
 /// </summary>
 /// <param name="serializer">序列化工具</param>
 /// <param name="parameters">参数</param>
 /// <exception cref="SerializerException"></exception>
 public void SetBodyParameters(ISerializer serializer, params object[] parameters)
 {
     if (parameters == null || parameters.Length == 0)
     {
         return;
     }
     var builder = new ByteBuilder(Endians.Big);
     foreach (var item in parameters)
     {
         // 序列化参数为二进制内容
         var paramBytes = serializer.Serialize(item);
         // 添加参数内容长度            
         builder.Add(paramBytes == null ? 0 : paramBytes.Length);
         // 添加参数内容
         builder.Add(paramBytes);
     }
     this.Body = builder.ToArray();
 }
开发者ID:cityjoy,项目名称:NetworkSocket,代码行数:24,代码来源:FastPacket.cs

示例12: GetJsonContents

 private static Action<Stream> GetJsonContents(dynamic model, ISerializer serializer)
 {
     return stream => serializer.Serialize("text/csv", model, stream);
 }
开发者ID:apxnowhere,项目名称:Encore,代码行数:4,代码来源:CsvResponse.cs

示例13: Serialize

 /// <summary>
 /// Serializes the specified obj.
 /// </summary>
 /// <param name="obj">The obj.</param>
 /// <param name="serializer">The serializer.</param>
 /// <returns></returns>
 public string Serialize(object obj, ISerializer serializer)
 {
     if (obj is ICollection && !(obj is IDictionary<string, object>))
         return serializer.Serialize(FromCollection((ICollection)obj, serializer));
     else
         return serializer.Serialize(FromObject(obj, serializer));
 }
开发者ID:managedfusion,项目名称:managedfusion,代码行数:13,代码来源:Serializer.cs

示例14: Serialize

 public void Serialize(ISerializer serializer, BinaryWriter binary, object value)
 {
   var type = value.GetType();
   if (type.IsArray)
   {
     var array = (Array)value;
     binary.Write(TypeCode.Array);
     TypeSpecifier.Write(binary, type);
     binary.Write(array.Rank);
     for (var i = 0; i < array.Rank; ++i)
     {
       binary.Write(array.GetLength(i));
     }
     var indexer = new Int32[array.Rank];
     while (!IsEnd(array, indexer))
     {
       serializer.Serialize(serializer, binary, array.GetValue(indexer));
       Next(array, indexer);
     }
   }
   else if (type == typeof(string))
   {
     var stringValue = (string)value;
     binary.Write(TypeCode.String);
     binary.Write(System.Text.Encoding.ASCII.GetByteCount(stringValue));
     binary.Write(System.Text.Encoding.ASCII.GetBytes(stringValue));
   }
   else if (type == typeof(Byte))
   {
     binary.Write(TypeCode.Byte);
     binary.Write((Byte)value);
   }
   else if (type == typeof(Int16))
   {
     binary.Write(TypeCode.Int16);
     binary.Write((Int16)value);
   }
   else if (type == typeof(Int32))
   {
     binary.Write(TypeCode.Int32);
     binary.Write((Int32)value);
   }
   else if (type == typeof(Int64))
   {
     binary.Write(TypeCode.Int64);
     binary.Write((Int64)value);
   }
   else if (type == typeof(Double))
   {
     binary.Write(TypeCode.Double);
     binary.Write((Double)value);
   }
   else if (type == typeof(Single))
   {
     binary.Write(TypeCode.Single);
     binary.Write((Single)value);
   }
   else if (type.IsInstanceOfGenericType(typeof(Dictionary<,>)))
   {
     var dictionary = (IDictionary)value;
     binary.Write(TypeCode.Dictionary);
     TypeSpecifier.Write(binary, type);
     binary.Write(dictionary.Keys.Count);
     foreach (var key in dictionary.Keys)
     {
       serializer.Serialize(serializer, binary, key);
       serializer.Serialize(serializer, binary, dictionary[key]);
     }
   }
   else if (type.IsInstanceOfGenericType(typeof(List<>)))
   {
     var collection = (IList)value;
     binary.Write(TypeCode.List);
     TypeSpecifier.Write(binary, type);
     binary.Write(collection.Count);
     foreach (var el in collection)
     {
       serializer.Serialize(serializer, binary, el);
     }
   }
   else
   {
     binary.Write(TypeCode.Object);
     TypeSpecifier.Write(binary, type);
     CustomBinarySerializer.Serializers.ForObject(type).Serialize(serializer, binary, value);
   }
 }
开发者ID:jlewallen,项目名称:machine.serialization,代码行数:87,代码来源:DefaultSerializer.cs

示例15: Execute

        /// <summary>
        /// 
        /// </summary>
        /// <param name="requestBytes"></param>
        /// <param name="productName"></param>
        /// <param name="serializer"></param>
        /// <returns></returns>
        public static byte[] Execute(byte[] requestBytes, string productName, ISerializer serializer) {
            if(productName.IsWhiteSpace())
                productName = AdoTool.DefaultDatabaseName;

            XdsResponseDocument xdsResponse = null;
            byte[] result = null;

            try {
                Guard.Assert(requestBytes != null && requestBytes.Length > 0, "요청 정보가 없습니다.");
                XmlDataServiceFacade.CheckProductExists(productName);

                var requestData = (byte[])serializer.Deserialize(requestBytes);
                var xdsRequest = requestData.ConvertToXdsRequestDocument(XmlTool.XmlEncoding);
                xdsResponse = XmlDataServiceFacade.Execute(xdsRequest, productName);
            }
            catch(Exception ex) {
                if(log.IsErrorEnabled)
                    log.ErrorException("예외가 발생했습니다.", ex);

                if(xdsResponse == null)
                    xdsResponse = new XdsResponseDocument();
                xdsResponse.ReportError(ex);
            }
            finally {
                byte[] xdsResponseBytes;
                XmlTool.Serialize(xdsResponse, out xdsResponseBytes);

                result = serializer.Serialize(xdsResponseBytes);
            }
            return result;
        }
开发者ID:debop,项目名称:NFramework,代码行数:38,代码来源:XmlDataServiceFacade.cs


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