本文整理汇总了C#中SerializationMode类的典型用法代码示例。如果您正苦于以下问题:C# SerializationMode类的具体用法?C# SerializationMode怎么用?C# SerializationMode使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SerializationMode类属于命名空间,在下文中一共展示了SerializationMode类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetStateSlotMetadata
/// <summary>
/// Generates the state slot metadata for the <paramref name="obj" />.
/// </summary>
/// <param name="obj">The object the state slot metadata should be generated for.</param>
/// <param name="objectIdentifier">The identifier of the <paramref name="obj" />.</param>
/// <param name="mode">The serialization mode that should be used to generate the metadata.</param>
protected internal override IEnumerable<StateSlotMetadata> GetStateSlotMetadata(object obj, int objectIdentifier, SerializationMode mode)
{
Requires.That(((Array)obj).Rank == 1 && !obj.GetType().GetElementType().IsArray, "Multidimensional arrays are not supported.");
var elementType = obj.GetType().GetElementType();
var length = ((Array)obj).GetLength(0);
if (elementType.IsStructType())
{
foreach (var metadataSlot in StateSlotMetadata.FromStruct(elementType, mode))
{
metadataSlot.Object = obj;
metadataSlot.ObjectIdentifier = objectIdentifier;
metadataSlot.ObjectType = obj.GetType();
metadataSlot.ElementCount = length;
yield return metadataSlot;
}
}
else
{
yield return new StateSlotMetadata
{
Object = obj,
ObjectIdentifier = objectIdentifier,
ObjectType = obj.GetType(),
DataType = obj.GetType().GetElementType(),
ElementCount = length
};
}
}
示例2: XmlObjectSerializerReadContextComplex
internal XmlObjectSerializerReadContextComplex(DataContractSerializer serializer, DataContract rootTypeDataContract, DataContractResolver dataContractResolver)
: base(serializer, rootTypeDataContract, dataContractResolver)
{
_mode = SerializationMode.SharedContract;
_preserveObjectReferences = serializer.PreserveObjectReferences;
_serializationSurrogateProvider = serializer.SerializationSurrogateProvider;
}
示例3: XmlObjectSerializerReadContextComplex
internal XmlObjectSerializerReadContextComplex(DataContractSerializer serializer, DataContract rootTypeDataContract, DataContractResolver dataContractResolver)
: base(serializer, rootTypeDataContract, dataContractResolver)
{
this.mode = SerializationMode.SharedContract;
this.preserveObjectReferences = serializer.PreserveObjectReferences;
this.dataContractSurrogate = serializer.DataContractSurrogate;
}
示例4: SerializeInternal
private static MvcHtmlString SerializeInternal(HtmlHelper htmlHelper, string name, object data, SerializationMode mode, bool useViewData, MvcSerializer serializer)
{
if (htmlHelper == null)
{
throw new ArgumentNullException("htmlHelper");
}
if (String.IsNullOrEmpty(name))
{
throw new ArgumentException(MvcResources.Common_NullOrEmpty, "name");
}
name = htmlHelper.ViewContext.ViewData.TemplateInfo.GetFullHtmlFieldName(name);
if (useViewData)
{
data = htmlHelper.ViewData.Eval(name);
}
string serializedData = (serializer ?? new MvcSerializer()).Serialize(data, mode);
TagBuilder builder = new TagBuilder("input");
builder.Attributes["type"] = "hidden";
builder.Attributes["name"] = name;
builder.Attributes["value"] = serializedData;
return MvcHtmlString.Create(builder.ToString(TagRenderMode.SelfClosing));
}
示例5: GetStateSlotMetadata
/// <summary>
/// Generates the state slot metadata for the <paramref name="obj" />.
/// </summary>
/// <param name="obj">The object the state slot metadata should be generated for.</param>
/// <param name="objectIdentifier">The identifier of the <paramref name="obj" />.</param>
/// <param name="mode">The serialization mode that should be used to generate the metadata.</param>
protected internal override IEnumerable<StateSlotMetadata> GetStateSlotMetadata(object obj, int objectIdentifier, SerializationMode mode)
{
foreach (var field in GetFields(obj, mode))
{
if (field.FieldType.IsStructType())
{
foreach (var metadataSlot in StateSlotMetadata.FromStruct(field.FieldType, mode))
{
metadataSlot.Object = obj;
metadataSlot.ObjectIdentifier = objectIdentifier;
metadataSlot.ObjectType = obj.GetType();
metadataSlot.ElementCount = 1;
metadataSlot.Field = field;
yield return metadataSlot;
}
}
else
{
yield return new StateSlotMetadata
{
Object = obj,
ObjectType = obj.GetType(),
ObjectIdentifier = objectIdentifier,
DataType = field.FieldType,
Field = field,
ElementCount = 1
};
}
}
}
示例6: Deserialize
internal static object Deserialize(string serializedValue, SerializationMode mode, IMachineKey machineKey) {
if (String.IsNullOrEmpty(serializedValue)) {
throw new ArgumentException(MvcResources.Common_NullOrEmpty, "serializedValue");
}
MachineKeyProtection protectionMode = GetMachineKeyProtectionMode(mode);
try {
// First, need to decrypt / verify data
byte[] rawBytes = machineKey.Decode(serializedValue, protectionMode);
// Next, verify magic header
if (!ArrayContainsMagicHeader(rawBytes)) {
throw new SerializationException(MvcResources.MvcSerializer_MagicHeaderCheckFailed);
}
// Finally, deserialize the object graph
using (MemoryStream ms = new MemoryStream(rawBytes, _magicHeader.Length, rawBytes.Length - _magicHeader.Length)) {
return DeserializeGraph(ms);
}
}
catch (Exception ex) {
throw CreateSerializationException(ex);
}
}
示例7: XmlObjectSerializerReadContextComplex
internal XmlObjectSerializerReadContextComplex(NetDataContractSerializer serializer) : base(serializer)
{
this.mode = SerializationMode.SharedType;
this.preserveObjectReferences = true;
this.binder = serializer.Binder;
this.surrogateSelector = serializer.SurrogateSelector;
this.assemblyFormat = serializer.AssemblyFormat;
}
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:8,代码来源:XmlObjectSerializerReadContextComplex.cs
示例8: GetFormatter
private static IStateFormatter GetFormatter(SerializationMode mode) {
Func<IStateFormatter> formatterFactory;
if (!_registeredFormatterFactories.TryGetValue(mode, out formatterFactory)) {
throw new ArgumentOutOfRangeException("mode", MvcResources.MvcSerializer_InvalidSerializationMode);
}
return formatterFactory();
}
示例9: GetFormatter
private static IStateFormatter GetFormatter(SerializationMode mode)
{
Func<IStateFormatter> formatterFactory;
if (!_factories.TryGetValue(mode, out formatterFactory))
throw Error.InvalidModelStateSerializationMode(mode);
return formatterFactory();
}
示例10: GetFields
/// <summary>
/// Gets the fields declared by the <paramref name="obj" /> that should be serialized.
/// </summary>
/// <param name="obj">The object that should be serialized.</param>
/// <param name="mode">The serialization mode that should be used to serialize the objects.</param>
/// <param name="startType">
/// The first type in <paramref name="obj" />'s inheritance hierarchy whose fields should be returned.
/// If <c>null</c>, corresponds to <paramref name="obj" />'s actual type.
/// </param>
/// <param name="inheritanceRoot">
/// The first base type of the <paramref name="obj" /> whose fields should be ignored. If
/// <c>null</c>, <see cref="object" /> is the inheritance root.
/// </param>
/// <param name="discoveringObjects">Indicates whether objects are being discovered.</param>
protected override IEnumerable<FieldInfo> GetFields(object obj, SerializationMode mode, Type startType = null, Type inheritanceRoot = null,
bool discoveringObjects = false)
{
var fields = base.GetFields(obj, mode, startType, inheritanceRoot, discoveringObjects);
if (mode == SerializationMode.Full || discoveringObjects)
return fields;
return fields.Where(field => field.Name == "_size");
}
示例11: XmlObjectSerializerWriteContextComplex
internal XmlObjectSerializerWriteContextComplex(NetDataContractSerializer serializer, Hashtable surrogateDataContracts)
: base(serializer)
{
this.mode = SerializationMode.SharedType;
this.preserveObjectReferences = true;
this.streamingContext = serializer.Context;
this.binder = serializer.Binder;
this.surrogateSelector = serializer.SurrogateSelector;
this.surrogateDataContracts = surrogateDataContracts;
}
示例12: ProfilePropertySettings
public ProfilePropertySettings(string name, bool readOnly, SerializationMode serializeAs, string providerName, string defaultValue, string profileType, bool allowAnonymous, string customProviderData)
{
this.Name = name;
this.ReadOnly = readOnly;
this.SerializeAs = serializeAs;
this.Provider = providerName;
this.DefaultValue = defaultValue;
this.Type = profileType;
this.AllowAnonymous = allowAnonymous;
this.CustomProviderData = customProviderData;
}
示例13: GetMachineKeyProtectionMode
private static MachineKeyProtection GetMachineKeyProtectionMode(SerializationMode mode) {
switch (mode) {
case SerializationMode.Signed:
return MachineKeyProtection.Validation;
case SerializationMode.EncryptedAndSigned:
return MachineKeyProtection.All;
default:
// bad
throw new ArgumentOutOfRangeException("mode", MvcResources.MvcSerializer_InvalidSerializationMode);
}
}
示例14: Deserialize
public virtual object Deserialize(string serializedValue, SerializationMode mode) {
if (String.IsNullOrEmpty(serializedValue)) {
throw new ArgumentException(MvcResources.Common_NullOrEmpty, "serializedValue");
}
IStateFormatter formatter = GetFormatter(mode);
try {
object deserializedValue = formatter.Deserialize(serializedValue);
return deserializedValue;
}
catch (Exception ex) {
throw CreateSerializationException(ex);
}
}
示例15: GetSerializer
public static ISerializer GetSerializer(SerializationMode mode)
{
switch(mode)
{
case SerializationMode.Xml:
return Serializer.Xml;
case SerializationMode.DataContractJson:
return Serializer.DataContractJson;
case SerializationMode.NewtonsoftJson:
return Serializer.NewtonsoftJson;
default:
throw new NotSupportedException();
}
}