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


C# SerializationMode类代码示例

本文整理汇总了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
				};
			}
		}
开发者ID:isse-augsburg,项目名称:ssharp,代码行数:37,代码来源:ArraySerializer.cs

示例2: XmlObjectSerializerReadContextComplex

 internal XmlObjectSerializerReadContextComplex(DataContractSerializer serializer, DataContract rootTypeDataContract, DataContractResolver dataContractResolver)
     : base(serializer, rootTypeDataContract, dataContractResolver)
 {
     _mode = SerializationMode.SharedContract;
     _preserveObjectReferences = serializer.PreserveObjectReferences;
     _serializationSurrogateProvider = serializer.SerializationSurrogateProvider;
 }
开发者ID:nadyalo,项目名称:corefx,代码行数:7,代码来源:XmlObjectSerializerReadContextComplex.cs

示例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;
 }
开发者ID:nlh774,项目名称:DotNetReferenceSource,代码行数:7,代码来源:XmlObjectSerializerReadContextComplex.cs

示例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));
        }
开发者ID:JokerMisfits,项目名称:linux-packaging-mono,代码行数:26,代码来源:SerializationExtensions.cs

示例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
					};
				}
			}
		}
开发者ID:isse-augsburg,项目名称:ssharp,代码行数:37,代码来源:ObjectSerializer.cs

示例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);
            }
        }
开发者ID:jesshaw,项目名称:ASP.NET-Mvc-3,代码行数:25,代码来源:MvcSerializer.cs

示例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();
        }
开发者ID:consumentor,项目名称:Server,代码行数:8,代码来源:MvcSerializer.cs

示例9: GetFormatter

		private static IStateFormatter GetFormatter(SerializationMode mode)
		{
			Func<IStateFormatter> formatterFactory;
			if (!_factories.TryGetValue(mode, out formatterFactory))
				throw Error.InvalidModelStateSerializationMode(mode);

			return formatterFactory();
		}
开发者ID:radischevo,项目名称:Radischevo.Wahha,代码行数:8,代码来源:ModelStateSerializer.cs

示例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");
		}
开发者ID:isse-augsburg,项目名称:ssharp,代码行数:24,代码来源:ListSerializer.cs

示例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;
 }
开发者ID:krytht,项目名称:DotNetReferenceSource,代码行数:10,代码来源:XmlObjectSerializerWriteContextComplex.cs

示例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;
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:11,代码来源:ProfilePropertySettings.cs

示例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);
            }
        }
开发者ID:jesshaw,项目名称:ASP.NET-Mvc-3,代码行数:13,代码来源:MvcSerializer.cs

示例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);
            }
        }
开发者ID:consumentor,项目名称:Server,代码行数:14,代码来源:MvcSerializer.cs

示例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();
			}
		}
开发者ID:deboe2015,项目名称:Ctrip.SOA,代码行数:14,代码来源:Serializer.cs


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