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


C# SerializationContext类代码示例

本文整理汇总了C#中SerializationContext的典型用法代码示例。如果您正苦于以下问题:C# SerializationContext类的具体用法?C# SerializationContext怎么用?C# SerializationContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: ConvertStringToLayoutInfo

        public LayoutInfo ConvertStringToLayoutInfo(string layoutInfo, Store store)
        {
            LayoutInfo lInfo = null;

            Microsoft.VisualStudio.Modeling.SerializationResult serializationResult = new Microsoft.VisualStudio.Modeling.SerializationResult();
            DomainXmlSerializerDirectory directory = this.GetDirectory(store);
            System.Text.Encoding encoding = System.Text.Encoding.GetEncoding("ISO-8859-1");
            Microsoft.VisualStudio.Modeling.SerializationContext serializationContext = new SerializationContext(directory, "", serializationResult);
            this.InitializeSerializationContext(store.DefaultPartition, serializationContext, false);

            DomainClassXmlSerializer rootSerializer = directory.GetSerializer(LayoutInfo.DomainClassId);
            using(System.Xml.XmlReader reader = System.Xml.XmlReader.Create(new System.IO.StringReader(layoutInfo)) )
            {
                
                reader.Read(); // Move to the first node - will be the XmlDeclaration if there is one.
                serializationResult.Encoding = encoding;

                reader.MoveToContent();

                lInfo = rootSerializer.TryCreateInstance(serializationContext, reader, store.DefaultPartition) as LayoutInfo;
                rootSerializer.Read(serializationContext, lInfo, reader);
            }

            return lInfo;
        }
开发者ID:apoorv-vijay-joshi,项目名称:FSE-2011-PDE,代码行数:25,代码来源:SerializationHelper.cs

示例2: DetermineEnumSerializationMethod

		/// <summary>
		///		Determines <see cref="EnumSerializationMethod"/> for the target.
		/// </summary>
		/// <param name="context">Context information.</param>
		/// <param name="enumType">The target enum type.</param>
		/// <param name="enumMemberSerializationMethod">The method argued by the member.</param>
		/// <returns>Determined <see cref="EnumSerializationMethod"/> for the target.</returns>
		public static EnumSerializationMethod DetermineEnumSerializationMethod(
			SerializationContext context,
			Type enumType,
			EnumMemberSerializationMethod enumMemberSerializationMethod )
		{
			EnumSerializationMethod method = context.EnumSerializationMethod;
			switch ( enumMemberSerializationMethod )
			{
				case EnumMemberSerializationMethod.ByName:
				{
					method = EnumSerializationMethod.ByName;
					break;
				}
				case EnumMemberSerializationMethod.ByUnderlyingValue:
				{
					method = EnumSerializationMethod.ByUnderlyingValue;
					break;
				}
				default:
				{
					var attributesOnType = enumType.GetCustomAttributes( typeof( MessagePackEnumAttribute ), false );
					if ( attributesOnType.Length > 0 )
					{
						// ReSharper disable once PossibleNullReferenceException
						method = ( attributesOnType[ 0 ] as MessagePackEnumAttribute ).SerializationMethod;
					}

					break;
				}
			}

			return method;
		}
开发者ID:eslo,项目名称:msgpack-cli,代码行数:40,代码来源:EnumMessagePackSerializerHelper.cs

示例3: Deserialize

 public object Deserialize(
     StreamReader streamReader, 
     SerializationContext serializationContext, 
     PropertyMetaData propertyMetaData = null)
 {
     return streamReader.ReadInt16();
 }
开发者ID:gordonc64,项目名称:AOtomation.Messaging,代码行数:7,代码来源:Int16Serializer.cs

示例4: Serialize

        internal static int Serialize(Guid value, SerializationContext context, bool lengthPrefix)
        {
            if (value == Guid.Empty)
            {
                if (lengthPrefix)
                {
                    context.WriteByte(0);
                    return 1;
                }
                return 0;
            }
            byte[] buffer = value.ToByteArray();

            int len = 0;
            if (lengthPrefix)
            {
                context.WriteByte((byte)18);
                len = 1;
            }
            context.WriteByte(FieldLo << 3 | (int)WireType.Fixed64);
            context.WriteBlock(buffer, 0, 8);
            context.WriteByte(FieldHi << 3 | (int)WireType.Fixed64);
            context.WriteBlock(buffer, 8, 8);
            return len + 18;
        }
开发者ID:Klaudit,项目名称:inbox2_desktop,代码行数:25,代码来源:ProtoGuid.cs

示例5: Deserialize

        public object Deserialize(
            StreamReader streamReader,
            SerializationContext serializationContext,
            PropertyMetaData propertyMetaData = null)
        {
            var mess = new GenericCmdMessage();
            mess.N3MessageType = (N3MessageType)streamReader.ReadInt32();
            mess.Identity = streamReader.ReadIdentity();
            mess.Unknown = streamReader.ReadByte();
            mess.Temp1 = streamReader.ReadInt32();
            mess.Count = streamReader.ReadInt32();
            mess.Action = (GenericCmdAction)streamReader.ReadInt32();
            mess.Temp4 = streamReader.ReadInt32();
            mess.User = streamReader.ReadIdentity();
            int len = 1;
            if (mess.Action == GenericCmdAction.UseItemOnItem)
            {
                len = 2;
            }

            mess.Target = new Identity[len];
            for (int i = 0; i < mess.Target.Length; i++)
            {
                mess.Target[i] = streamReader.ReadIdentity();
            }
            return mess;
        }
开发者ID:gordonc64,项目名称:AOtomation.Messaging,代码行数:27,代码来源:GenericCmdSerializer.cs

示例6: WritePropertiesAsElements

        private static void WritePropertiesAsElements(SerializationContext serializationContext, MetaModelLibrary element, global::System.Xml.XmlWriter writer)
        {
            // FilePath
            if (!serializationContext.Result.Failed)
            {
                global::System.String propValue = element.FilePath;
                if (!serializationContext.Result.Failed)
                {
                    if (!string.IsNullOrEmpty(propValue))
                        LanguageDSLSerializationHelper.Instance.WriteElementString(serializationContext, element, writer, "filePath", propValue);

                }
            }
            // Name
            if (!serializationContext.Result.Failed)
            {
                global::System.String propValue = element.Name;
                if (!serializationContext.Result.Failed)
                {
                    if (!string.IsNullOrEmpty(propValue))
                        LanguageDSLSerializationHelper.Instance.WriteElementString(serializationContext, element, writer, "name", propValue);

                }
            }
        }
开发者ID:apoorv-vijay-joshi,项目名称:FSE-2011-PDE,代码行数:25,代码来源:MetaModelLibrarySerializer.cs

示例7: Deserialize

 public object Deserialize(
     StreamReader streamReader, 
     SerializationContext serializationContext, 
     PropertyMetaData propertyMetaData = null)
 {
     return this.serializer.Deserialize(streamReader, serializationContext, propertyMetaData);
 }
开发者ID:gordonc64,项目名称:AOtomation.Messaging,代码行数:7,代码来源:DiagnosticSerializer.cs

示例8: Deserialize

        public object Deserialize(
            StreamReader streamReader, 
            SerializationContext serializationContext, 
            PropertyMetaData propertyMetaData = null)
        {
            var identityType = (IdentityType)streamReader.ReadInt32();
            if (identityType != IdentityType.VendingMachine)
            {
                streamReader.Position = streamReader.Position - 4;
                return null;
            }

            var playfieldVendorInfo = new PlayfieldVendorInfo
                                          {
                                              Unknown1 =
                                                  new Identity
                                                      {
                                                          Type = identityType, 
                                                          Instance = streamReader.ReadInt32()
                                                      }, 
                                              Unknown2 = streamReader.ReadInt32(), 
                                              VendorCount = streamReader.ReadInt32(), 
                                              FirstVendorId = streamReader.ReadInt32()
                                          };
            return playfieldVendorInfo;
        }
开发者ID:gordonc64,项目名称:AOtomation.Messaging,代码行数:26,代码来源:PlayfieldVendorInfoSerializer.cs

示例9: Serialize

        public override void Serialize(SerializationContext context)
        {
            base.Serialize(context);

            int target = (Owner != null) ? Owner.ServerIndex : -1;
            context.Write(target);
        }
开发者ID:cody82,项目名称:spacewar-arena,代码行数:7,代码来源:Program.cs

示例10: ExportSolution

        public void ExportSolution()
        {
            DDay.iCal.iCalendar iCal = new DDay.iCal.iCalendar();
            var t = new DBManager();
            t.initInputData();
            t.initOutputData();
            foreach(ScheduledTimeSlot[] solution in (t.solutions))
            {
                for (int i = 0; i < solution.Length; i++)
                {
                    Event evt = iCal.Create<Event>();

                    evt.Start = iCalDateTime.Today.AddHours((int)solution[i].timeSlot.StartHour).AddDays((int)(solution[i].timeSlot.Day));

                    evt.End = iCalDateTime.Today.AddHours((int)solution[i].timeSlot.EndHour).AddDays((int)(solution[i].timeSlot.Day));

                    evt.Summary = string.Join(", ", solution[i].groups.Select(g => g.name));

                    evt.Location = solution[i].room.nameOrNumber;
                }
                break;
            }

            ISerializationContext ctx = new SerializationContext();
            ISerializerFactory factory = new DDay.iCal.Serialization.iCalendar.SerializerFactory();
            // Get a serializer for our object
            IStringSerializer serializer = factory.Build(iCal.GetType(), ctx) as IStringSerializer;

            string output = serializer.SerializeToString(iCal);
            var bytes = Encoding.UTF8.GetBytes(output);

            File.WriteAllBytes("solution.ics", bytes);
        }
开发者ID:victoria92,项目名称:university-program-generator,代码行数:33,代码来源:ICalGenerator.cs

示例11: Index

        // GET: Calendar
        public ActionResult Index()
        {
            foreach (var r in Request.Params.AllKeys)
            {
                System.Diagnostics.Debug.WriteLine(r + " = " + Request.Params[r]);
            }

            var iCal = new iCalendar();

            Event evt = iCal.Create<Event>();
            evt.Start = iCalDateTime.Today.AddHours(8);
            evt.End = evt.Start.AddHours(18); // This also sets the duration
            evt.Description = "The event description";
            evt.Location = "Event location";
            evt.Summary = "18 hour event summary";
            
            evt = iCal.Create<Event>();
            evt.Start = iCalDateTime.Today.AddDays(5);
            evt.End = evt.Start.AddDays(1);
            evt.IsAllDay = true;
            evt.Summary = "All-day event";

            ISerializationContext ctx = new SerializationContext();
            ISerializerFactory factory = new DDay.iCal.Serialization.iCalendar.SerializerFactory();
            IStringSerializer serializer = factory.Build(iCal.GetType(), ctx) as IStringSerializer;

            string output = serializer.SerializeToString(iCal);
            var bytes = System.Text.Encoding.UTF8.GetBytes(output);

            return File(bytes, "text/calendar");
        }
开发者ID:Stevoman,项目名称:StevesDocket,代码行数:32,代码来源:CalendarController.cs

示例12: DynamicMethodEmittingContext

		/// <summary>
		///		Initializes a new instance of the <see cref="DynamicMethodEmittingContext"/> class.
		/// </summary>
		/// <param name="context">The serialization context.</param>
		/// <param name="targetType">Type of the serialization target.</param>
		/// <param name="emitterFactory">
		///		The factory for <see cref="SerializerEmitter"/> to be used.
		/// </param>
		/// <param name="enumEmitterFactory">
		///		The factory for <see cref="EnumSerializerEmitter"/> to be used.
		/// </param>
		public DynamicMethodEmittingContext( SerializationContext context, Type targetType,
			Func<SerializerEmitter> emitterFactory, Func<EnumSerializerEmitter> enumEmitterFactory )
			: base( context, emitterFactory, enumEmitterFactory )
		{
			this._context = ILConstruct.Argument( 0, typeof( SerializationContext ), "context" );
			this.Reset( targetType, null );
		}
开发者ID:gezidan,项目名称:ZYSOCKET,代码行数:18,代码来源:DynamicMethodEmittingContext.cs

示例13: ByteArray

        public ByteArray(byte[] buffer, SerializationContext serializationContext)
        {
            this.serializationContext = serializationContext;

            memoryStream = new MemoryStream(buffer);
            ReloadStreams();
        }
开发者ID:GodLesZ,项目名称:rtmp-sharp,代码行数:7,代码来源:ByteArray.cs

示例14: GetObjectData

        public override void GetObjectData(SerializationContext output)
        {
            base.GetObjectData(output);

            output.WriteVersion(1);
            output.Write(ROM);
        }
开发者ID:CadeLaRen,项目名称:BizHawk,代码行数:7,代码来源:CartA4K.cs

示例15: SaveToFile

 public void SaveToFile(string icsFilename) {
     var ctx = new SerializationContext();
     var factory = new SerializerFactory();
     var serializer = factory.Build(ical.GetType(), ctx) as IStringSerializer;
     var content = serializer.SerializeToString(ical);
     File.WriteAllText(icsFilename, content);
 }
开发者ID:slieser,项目名称:sandbox2,代码行数:7,代码来源:Calendar.cs


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