當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。