• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# SerializationMode类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



SerializationMode类属于命名空间,在下文中一共展示了SerializationMode类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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


示例16: 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)
		{
			// Gets the fields declared by the obj that should be serialized. In full serialization mode, this only
			// includes the fields declared by <paramref name="obj" /> itself, not any of the fields declared by its base types. In
			// optimized mode, this includes all fields. The reason is that in optimized mode, fault effects are actually treated as
			// components, whereas in full mode, they only serve to serialize the delta to their base class.

			var type = ((Component)obj).FaultEffectType;
			return mode == SerializationMode.Optimized
				? base.GetFields(obj, mode)
				: base.GetFields(obj, mode, type, type.BaseType);
		}
开发者ID:isse-augsburg,项目名称:ssharp,代码行数:29,代码来源:FaultEffectSerializer.cs


示例17: Serialize

        internal void Serialize(ClassMapping mapping, object instance, bool summary, SerializationMode mode = SerializationMode.AllMembers)
        {
            if (mapping == null) throw Error.ArgumentNull("mapping");

            _current.WriteStartComplexContent();

            // Emit members that need xml /attributes/ first (to facilitate stream writer API)
            foreach (var prop in mapping.PropertyMappings.Where(pm => pm.SerializationHint == XmlSerializationHint.Attribute))
                if(!summary || prop.InSummary) write(mapping, instance, summary, prop, mode);

            // Then emit the rest
            foreach (var prop in mapping.PropertyMappings.Where(pm => pm.SerializationHint != XmlSerializationHint.Attribute))
                if (!summary || prop.InSummary) write(mapping, instance, summary, prop, mode);

            _current.WriteEndComplexContent();
        }
开发者ID:ranjancse26,项目名称:fhir-net-api,代码行数:16,代码来源:ComplexTypeWriter.cs


示例18: GetReferencedObjects

		/// <summary>
		///   Gets all objects referenced by <paramref name="obj" /> potentially marked with the <paramref name="hidden" /> attribute.
		/// </summary>
		/// <param name="obj">The object the referenced objects should be returned for.</param>
		/// <param name="mode">The serialization mode that should be used to serialize the objects.</param>
		/// <param name="hidden">The <see cref="HiddenAttribute" /> instance, if any, the field storing <paramref name="obj" /> was marked with.</param>
		protected internal override IEnumerable<object> GetReferencedObjects(object obj, SerializationMode mode, HiddenAttribute hidden)
		{
			// Optimization: Skip enumerables with hidden elements
			if (mode == SerializationMode.Optimized && hidden?.HideElements == true)
			{
				// We have to make sure the objects referenced by the list are discovered nevertheless
				var enumerable = obj as IEnumerable;
				if (enumerable == null)
					yield break;

				foreach (var element in enumerable.Cast<object>().Where(item => item.GetType().IsReferenceType()))
					yield return element;
			}
			else
				yield return obj;
		}
开发者ID:isse-augsburg,项目名称:ssharp,代码行数:22,代码来源:ListSerializer.cs


示例19: Serialize

		public static string Serialize(this HtmlHelper helper, 
			string name, object data, SerializationMode mode)
		{
			Precondition.Require(helper, () => Error.ArgumentNull("helper"));
			Precondition.Defined(name, () => Error.ArgumentNull("name"));

			ModelStateSerializer serializer = new ModelStateSerializer();
			string elementName = helper.Context.ViewData.Template.GetHtmlElementName(name);
			string value = serializer.Serialize(data ?? helper.Context.ViewData.Model, mode);

			HtmlElementBuilder builder = new HtmlElementBuilder("input");
			builder.Attributes["type"] = "hidden";
			builder.Attributes["name"] = elementName;
			builder.Attributes["value"] = value;

			return builder.ToString();
		}
开发者ID:radischevo,项目名称:Radischevo.Wahha,代码行数:17,代码来源:SerializationExtensions.cs


示例20: GetReferencedObjects

		/// <summary>
		///   Gets all objects referenced by <paramref name="obj" />, excluding <paramref name="obj" /> itself.
		/// </summary>
		/// <param name="obj">The object the referenced objects should be returned for.</param>
		/// <param name="mode">The serialization mode that should be used to serialize the objects.</param>
		protected internal override IEnumerable<object> GetReferencedObjects(object obj, SerializationMode mode)
		{
			if (mode == SerializationMode.Optimized)
				yield break;

			var d = (Delegate)obj;
			var method = d.Method;

			yield return obj.GetType();
			yield return method.ReturnType;
			yield return method.DeclaringType;

			foreach (var parameter in method.GetParameters())
				yield return parameter.GetType();

			yield return new DelegateMetadata(d);
		}
开发者ID:isse-augsburg,项目名称:ssharp,代码行数:22,代码来源:DelegateSerializer.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# SerializationReader类代码示例发布时间:2022-05-24
下一篇:
C# SerializationInfo类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap