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


C# SerializationContext.IsDefaultValueSerializationForced方法代码示例

本文整理汇总了C#中MonoDevelop.Core.Serialization.SerializationContext.IsDefaultValueSerializationForced方法的典型用法代码示例。如果您正苦于以下问题:C# SerializationContext.IsDefaultValueSerializationForced方法的具体用法?C# SerializationContext.IsDefaultValueSerializationForced怎么用?C# SerializationContext.IsDefaultValueSerializationForced使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MonoDevelop.Core.Serialization.SerializationContext的用法示例。


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

示例1: Serialize

		internal DataCollection Serialize (SerializationContext serCtx, object obj)
		{
			DataCollection itemCol = new DataCollection ();
			
			foreach (ItemProperty prop in Properties) {
				if (prop.ReadOnly || !prop.CanSerialize (serCtx, obj))
					continue;
				
				DataCollection col = itemCol;

				object val = prop.GetValue (obj);
				if (val == null) {
					if (serCtx.IncludeDeletedValues) {
						if (prop.IsNested)
							col = GetNestedCollection (col, prop.NameList, 0, true);
						col.Add (new DataDeletedNode (prop.SingleName));
					}
					continue;
				}
				
				var isDefault = val.Equals (prop.DefaultValue);
				if (isDefault && !serCtx.IsDefaultValueSerializationForced (prop))
					continue;

				if (prop.IsNested)
					col = GetNestedCollection (col, prop.NameList, 0, isDefault);
				
				if (prop.ExpandedCollection) {
					ICollectionHandler handler = prop.ExpandedCollectionHandler;
					object pos = handler.GetInitialPosition (val);
					while (handler.MoveNextItem (val, ref pos)) {
						object item = handler.GetCurrentItem (val, pos);
						if (item == null) continue;
						DataNode data = prop.Serialize (serCtx, obj, item);
						data.Name = prop.SingleName;
						col.Add (data);
					}
				}
				else {
					DataNode data = prop.Serialize (serCtx, obj, val);
					if (data == null) {
						if (serCtx.IncludeDeletedValues)
							col.Add (new DataDeletedNode (prop.SingleName));
						continue;
					}
					data.IsDefaultValue = isDefault;
					col.Add (data);
				}
			}
			
			if (obj is IExtendedDataItem) {
				// Serialize raw data which could not be deserialized
				DataItem uknData = (DataItem) ((IExtendedDataItem)obj).ExtendedProperties ["__raw_data"];
				if (uknData != null)
					itemCol.Merge (uknData.ItemData);
			}
			
			return itemCol;
		}
开发者ID:sushihangover,项目名称:monodevelop,代码行数:59,代码来源:ClassDataType.cs


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