本文整理汇总了C#中IClassMap.GetDocElement方法的典型用法代码示例。如果您正苦于以下问题:C# IClassMap.GetDocElement方法的具体用法?C# IClassMap.GetDocElement怎么用?C# IClassMap.GetDocElement使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IClassMap
的用法示例。
在下文中一共展示了IClassMap.GetDocElement方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetNodeForObject
protected virtual XmlNode GetNodeForObject(XmlNode xmlRoot, object obj, IClassMap classMap)
{
string element = classMap.GetDocElement();
XmlNode xmlNode = FindNodeForObject(xmlRoot, obj, classMap);
//If the element doesn't exist, add it
if (xmlNode == null)
{
xmlNode = xmlRoot.OwnerDocument.CreateElement(element) ;
xmlRoot.AppendChild(xmlNode);
}
return xmlNode;
}
示例2: FindNodeForObject
protected virtual XmlNode FindNodeForObject(XmlNode xmlRoot, object obj, IClassMap classMap)
{
IObjectManager om = this.Context.ObjectManager;
string element = classMap.GetDocElement();
string xpath = "";
foreach (IPropertyMap idPropertyMap in classMap.GetIdentityPropertyMaps() )
{
if (xpath.Length > 0 )
xpath += " and "; // do not localize
if (idPropertyMap.DocElement.Length > 0)
xpath += idPropertyMap.GetDocElement() + " = \"" + om.GetPropertyValue(obj, idPropertyMap.Name).ToString() + "\""; // do not localize
else
xpath += "@" + idPropertyMap.GetDocAttribute() + " = \"" + om.GetPropertyValue(obj, idPropertyMap.Name).ToString() + "\""; // do not localize
}
xpath = element + "[" + xpath + "]";
return xmlRoot.SelectSingleNode(xpath);
}
示例3: FindNodesForObjects
protected virtual XmlNodeList FindNodesForObjects(XmlNode xmlRoot, IClassMap classMap)
{
IObjectManager om = this.Context.ObjectManager;
string element = classMap.GetDocElement();
return xmlRoot.SelectNodes(element);
}
示例4: DeserializeObject
protected virtual void DeserializeObject(Type type, IList listToFill, IClassMap classMap, string xml)
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(xml);
XmlNode xmlRoot = xmlDoc.SelectSingleNode(classMap.GetDocElement());
object obj = InstantiateObject(type, classMap, xmlRoot);
DeserializeObject(obj, classMap, xmlRoot);
listToFill.Add(obj);
}
示例5: CreateObjectXmlDocument
protected virtual XmlDocument CreateObjectXmlDocument(IClassMap classMap, string fileName)
{
ISourceMap sourceMap = classMap.GetDocSourceMap();
MemoryStream ms = new MemoryStream() ;
XmlTextWriter xmlWriter = new XmlTextWriter(
ms,
Encoding.GetEncoding( sourceMap.GetDocEncoding() ));
xmlWriter.Formatting = Formatting.Indented;
xmlWriter.WriteStartDocument(false);
xmlWriter.WriteDocType("Object",null,null,null);
xmlWriter.WriteComment("Serialized object"); // do not localize
xmlWriter.WriteStartElement(classMap.GetDocElement(), null);
xmlWriter.WriteEndElement();
xmlWriter.WriteEndDocument();
//Write the XML to file and close the writer
xmlWriter.Flush();
string xml = Encoding.GetEncoding( "utf-8" ).GetString(ms.ToArray(),0,(int)ms.Length);
xmlWriter.Close();
//Obs fulhack!! Jag får ett konstigt skräptecken i början!!
xml = xml.Substring(1);
XmlDocument xmlDocument = new XmlDocument() ;
xmlDocument.LoadXml(xml);
CachedXmlDocument cachedXmlDocument = new CachedXmlDocument(xmlDocument, fileName) ;
cachedXmlDocuments[fileName] = cachedXmlDocument;
return xmlDocument;
}
示例6: InstantiateObject
private object InstantiateObject(Type type, IClassMap classMap, XmlNode xmlObject)
{
IObjectManager om = this.Context.ObjectManager;
string element = classMap.GetDocElement();
string identity = "";
string separator = classMap.GetIdentitySeparator();
foreach (IPropertyMap idPropertyMap in classMap.GetIdentityPropertyMaps())
{
if (identity.Length > 0)
identity += separator;
if (idPropertyMap.DocElement.Length > 0)
{
XmlNode idNode = xmlObject.SelectSingleNode(idPropertyMap.GetDocElement());
if (idNode != null)
identity += idNode.InnerText;
else
throw new NPersistException(String.Format("Could not find id element {0} for property {1} of class {2} in element {3}", idPropertyMap.GetDocElement(), idPropertyMap.Name, type.ToString(), xmlObject.Name));
}
else
{
string attribName = idPropertyMap.GetDocAttribute();
if (xmlObject.Attributes[attribName] != null)
identity += xmlObject.Attributes[attribName].Value;
else
throw new NPersistException(String.Format("Could not find id attribute {0} for property {1} of class {2} in element {3}", attribName, idPropertyMap.Name, type.ToString(), xmlObject.Name));
}
}
return this.Context.GetObjectById(identity, type, true);
}
示例7: SavePerObject
protected virtual void SavePerObject(object obj, IClassMap classMap, bool creating)
{
string fileName = GetFileNamePerObject(obj, classMap);
LogMessage message = new LogMessage("Saving object to file");
LogMessage verbose = new LogMessage("File: {0},, Object Type: {1}" , fileName , obj.GetType());
this.Context.LogManager.Debug(this, message, verbose); // do not localize
XmlDocument xmlDoc;
if (creating)
{
if (File.Exists(fileName))
throw new NPersistException("The file '" + fileName + "' already exists!"); // do not localize
xmlDoc = CreateObjectXmlDocument(classMap, fileName);
}
else
{
if (!(File.Exists(fileName)))
throw new NPersistException("The file '" + fileName + "' could not be found!"); // do not localize
xmlDoc = GetXmlDocument(fileName);
}
XmlNode xmlObject = xmlDoc.SelectSingleNode(classMap.GetDocElement() );
SerializeObject(xmlObject, obj, classMap, creating);
}