本文整理汇总了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;
}
示例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;
}
示例3: Deserialize
public object Deserialize(
StreamReader streamReader,
SerializationContext serializationContext,
PropertyMetaData propertyMetaData = null)
{
return streamReader.ReadInt16();
}
示例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;
}
示例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;
}
示例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);
}
}
}
示例7: Deserialize
public object Deserialize(
StreamReader streamReader,
SerializationContext serializationContext,
PropertyMetaData propertyMetaData = null)
{
return this.serializer.Deserialize(streamReader, serializationContext, propertyMetaData);
}
示例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;
}
示例9: Serialize
public override void Serialize(SerializationContext context)
{
base.Serialize(context);
int target = (Owner != null) ? Owner.ServerIndex : -1;
context.Write(target);
}
示例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);
}
示例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");
}
示例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 );
}
示例13: ByteArray
public ByteArray(byte[] buffer, SerializationContext serializationContext)
{
this.serializationContext = serializationContext;
memoryStream = new MemoryStream(buffer);
ReloadStreams();
}
示例14: GetObjectData
public override void GetObjectData(SerializationContext output)
{
base.GetObjectData(output);
output.WriteVersion(1);
output.Write(ROM);
}
示例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);
}