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


C# SerializationWriter.Write方法代码示例

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


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

示例1: Serialize

		public static void Serialize(SerializationWriter writer, Color color)
		{
			BitVector32 flags = new BitVector32();

			if (color.IsKnownColor)
				flags[ColorIsKnown] = true;
			else if (color.IsNamedColor)
				flags[ColorHasName] = true;
			else if (!color.IsEmpty)
			{
				flags[ColorHasValue] = true;
				flags[ColorHasRed] = color.R != 0;
				flags[ColorHasGreen] = color.G != 0;
				flags[ColorHasBlue] = color.B != 0;
				flags[ColorHasAlpha] = color.A != 0;
			}
			writer.WriteOptimized(flags);

			if (color.IsKnownColor)
				writer.WriteOptimized((int) color.ToKnownColor());
			else if (color.IsNamedColor)
				writer.WriteOptimized(color.Name);
			else if (!color.IsEmpty)
			{
				byte component;
				if ( (component = color.R) != 0) writer.Write(component);	
				if ( (component = color.G) != 0) writer.Write(component);	
				if ( (component = color.B) != 0) writer.Write(component);	
				if ( (component = color.A) != 0) writer.Write(component);	
			}
		}
开发者ID:elementar,项目名称:Suprifattus.Util,代码行数:31,代码来源:DrawingFastSerializationHelper.cs

示例2: TestNull

        public void TestNull()
        {
            using (MemoryStream ms = new MemoryStream())
            using (SerializationWriter sw = new SerializationWriter(ms))
            using (SerializationReader sr = new SerializationReader(ms))
            {
                sw.Write<object>(null);

                sw.Write<int[]>(null);
                sw.Write<List<int>>(null);
                sw.Write<Dictionary<int, string>>(null);

                sw.Write<TestSerializable>(null);
            }
        }
开发者ID:smoogipooo,项目名称:SerializationLib,代码行数:15,代码来源:RangeTests.cs

示例3: GetObjectData

		public virtual void GetObjectData(SerializationInfo info, StreamingContext context)
		{
			using (SerializationWriter writer = new SerializationWriter())
			{
				writer.Write(_name);
				writer.WriteObject(_dataType);
				writer.WriteObject(_value);
				info.AddValue("d", writer.ToArray());
			}

		}
开发者ID:uQr,项目名称:Visual-NHibernate,代码行数:11,代码来源:UserOption.cs

示例4: TestUTF16Chars

        public void TestUTF16Chars()
        {
            using (MemoryStream ms = new MemoryStream())
            using (SerializationWriter sw = new SerializationWriter(ms, new UnicodeEncoding()))
            using (SerializationReader sr = new SerializationReader(ms, new UnicodeEncoding()))
            {
                for (int i = 0; i < 55296; i++)
                    sw.Write((char)i);

                sw.Flush();
                ms.Position = 0;

                for (int i = 0; i < 55296; i++)
                    Assert.AreEqual((char)i, sr.Read<char>());
            }
        }
开发者ID:smoogipooo,项目名称:SerializationLib,代码行数:16,代码来源:StringTests.cs

示例5: TestUTF16String

        public void TestUTF16String()
        {
            using (MemoryStream ms = new MemoryStream())
            using (SerializationWriter sw = new SerializationWriter(ms, new UnicodeEncoding()))
            using (SerializationReader sr = new SerializationReader(ms, new UnicodeEncoding()))
            {
                StringBuilder sb = new StringBuilder();
                for (int i = 0; i < 55296; i++)
                    sb.Append((char)i);
                string res = sb.ToString();
                sw.Write(res);

                sw.Flush();
                ms.Position = 0;

                Assert.AreEqual(res, sr.Read<string>());
            }
        }
开发者ID:smoogipooo,项目名称:SerializationLib,代码行数:18,代码来源:StringTests.cs

示例6: TestBytes

        public void TestBytes()
        {
            Random rand = new Random();

            using (MemoryStream ms = new MemoryStream())
            using (SerializationWriter sw = new SerializationWriter(ms))
            using (SerializationReader sr = new SerializationReader(ms))
            {
                byte[] values = new byte[Config.MULTI_TEST_COUNT];
                rand.NextBytes(values);
                for (int i = 0; i < Config.MULTI_TEST_COUNT; i++)
                    sw.Write(values[i]);

                sw.Flush();
                ms.Position = 0;

                for (int i = 0; i < Config.MULTI_TEST_COUNT; i++)
                    Assert.AreEqual(values[i], sr.Read<byte>());
            }
        }
开发者ID:smoogipooo,项目名称:SerializationLib,代码行数:20,代码来源:PrimitiveTests.cs

示例7: TestBasicList

        public void TestBasicList()
        {
            Random rand = new Random();

            using (MemoryStream ms = new MemoryStream())
            using (SerializationWriter sw = new SerializationWriter(ms))
            using (SerializationReader sr = new SerializationReader(ms))
            {
                List<int> list = new List<int>(Config.MULTI_TEST_COUNT);
                for (int i = 0; i < Config.MULTI_TEST_COUNT; i++)
                    list.Add(rand.Next(int.MinValue, int.MaxValue));
                sw.Write(list);

                sw.Flush();
                ms.Position = 0;

                List<int> ret = sr.Read<List<int>>();
                for (int i = 0; i < list.Count; i++)
                    Assert.AreEqual(list[i], ret[i]);
            }
        }
开发者ID:smoogipooo,项目名称:SerializationLib,代码行数:21,代码来源:ArrayTests.cs

示例8: TestBasicDictionary

        public void TestBasicDictionary()
        {
            Random rand = new Random();

            using (MemoryStream ms = new MemoryStream())
            using (SerializationWriter sw = new SerializationWriter(ms))
            using (SerializationReader sr = new SerializationReader(ms))
            {
                Dictionary<int, float> dict = new Dictionary<int, float>(Config.MULTI_TEST_COUNT);
                for (int i = 0; i < Config.MULTI_TEST_COUNT; i++)
                    dict[rand.Next(int.MinValue, int.MaxValue)] = (float)rand.NextDouble();
                sw.Write(dict);

                sw.Flush();
                ms.Position = 0;

                Dictionary<int, float> ret = sr.Read<Dictionary<int, float>>();
                foreach (KeyValuePair<int, float> kvp in dict)
                    Assert.AreEqual(kvp.Value, ret[kvp.Key]);
            }
        }
开发者ID:smoogipooo,项目名称:SerializationLib,代码行数:21,代码来源:ArrayTests.cs

示例9: TestBasicArray

        public void TestBasicArray()
        {
            Random rand = new Random();

            using (MemoryStream ms = new MemoryStream())
            using (SerializationWriter sw = new SerializationWriter(ms))
            using (SerializationReader sr = new SerializationReader(ms))
            {
                int[] array = new int[Config.MULTI_TEST_COUNT];
                for (int i = 0; i < Config.MULTI_TEST_COUNT; i++)
                    array[i] = rand.Next(int.MinValue, int.MaxValue);
                sw.Write(array);

                sw.Flush();
                ms.Position = 0;

                int[] ret = sr.Read<int[]>();
                for (int i = 0; i < ret.Length; i++)
                    Assert.AreEqual(array[i], ret[i]);
            }
        }
开发者ID:smoogipooo,项目名称:SerializationLib,代码行数:21,代码来源:ArrayTests.cs

示例10: TestBools

        public void TestBools()
        {
            Random rand = new Random();

            using (MemoryStream ms = new MemoryStream())
            using (SerializationWriter sw = new SerializationWriter(ms))
            using (SerializationReader sr = new SerializationReader(ms))
            {
                bool[] values = new bool[Config.MULTI_TEST_COUNT];
                for (int i = 0; i < Config.MULTI_TEST_COUNT; i++)
                {
                    values[i] = rand.Next(0, 2) == 1;
                    sw.Write(values[i]);
                }

                sw.Flush();
                ms.Position = 0;

                for (int i = 0; i < Config.MULTI_TEST_COUNT; i++)
                    Assert.AreEqual(values[i], sr.Read<bool>());
            }
        }
开发者ID:smoogipooo,项目名称:SerializationLib,代码行数:22,代码来源:PrimitiveTests.cs

示例11: TestDateTimes

        public void TestDateTimes()
        {
            Random rand = new Random();

            using (MemoryStream ms = new MemoryStream())
            using (SerializationWriter sw = new SerializationWriter(ms))
            using (SerializationReader sr = new SerializationReader(ms))
            {
                DateTime[] values = new DateTime[Config.MULTI_TEST_COUNT];

                for (int i = 0; i < Config.MULTI_TEST_COUNT; i++)
                {
                    values[i] = new DateTime(rand.Next(1970, 5623), rand.Next(1, 13), rand.Next(1, 29), rand.Next(0, 24), rand.Next(0, 60), rand.Next(0, 60), DateTimeKind.Utc);
                    sw.Write(values[i]);
                }

                sw.Flush();
                ms.Position = 0;

                for (int i = 0; i < Config.MULTI_TEST_COUNT; i++)
                    Assert.AreEqual(values[i], sr.Read<DateTime>());
            }
        }
开发者ID:smoogipooo,项目名称:SerializationLib,代码行数:23,代码来源:PrimitiveTests.cs

示例12: Serialize

        private void Serialize(ref SerializationWriter mySerializationWriter, DirectoryEntry myDirectoryEntry)
        {
            try
            {

                #region Write the InlineData

                mySerializationWriter.Write(myDirectoryEntry._InlineData);

                #endregion

                #region Write the INodePositions

                mySerializationWriter.WriteUInt32((UInt32)myDirectoryEntry.INodePositions.Count);

                foreach (var _ExtendedPosition in myDirectoryEntry.INodePositions)
                {
                    _ExtendedPosition.StorageUUID.Serialize(ref mySerializationWriter);
                    mySerializationWriter.WriteUInt64(_ExtendedPosition.Position);
                }

                #endregion

                #region Write the ObjectStreamsList

                mySerializationWriter.WriteUInt32((UInt32)myDirectoryEntry.ObjectStreamsList.Count);

                foreach (var _ObjectStreamType in myDirectoryEntry.ObjectStreamsList)
                    mySerializationWriter.WriteString(_ObjectStreamType);

                #endregion

                myDirectoryEntry.isDirty = false;

            }

            catch (SerializationException e)
            {
                throw new SerializationException(e.Message);
            }
        }
开发者ID:ipbi,项目名称:sones,代码行数:41,代码来源:DirectoryEntry.cs

示例13: GetObjectData

        protected override void GetObjectData(SerializationWriter sw)
        {
            if (sw == null) {
                throw new ArgumentNullException("sw");
            }

            base.GetObjectData(sw);

            sw.Write(_IsOp);
            sw.Write(_IsVoice);
        }
开发者ID:tuukka,项目名称:smuxi,代码行数:11,代码来源:IrcGroupPersonModel.cs

示例14: GetObjectData

 public override void GetObjectData(SerializationInfo info, StreamingContext context)
 {
     #if FAST_SERIALIZATION
     using (SerializationWriter writer = new SerializationWriter())
     {
         writer.Write(_alias);
         writer.Write(_characterMaximumLength);
         writer.Write(_dataType);
         writer.Write(_direction);
         writer.Write(_enabled);
         writer.Write(_isUserDefined);
         writer.Write(_name);
         writer.Write(_ordinalPosition);
         writer.WriteObject(_userOptions);
         writer.Write(_precision);
         writer.Write(_scale);
         info.AddValue("d", writer.ToArray());
     }
     #else
     info.AddValue("SerializationVersion", SerializationVersion);
     info.AddValue("Alias", _alias);
     info.AddValue("CharacterMaximumLength", _characterMaximumLength);
     info.AddValue("DataType", _dataType);
     info.AddValue("Direction", _direction);
     info.AddValue("Enabled", _enabled);
     //info.AddValue("ExposedUserOptions", _exposedUserOptions);
     info.AddValue("IsUserDefined", _isUserDefined);
     info.AddValue("Name", _name);
     info.AddValue("OrdinalPosition", _ordinalPosition);
     info.AddValue("UserOptions", _userOptions);
     info.AddValue("Precision", _precision);
     info.AddValue("Scale", _scale);
     #endif
 }
开发者ID:uQr,项目名称:Visual-NHibernate,代码行数:34,代码来源:StoredProcedure.cs

示例15: Serialize

 public void Serialize(SerializationWriter writer)
 {
     writer.Write(strength);
     writer.Write(weight);
 }
开发者ID:killix,项目名称:Virsona-ChatBot-Tools,代码行数:5,代码来源:ProbableStrength.cs


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