if(valueElement!=null&&overwrite)//value element exists and overwrite is true
{
valueElement.Value=value;//overwrite existing value
}
elseif(!overwrite&&propertyElement.Elements(XmlDataHandler.VALUE_ELEMENT_NAME).Any(v=>v.Value.Equals(value)))//no overwrite and same value exists already
sameValueElement.Remove();//remove the already existing value from its current position
propertyElement.AddFirst(sameValueElement);//add it as the first element again
}
else//no value element exists or overwrite is false
propertyElement.AddFirst(newXElement(XmlDataHandler.VALUE_ELEMENT_NAME){Value=value});//add a new value element
valueElement.Value=value;//overwrite existing value
}
else//property element doesn't exist
elseif(!overwrite&&propertyElement.Elements(XmlDataHandler.VALUE_ELEMENT_NAME).Any(v=>v.Value.Equals(value)))//no overwrite and same value exists already
{
propertyElement=newXElement(propertyName,newXElement(XmlDataHandler.VALUE_ELEMENT_NAME){Value=value});//create the new property element with the value element
propertyElement.SetAttributeValue(XmlDataHandler.VALUE_TYPE_ATTRIBUTE_NAME,typeof(TProperty).FullName);//add the property type attribute
typeElement.Add(propertyElement);//create new property element with the value element
sameValueElement.Remove();//remove the already existing value from its current position
propertyElement.AddFirst(sameValueElement);//add it as the first element again
}
else//no value element exists or overwrite is false
propertyElement.AddFirst(newXElement(XmlDataHandler.VALUE_ELEMENT_NAME){Value=value});//add a new value element
}
else//type element doesn't exist
else//property element doesn't exist
{
XElementpropertyElement=newXElement(propertyName,newXElement(XmlDataHandler.VALUE_ELEMENT_NAME){Value=value});//create the new property element with the value element
propertyElement=newXElement(propertyName,newXElement(XmlDataHandler.VALUE_ELEMENT_NAME){Value=value});//create the new property element with the value element
propertyElement.SetAttributeValue(XmlDataHandler.VALUE_TYPE_ATTRIBUTE_NAME,typeof(TProperty).FullName);//add the property type attribute
_rootElement.Add(newXElement(typeName,propertyElement));//create a new type element with the new property element
rootElement.Add(propertyElement);//create new property element with the value element
}
//TODO: check if whole file is overwritten (probably) -> performance issues for large files?
@ -107,19 +101,27 @@ namespace GBase.DataHandling
/// </summary>
/// <typeparam name="T">The <see cref="Type"/> of the property</typeparam>
/// <typeparam name="TProperty">The <see cref="Type"/> of the property</typeparam>
/// <param name="file"></param>
/// <param name="propertyName">The name of the property</param>
/// <param name="value">The value to set</param>
/// <param name="cancellationToken"></param>
/// <returns>A <see cref="Task"/> to await</returns>