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

C# Serialization.DataItem类代码示例

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

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



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

示例1: ReadSlnData

		public override void ReadSlnData (DataItem item)
		{
			// Remove the default configuration, since new ones will be loaded
			CompiledAssemblyProject project = (CompiledAssemblyProject) EntityItem;
			project.Configurations.Clear ();
			
			DataSerializer ser = new DataSerializer (MSBuildProjectService.DataContext);
			ser.SerializationContext.BaseFile = EntityItem.FileName;
			ser.SerializationContext.DirectorySeparatorChar = '\\';
			ser.Deserialize (project, item);
		}
开发者ID:Kalnor,项目名称:monodevelop,代码行数:11,代码来源:CompiledAssemblyProjectMSBuildHandler.cs


示例2: UpdateFromItem

		internal void UpdateFromItem (DataItem item, HashSet<DataItem> removedItems)
		{
			var counter = new Dictionary<string, int> ();
			foreach (var d in item.ItemData) {
				DataNode current = null;
				DataCollection col;
				if (!counter.ContainsKey (d.Name))
					counter [d.Name] = 0;
				var index = ItemData.FindData (d.Name, out col, false, counter[d.Name]);
				counter [d.Name]++;
				if (index != -1) {
					current = col [index];
				}
				if (current != null) {
					if (d.IsDefaultValue || d is DataDeletedNode) {
						if (current is DataItem)
							removedItems.Add ((DataItem)current);
						ItemData.Remove (current);
					} else if (current.GetType () != d.GetType () || current is DataValue) {
						var i = ItemData.IndexOf (current);
						ItemData [i] = d;
						if (current is DataItem)
							removedItems.Add ((DataItem)current);
					} else if (current is DataItem) {
						((DataItem)current).UpdateFromItem ((DataItem)d, removedItems);
					}
				} else if (!d.IsDefaultValue && !(d is DataDeletedNode)) {
					var dataItem = d as DataItem;
					if (dataItem != null) {
						var newDataItem = new DataItem () {
							Name = d.Name,
							UniqueNames = dataItem.UniqueNames
						};
						newDataItem.UpdateFromItem (dataItem, removedItems);
						ItemData.Add (newDataItem);
					} else {
						ItemData.Add (d);
					}
				}
			}
		}
开发者ID:kdubau,项目名称:monodevelop,代码行数:41,代码来源:DataItem.cs


示例3: UpdateFromItem

		internal void UpdateFromItem (DataItem item, HashSet<DataItem> removedItems)
		{
			foreach (var d in item.ItemData) {
				var current = ItemData[d.Name];
				if (current != null) {
					if (d.IsDefaultValue || d is DataDeletedNode) {
						if (current is DataItem)
							removedItems.Add ((DataItem)current);
						ItemData.Remove (current);
					}
					else if (current.GetType () != d.GetType () || current is DataValue) {
						var i = ItemData.IndexOf (current);
						ItemData [i] = d;
						if (current is DataItem)
							removedItems.Add ((DataItem)current);
					} else if (current is DataItem) {
						((DataItem)current).UpdateFromItem ((DataItem)d, removedItems);
					}
				} else if (!d.IsDefaultValue && !(d is DataDeletedNode)) {
					ItemData.Add (d);
				}
			}
		}
开发者ID:pabloescribanoloza,项目名称:monodevelop,代码行数:23,代码来源:DataItem.cs


示例4: OnSerialize

		internal protected override DataNode OnSerialize (SerializationContext serCtx, object mdata, object collection)
		{
			MapData mapData = (mdata != null) ? (MapData) mdata : GetDefaultData ();
			DataItem colItem = new DataItem ();
			colItem.Name = Name;
			colItem.UniqueNames = false;
			IDictionary dict = (IDictionary) collection;
			
			foreach (DictionaryEntry e in dict) {
				DataItem item = new DataItem ();
				item.Name = mapData.ItemName;
				item.UniqueNames = true;
				
				DataNode key = mapData.KeyType.Serialize (serCtx, null, e.Key);
				key.Name = mapData.KeyName;
				DataNode value = mapData.ValueType.Serialize (serCtx, null, e.Value);
				value.Name = mapData.ValueName;
				item.ItemData.Add (key);
				item.ItemData.Add (value);
				
				colItem.ItemData.Add (item);
			}
			return colItem;
		}
开发者ID:FreeBSD-DotNet,项目名称:monodevelop,代码行数:24,代码来源:DictionaryDataType.cs


示例5: WriteAttributes

		protected virtual void WriteAttributes (XmlElement elem, DataItem item)
		{
			if (StoreAllInElements)
				return;
			foreach (DataNode data in item.ItemData) {
				DataValue val = data as DataValue;
				if (val != null && (item.UniqueNames || val.StoreAsAttribute))
					WriteAttribute (elem, val.Name, val.Value);
			}
		}
开发者ID:transformersprimeabcxyz,项目名称:monodevelop-1,代码行数:10,代码来源:XmlDataSerializer.cs


示例6: ReadDataNode

		bool ReadDataNode (DataItem item, List<string> lines, int lastLine, string prefix, ref int lineNum)
		{
			string s = lines [lineNum].Trim (' ','\t');
			
			if (s.Length == 0) {
				lineNum++;
				return true;
			}
			
			// Check if the line belongs to the current item
			if (prefix.Length > 0) {
				if (!s.StartsWith (prefix + "."))
					return false;
				s = s.Substring (prefix.Length + 1);
			} else {
				if (s.StartsWith ("$"))
					return false;
			}
			
			int i = s.IndexOf ('=');
			if (i == -1) {
				lineNum++;
				return true;
			}

			string name = s.Substring (0, i).Trim (' ','\t');
			if (name.Length == 0) {
				lineNum++;
				return true;
			}
			
			string value = s.Substring (i+1).Trim (' ','\t');
			if (value.StartsWith ("$")) {
				// New item
				DataItem child = new DataItem ();
				child.Name = name;
				lineNum++;
				while (lineNum <= lastLine) {
					if (!ReadDataNode (child, lines, lastLine, value, ref lineNum))
						break;
				}
				item.ItemData.Add (child);
			}
			else {
				value = DecodeString (value);
				DataValue val = new DataValue (name, value);
				item.ItemData.Add (val);
				lineNum++;
			}
			return true;
		}
开发者ID:riverans,项目名称:monodevelop,代码行数:51,代码来源:SlnFileFormat.cs


示例7: WriteDataItem

		static void WriteDataItem (SlnSection pset, DataItem item)
		{
			HashSet<DataItem> removedItems = new HashSet<DataItem> ();
			Dictionary<DataNode,int> ids = new Dictionary<DataNode, int> ();

			// First of all read the existing data item, since we want to keep data that has not been modified
			// The ids collection is filled with a map of items and their ids
			var currentItem = ReadDataItem (pset, ids);

			// UpdateFromItem will add new data to the item, it will remove the data that has been removed, and
			// will ignore unknown data that has not been set or removed
			currentItem.UpdateFromItem (item, removedItems);

			// List of IDs that are not used anymore and can be reused when writing the item
			var unusedIds = new Queue<int> (removedItems.Select (it => ids[it]).OrderBy (i => i));

			// Calculate the next free id, to be used when adding new items
			var usedIds = ids.Where (p => !removedItems.Contains (p.Key)).Select (p => p.Value).ToArray ();
			int nextId = usedIds.Length > 0 ? usedIds.Max () + 1 : 0;

			var newSet = new List<KeyValuePair<string, string>> ();

			foreach (DataNode val in currentItem.ItemData)
				WriteDataNode (newSet, "", val, ids, unusedIds, ref nextId);
			
			pset.SetContent (newSet);
		}
开发者ID:sushihangover,项目名称:monodevelop,代码行数:27,代码来源:IMSBuildPropertySet.cs


示例8: GetNestedCollection

		DataCollection GetNestedCollection (DataCollection col, string[] nameList, int pos, bool isDefault)
		{
			if (pos == nameList.Length - 1) return col;

			DataItem item = col [nameList[pos]] as DataItem;
			if (item == null) {
				item = new DataItem ();
				item.Name = nameList[pos];
				col.Add (item);
				item.IsDefaultValue = isDefault;
			}
			if (item.IsDefaultValue && !isDefault)
				item.IsDefaultValue = false;
			return GetNestedCollection (item.ItemData, nameList, pos + 1, isDefault);
		}
开发者ID:sushihangover,项目名称:monodevelop,代码行数:15,代码来源:ClassDataType.cs


示例9: WriteDataItem

		void WriteDataItem (StreamWriter sw, DataItem item)
		{
			int id = 0;
			foreach (DataNode val in item.ItemData)
				WriteDataNode (sw, "", val, ref id);
		}
开发者ID:riverans,项目名称:monodevelop,代码行数:6,代码来源:SlnFileFormat.cs


示例10: ReadDataItem

		static DataItem ReadDataItem (SlnSection pset, Dictionary<DataNode,int> ids)
		{
			DataItem it = new DataItem ();

			var lines = pset.GetContent ().ToArray ();

			int lineNum = 0;
			int lastLine = lines.Length - 1;
			while (lineNum <= lastLine) {
				if (!ReadDataNode (it, lines, lastLine, "", ids, ref lineNum))
					lineNum++;
			}
			return it;
		}
开发者ID:sushihangover,项目名称:monodevelop,代码行数:14,代码来源:IMSBuildPropertySet.cs


示例11: Read

		public DataNode Read (XmlReader reader)
		{
			DataItem item = new DataItem (); 
			item.UniqueNames = false;
			reader.MoveToContent ();
			string name = reader.LocalName;
			item.Name = name;
			
			while (reader.MoveToNextAttribute ()) {
				if (reader.LocalName == "xmlns")
					continue;
				DataNode data = ReadAttribute (reader.LocalName, reader.Value);
				if (data != null) {
					DataValue val = data as DataValue;
					if (val != null)
						val.StoreAsAttribute = true;
					item.ItemData.Add (data);
				}
			}
			
			reader.MoveToElement ();
			if (reader.IsEmptyElement) {
				reader.Skip ();
				return item;
			}
			
			reader.ReadStartElement ();
			reader.MoveToContent ();
			
			string text = "";
			while (reader.NodeType != XmlNodeType.EndElement) {
				if (reader.NodeType == XmlNodeType.Element) {
					DataNode data = ReadChild (reader, item);
					if (data != null) item.ItemData.Add (data);
				} else if (reader.NodeType == XmlNodeType.Text) {
					text += reader.Value;
					reader.Skip ();
				} else {
					reader.Skip ();
				}
			}
			
			reader.ReadEndElement ();
			
			if (!item.HasItemData && text != "")
				return new DataValue (name, text); 

			return item;
		}
开发者ID:transformersprimeabcxyz,项目名称:monodevelop-1,代码行数:49,代码来源:XmlDataSerializer.cs


示例12: SetConfigurationItemData

		public void SetConfigurationItemData (SerializationContext serCtx, object obj, DataItem data)
		{
			ClassDataType dataType = (ClassDataType) GetConfigurationDataType (obj.GetType ());
			dataType.Deserialize (serCtx, null, data, obj);
		}
开发者ID:FreeBSD-DotNet,项目名称:monodevelop,代码行数:5,代码来源:DataContext.cs


示例13: SetTypeInfo

		public void SetTypeInfo (DataItem item, Type type)
		{
			item.ItemData.Add (new DataValue ("ctype", GetConfigurationDataType (type).Name));
		}
开发者ID:FreeBSD-DotNet,项目名称:monodevelop,代码行数:4,代码来源:DataContext.cs


示例14: Deserialize

		void Deserialize (SerializationContext serCtx, object obj, DataCollection itemData, DataItem ukwnDataRoot, string baseName)
		{
			Hashtable expandedCollections = null;
			
			foreach (DataNode value in itemData) {
				ItemProperty prop = (ItemProperty) properties [baseName + value.Name];
				if (prop == null) {
					if (value is DataItem) {
						DataItem root = new DataItem ();
						root.Name = value.Name;
						root.UniqueNames = ((DataItem)value).UniqueNames;
						if (ukwnDataRoot != null)
							ukwnDataRoot.ItemData.Add (root);
						Deserialize (serCtx, obj, ((DataItem)value).ItemData, root, baseName + value.Name + "/");

						// If no unknown data has been added, there is no need to keep this
						// in the unknown items list.
						if (ukwnDataRoot != null && !root.HasItemData)
							ukwnDataRoot.ItemData.Remove (root);
					}
					else if (obj is IExtendedDataItem && (value.Name != "ctype" || baseName.Length > 0)) {
						// store unreadable raw data to a special property so it can be 
						// serialized back an the original format is kept
						// The ctype attribute don't need to be stored for the root object, since
						// it is generated by the serializer
						ukwnDataRoot.ItemData.Add (value);
					}
					continue;
				}
				if (prop.WriteOnly || !prop.CanDeserialize (serCtx, obj))
					continue;
				
				try {
					if (prop.ExpandedCollection) {
						ICollectionHandler handler = prop.ExpandedCollectionHandler;
						if (expandedCollections == null) expandedCollections = new Hashtable ();
						
						object pos, col;
						if (!expandedCollections.ContainsKey (prop)) {
							col = handler.CreateCollection (out pos, -1);
						} else {
							pos = expandedCollections [prop];
							col = prop.GetValue (obj);
						}
						handler.AddItem (ref col, ref pos, prop.Deserialize (serCtx, obj, value));
						expandedCollections [prop] = pos;
						prop.SetValue (obj, col);
					}
					else {
						if (prop.HasSetter && prop.DataType.CanCreateInstance)
							prop.SetValue (obj, prop.Deserialize (serCtx, obj, value));
						else if (prop.DataType.CanReuseInstance) {
							object pval = prop.GetValue (obj);
							if (pval == null) {
								if (prop.HasSetter)
									throw new InvalidOperationException ("The property '" + prop.Name + "' is null and a new instance of '" + prop.PropertyType + "' can't be created.");
								else
									throw new InvalidOperationException ("The property '" + prop.Name + "' is null and it does not have a setter.");
							}
							prop.Deserialize (serCtx, obj, value, pval);
						} else {
							throw new InvalidOperationException ("The property does not have a setter.");
						}
					}
				}
				catch (Exception ex) {
					throw new InvalidOperationException ("Could not set property '" + prop.Name + "' in type '" + Name + "'", ex);
				}
			}
		}
开发者ID:transformersprimeabcxyz,项目名称:monodevelop-1,代码行数:70,代码来源:ClassDataType.cs


示例15: GetNestedCollection

		DataCollection GetNestedCollection (DataCollection col, string[] nameList, int pos)
		{
			if (pos == nameList.Length - 1) return col;

			DataItem item = col [nameList[pos]] as DataItem;
			if (item == null) {
				item = new DataItem ();
				item.Name = nameList[pos];
				col.Add (item);
			}
			return GetNestedCollection (item.ItemData, nameList, pos + 1);
		}
开发者ID:transformersprimeabcxyz,项目名称:monodevelop-1,代码行数:12,代码来源:ClassDataType.cs


示例16: OnSerialize

		internal protected override DataNode OnSerialize (SerializationContext serCtx, object mapData, object obj)
		{
			string ctype = null;
			
			if (obj.GetType () != ValueType) {
				if (obj is IExtendedDataItem) {
					// This is set by fallback types, to make sure the original type name is serialized back
					ctype = (string) ((IExtendedDataItem)obj).ExtendedProperties ["__raw_ctype"];
				}
				if (ctype == null) {
					DataType subtype = Context.GetConfigurationDataType (obj.GetType ());
					DataNode n = subtype.Serialize (serCtx, mapData, obj);
					DataItem it = n as DataItem;
					if (it == null) {
						it = new DataItem ();
						n.Name = "Value";
						it.ItemData.Add (n);
					}
					it.ItemData.Add (new DataValue ("ctype", subtype.Name));
					it.Name = Name;
					return it;
				}
			} 
			
			DataItem item = new DataItem ();
			item.Name = Name;
			
			ICustomDataItem citem = Context.AttributeProvider.GetCustomDataItem (obj);
			if (citem != null) {
				ClassTypeHandler handler = new ClassTypeHandler (serCtx, this);
				item.ItemData = citem.Serialize (handler);
			}
			else
				item.ItemData = Serialize (serCtx, obj);
				
			if (ctype != null)
				item.ItemData.Add (new DataValue ("ctype", ctype));

			return item;
		}
开发者ID:transformersprimeabcxyz,项目名称:monodevelop-1,代码行数:40,代码来源:ClassDataType.cs


示例17: ReadChild

		protected virtual DataNode ReadChild (XmlElement elem, DataItem parent)
		{
			return GetChildReader (parent).Read (elem);
		}
开发者ID:transformersprimeabcxyz,项目名称:monodevelop-1,代码行数:4,代码来源:XmlDataSerializer.cs


示例18: WriteChildren

		protected virtual void WriteChildren (XmlElement elem, DataItem item)
		{
			if (item.UniqueNames) {
				foreach (DataNode data in item.ItemData) {
					if (!(data is DataValue) || !StoreAsAttribute ((DataValue)data))
						WriteChild (elem, data);
				}
			} else {
				foreach (DataNode data in item.ItemData) {
					DataValue dval = data as DataValue;
					if (dval == null || !dval.StoreAsAttribute || !StoreAsAttribute (dval))
						WriteChild (elem, data);
				}
			}
		}
开发者ID:transformersprimeabcxyz,项目名称:monodevelop-1,代码行数:15,代码来源:XmlDataSerializer.cs


示例19: GetChildReader

		protected virtual XmlConfigurationReader GetChildReader (DataItem parent)
		{
			return this;
		}
开发者ID:transformersprimeabcxyz,项目名称:monodevelop-1,代码行数:4,代码来源:XmlDataSerializer.cs


示例20: ReadDataNode

		static bool ReadDataNode (DataItem item, KeyValuePair<string,string>[] lines, int lastLine, string prefix, Dictionary<DataNode,int> ids, ref int lineNum)
		{
			var s = lines [lineNum];

			string name = s.Key;
			if (name.Length == 0) {
				lineNum++;
				return true;
			}

			// Check if the line belongs to the current item
			if (prefix.Length > 0) {
				if (!s.Key.StartsWith (prefix + ".", StringComparison.Ordinal))
					return false;
				name = s.Key.Substring (prefix.Length + 1);
			} else {
				if (s.Key.StartsWith ("$", StringComparison.Ordinal))
					return false;
			}

			string value = s.Value;
			if (value.StartsWith ("$", StringComparison.Ordinal)) {
				// New item
				DataItem child = new DataItem ();
				child.Name = name;
				int id;
				if (ids != null && int.TryParse (value.Substring (1), out id))
					ids [child] = id;
				lineNum++;
				while (lineNum <= lastLine) {
					if (!ReadDataNode (child, lines, lastLine, value, ids, ref lineNum))
						break;
				}
				item.ItemData.Add (child);
			} else {
				value = DecodeString (value);
				DataValue val = new DataValue (name, value);
				item.ItemData.Add (val);
				lineNum++;
			}
			return true;
		}
开发者ID:sushihangover,项目名称:monodevelop,代码行数:42,代码来源:IMSBuildPropertySet.cs



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C# Serialization.DataNode类代码示例发布时间:2022-05-26
下一篇:
C# ProgressMonitoring.AggregatedOperationMonitor类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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