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


C# Serialization.DataItem类代码示例

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


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


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