本文整理汇总了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);
}
示例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);
}
}
}
}
示例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);
}
}
}
示例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;
}
示例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);
}
}
示例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;
}
示例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);
}
示例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);
}
示例9: WriteDataItem
void WriteDataItem (StreamWriter sw, DataItem item)
{
int id = 0;
foreach (DataNode val in item.ItemData)
WriteDataNode (sw, "", val, ref id);
}
示例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;
}
示例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;
}
示例12: SetConfigurationItemData
public void SetConfigurationItemData (SerializationContext serCtx, object obj, DataItem data)
{
ClassDataType dataType = (ClassDataType) GetConfigurationDataType (obj.GetType ());
dataType.Deserialize (serCtx, null, data, obj);
}
示例13: SetTypeInfo
public void SetTypeInfo (DataItem item, Type type)
{
item.ItemData.Add (new DataValue ("ctype", GetConfigurationDataType (type).Name));
}
示例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);
}
}
}
示例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);
}