本文整理汇总了C#中Identifier.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# Identifier.GetType方法的具体用法?C# Identifier.GetType怎么用?C# Identifier.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Identifier
的用法示例。
在下文中一共展示了Identifier.GetType方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: getResourcePath
private string getResourcePath(string ctx, Identifier id)
{
if( id is ObjectId ) {
return ctx + "/objects/" + id;
} else if ( id is ObjectPath ) {
return ctx + "/namespace" + id;
} else if (id is ObjectKey) {
return ctx + "/namespace/" + (id as ObjectKey).key;
} else {
throw new Exception("Unknown identifier: " + id.GetType().Name);
}
}
示例2: AddXrefValues
/// <summary>
/// Adds a simple Identifier name value to <see cref="TreeData.XRefXml"/>
/// </summary>
/// <param name="xRefId"></param>
/// <param name="id"></param>
/// <param name="propertyName">
/// Optional, if null then defaults to <see cref="id"/> Type name.
/// </param>
public static bool AddXrefValues(Tuple<Type, string> xRefId, Identifier id, string propertyName = null)
{
const string SOURCE = "source";
if (string.IsNullOrWhiteSpace(xRefId?.Item2) || xRefId.Item1 == null)
return false;
if(id == null)
return false;
if (TreeData.XRefXml == null)
return false;
var xrefSrcNode = TreeData.XRefXml.SelectSingleNode($"//{SOURCE}");
if (xrefSrcNode == null)
return false;
var simpleNameValuePair = new Tuple<string, string>(propertyName ?? id.GetType().Name, id.Value);
//heirarchy of xpaths
var xRefGroupXPath = $"//{X_REF_GROUP}[@{DATA_TYPE}='{xRefId.Item1.FullName}']";
var xDataReferenceXPath = xRefGroupXPath + $"//{X_REF_ID}[text()='{xRefId.Item2}']/../..";
var xRefAddXPath = xDataReferenceXPath + $"/{ADD}[@{NAME}='{simpleNameValuePair.Item1}']";
var xRefAddChildXPath = xRefAddXPath + $"/{ADD}[@{NAME}='Value']";
//get the x-ref-group node
var xRefGroupNode = TreeData.XRefXml.SelectSingleNode(xRefGroupXPath) as XmlElement;
if (xRefGroupNode == null)
{
xRefGroupNode = TreeData.XRefXml.CreateElement(X_REF_GROUP);
var xRefGroupAttr = TreeData.XRefXml.CreateAttribute(DATA_TYPE);
xRefGroupAttr.Value = xRefId.Item1.FullName;
xRefGroupNode.Attributes.Append(xRefGroupAttr);
if (xrefSrcNode.HasChildNodes)
xrefSrcNode.InsertAfter(xRefGroupNode, xrefSrcNode.LastChild);
else
xrefSrcNode.AppendChild(xRefGroupNode);
}
//get the x-data-reference node
var xDataReferenceNode = TreeData.XRefXml.SelectSingleNode(xDataReferenceXPath);
if (xDataReferenceNode == null)
{
xDataReferenceNode = TreeData.XRefXml.CreateElement(X_DATA_REFERENCE);
var xRefNode = TreeData.XRefXml.CreateElement(X_REF);
var xRefIdNode = TreeData.XRefXml.CreateElement(X_REF_ID);
xRefIdNode.InnerText = xRefId.Item2;
xRefNode.AppendChild(xRefIdNode);
xDataReferenceNode.AppendChild(xRefNode);
xRefGroupNode.AppendChild(xDataReferenceNode);
}
//get the outer add node
var xrefAdd = TreeData.XRefXml.SelectSingleNode(xRefAddXPath) as XmlElement;
if (xrefAdd == null)
{
xrefAdd = TreeData.XRefXml.CreateElement(ADD);
if (!xDataReferenceNode.HasChildNodes)
xDataReferenceNode.AppendChild(xrefAdd);
else
xDataReferenceNode.InsertAfter(xrefAdd, xDataReferenceNode.LastChild);
}
var xrefNameAttr = xrefAdd.Attributes[NAME] ?? TreeData.XRefXml.CreateAttribute(NAME);
xrefNameAttr.Value = simpleNameValuePair.Item1;
if (xrefAdd.Attributes[NAME] == null)
xrefAdd.Attributes.Append(xrefNameAttr);
//get the inner add node
var childNode = TreeData.XRefXml.SelectSingleNode(xRefAddChildXPath) as XmlElement;
if (childNode == null)
{
childNode = TreeData.XRefXml.CreateElement(ADD);
if (!xrefAdd.HasChildNodes)
xrefAdd.AppendChild(childNode);
else
xrefAdd.InsertAfter(childNode, xrefAdd.LastChild);
}
var nameAttr = childNode.Attributes[NAME] ?? TreeData.XRefXml.CreateAttribute(NAME);
nameAttr.Value = "Value";
var valAttr = childNode.Attributes[VALUE] ?? TreeData.XRefXml.CreateAttribute(VALUE);
valAttr.Value = simpleNameValuePair.Item2;
if (childNode.Attributes[NAME] == null)
childNode.Attributes.Append(nameAttr);
if (childNode.Attributes[VALUE] == null)
childNode.Attributes.Append(valAttr);
return true;
}