本文整理汇总了C#中System.Xml.Linq.XElement.TryGetAttributeValue方法的典型用法代码示例。如果您正苦于以下问题:C# XElement.TryGetAttributeValue方法的具体用法?C# XElement.TryGetAttributeValue怎么用?C# XElement.TryGetAttributeValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Xml.Linq.XElement
的用法示例。
在下文中一共展示了XElement.TryGetAttributeValue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AreaDefinition
/// <summary>
/// Initializes a new instance of the <see cref="AreaDefinition"/> class.
/// </summary>
/// <param name="element">The element.</param>
public AreaDefinition(XElement element)
: this()
{
this.AreaString.String = element.TryGetAttributeValue("Text", null);
this.MapToPropertyExpression = element.TryGetAttributeValue("MapTo", null);
this.Separator = element.TryGetAttributeValue("Separator", ":");
}
示例2: AreaDefinition
/// <summary>
/// Initializes a new instance of the <see cref="AreaDefinition"/> class.
/// </summary>
/// <param name="element">The element.</param>
public AreaDefinition(XElement element)
: this()
{
this.AreaString.String = element.TryGetAttributeValue("Text", null);
this.AreaString.IsContained = element.TryGetAttributeValue("Text-IsContained", true);
this.MapToPropertyName = element.TryGetAttributeValue("MapTo", null);
this.Separator = element.TryGetAttributeValue("Separator", ":");
}
示例3: CreatorInfo
public CreatorInfo(XElement node)
{
string value;
if (node.TryGetAttributeValue("id", out value))
_id = value;
XElement n = node.Element("name");
if (n != null && n.TryGetValue(out value))
_name = value;
n = node.Element("email");
if (n != null && n.TryGetValue(out value))
{
_email = value;
if (n.TryGetAttributeValue("display", out value))
_displayEmail = bool.Parse(value);
}
n = node.Element("bio");
if (n != null && n.TryGetValue(out value))
_bio = value;
n = node.Element("url");
if (n != null && n.TryGetValue(out value))
_url = value;
}
示例4: SectionDefinition
/// <summary>
/// Initializes a new instance of the <see cref="SectionDefinition"/> class.
/// </summary>
/// <param name="element">The XML-element to read the data from.</param>
public SectionDefinition(XElement element)
: this()
{
this.SectionString.String = element.TryGetAttributeValue("Text", null);
// Parse the aspects...
foreach (XElement aspectE in element.Elements("Aspect"))
{
SectionParserDefinition spDefinition = new SectionParserDefinition(aspectE);
if (string.IsNullOrWhiteSpace(spDefinition.Type))
{
// TODO: Log warning
continue;
}
this.Parsers.Add(spDefinition);
}
// Parse the areas...
foreach (XElement areaE in element.Elements("Area"))
{
AreaDefinition areaDefinition = new AreaDefinition(areaE);
if (!areaDefinition.IsValidDefinition())
{
// TODO: Log warning
continue;
}
this.Areas.Add(areaDefinition);
}
}
示例5:
object IAddressProvider.ParseXElement(XElement element)
{
string address = element.Value;
string receiptType = element.TryGetAttributeValue("Type", MailingEntryObject.ReceiptType.To.ToString());
return MailingEntryObject.FromAddress(address, receiptType);
}
示例6: SectionDefinition
/// <summary>
/// Initializes a new instance of the <see cref="SectionDefinition"/> class.
/// </summary>
/// <param name="element">The XML-element to read the data from.</param>
public SectionDefinition(XElement element)
: this()
{
this.SectionString.String = element.TryGetAttributeValue("Text", null);
this.SectionString.IsContained = element.TryGetAttributeValue("Text-IsContained", true);
// Parse the areas...
foreach (XElement areaE in element.Elements("Area"))
{
AreaDefinition areaDefinition = new AreaDefinition(areaE);
if (!areaDefinition.IsValidDefinition())
{
// TODO: Log warning
continue;
}
this.Areas.Add(areaDefinition);
}
}
示例7: PushEntryObject
object IAddressProvider.Convert(XElement element)
{
string consumer = element.TryGetAttributeValue("Consumer", null);
string recApiKey = element.Value;
PushEntryObject geo = new PushEntryObject();
geo.Consumer = consumer;
geo.RecipientApiKey = recApiKey;
return geo;
}
示例8: SectionParserDefinition
/// <summary>
/// Initializes a new instance of the <see cref="SectionParserDefinition"/> class.
/// </summary>
/// <param name="element">The element.</param>
public SectionParserDefinition(XElement element)
: this()
{
this.Type = element.TryGetAttributeValue("Type", null);
foreach (var item in element.Attributes())
{
if (item.Name == "Type")
{
continue;
}
Options[item.Name.LocalName] = item.Value;
}
}
示例9: MessageInfo
public MessageInfo(XElement node)
{
string value;
if (node.TryGetAttributeValue("id", out value))
_id = int.Parse(value);
XElement n = node.Element("title");
if (n != null && n.TryGetValue(out value))
_title = value;
n = node.Element("text");
if (n != null && n.TryGetValue(out value))
_text = value;
}
示例10: Deserialize
internal static KernelTypeInfo Deserialize(XElement xe, string directory = null)
{
string name = xe.GetAttributeValue(csNAME);
bool? isDummy = xe.TryGetAttributeBoolValue(csISDUMMY);
string behaviourStr = xe.TryGetAttributeValue(csDUMMYBEHAVIOUR);
string typeName = xe.Element(csTYPE).Value;
string assemblyFullName = xe.Element(csASSEMBLY).Value;
string assemblyName = xe.Element(csASSEMBLYNAME).Value;
string assemblyPath = xe.TryGetElementValue(csASSEMBLYPATH);
long checksum = XmlConvert.ToInt64(xe.Element(csCHECKSUM).Value);
eCudafyDummyBehaviour behaviour = string.IsNullOrEmpty(behaviourStr) ? eCudafyDummyBehaviour.Default : (eCudafyDummyBehaviour)Enum.Parse(typeof(eCudafyDummyBehaviour), behaviourStr);
Type type = null;
KernelTypeInfo kti = new KernelTypeInfo(null);
if (!string.IsNullOrEmpty(typeName) && !string.IsNullOrEmpty(assemblyFullName))
{
Assembly assembly = null;
try
{
assembly = Assembly.Load(assemblyFullName);
}
catch (FileNotFoundException)
{
directory = directory != null ? directory : string.Empty;
assemblyName = directory + Path.DirectorySeparatorChar + assemblyName;
if (File.Exists(assemblyName + ".dll"))
{
assembly = Assembly.LoadFrom(assemblyName + ".dll");
}
else if (File.Exists(assemblyName + ".exe"))
{
assembly = Assembly.LoadFrom(assemblyName + ".exe");
}
else if (!string.IsNullOrEmpty(assemblyPath))
{
assembly = Assembly.LoadFrom(assemblyPath);
}
else
throw;
}
if (assembly == null)
throw new CudafyException(CudafyException.csCOULD_NOT_LOAD_ASSEMBLY_X, assemblyFullName);
type = assembly.GetType(typeName);
kti = new KernelTypeInfo(type, isDummy == true ? true : false, behaviour);
}
kti.DeserializedChecksum = checksum;
return kti;
}
示例11: CategoryInfo
public CategoryInfo(CatalogInfo catalog, XElement node)
{
_catalog = catalog;
string value;
if (node.TryGetAttributeValue("id", out value))
_id = int.Parse(value);
XElement n = node.Element("name");
if (n != null && n.TryGetValue(out value))
_name = value;
n = node.Element("description");
if (n != null && n.TryGetValue(out value))
_description = value;
}
示例12: CatalogInfo
public CatalogInfo(XElement node)
{
string value;
if (node.TryGetAttributeValue("id", out value))
_id = int.Parse(value);
XElement n = node.Element("name");
if (n != null && n.TryGetValue(out value))
_name = value;
n = node.Element("description");
if (n != null && n.TryGetValue(out value))
_description = value;
n = node.Element("type");
if (n != null && n.TryGetValue(out value))
_type = (CatalogType)System.Enum.Parse(typeof(CatalogType), value);
}
示例13: ItemInfo
public ItemInfo(CatalogInfo catalog, XElement node)
{
_catalog = catalog;
string value;
if (node.TryGetAttributeValue("id", out value))
_id = int.Parse(value);
if (node.TryGetAttributeValue("categoryId", out value))
_categoryId = int.Parse(value);
if (node.TryGetAttributeValue("creatorId", out value))
_creatorId = value;
XElement n = node.Element("name");
if (n != null && n.TryGetValue(out value))
_name = value;
n = node.Element("description");
if (n != null && n.TryGetValue(out value))
_description = value;
n = node.Element("version");
if (n != null && n.TryGetValue(out value))
_version = value;
n = node.Element("downloadUrl");
if (n != null && n.TryGetValue(out value))
_downloadUrl = value;
n = node.Element("fileName");
if (n != null && n.TryGetValue(out value))
_fileName = value;
n = node.Element("screenshotUrl");
if (n != null && n.TryGetValue(out value))
_screenshotUrl = value;
n = node.Element("iconUrl");
if (n != null && n.TryGetValue(out value))
_iconUrl = value;
n = node.Element("worksWithMajorVersion");
if (n != null && n.TryGetValue(out value))
_worksWithMajorVersion = int.Parse(value);
n = node.Element("worksWithMinorVersion");
if (n != null && n.TryGetValue(out value))
_worksWithMinorVersion = int.Parse(value);
n = node.Element("requiresManualIntervention");
if (n != null && n.TryGetValue(out value))
_requiresManualIntervention = bool.Parse(value);
n = node.Element("dateAdded");
if (n != null && n.TryGetValue(out value))
_dateAdded = DateTime.Parse(value);
n = node.Element("statisticsInfo");
if (n != null)
_statistics = new StatisticsInfo(n);
n = node.Element("purchaseInfo");
if (n != null)
_purchase = new PurchaseInfo(n);
n = node.Element("tags");
if (n != null)
{
foreach (XElement e in n.Elements("tag"))
{
string tag;
if (e.TryGetValue(out tag))
_tags.Add(tag);
}
}
}
示例14: Deserialize
internal static KernelMethodInfo Deserialize(XElement xe, CudafyModule parentModule, string directory = null)
{
string methodName = xe.GetAttributeValue(csNAME);
string methodTypeName = xe.GetAttributeValue(csTYPE);
eKernelMethodType methodType = (eKernelMethodType)Enum.Parse(typeof(eKernelMethodType), methodTypeName);
bool? isDummy = xe.TryGetAttributeBoolValue(csISDUMMY);
string behaviourStr = xe.TryGetAttributeValue(csDUMMYBEHAVIOUR);
string typeName = xe.Element(csTYPE).Value;
string assemblyFullName = xe.Element(csASSEMBLY).Value;
string assemblyName = xe.Element(csASSEMBLYNAME).Value;
string assemblyPath = xe.TryGetElementValue(csASSEMBLYPATH);
long checksum = XmlConvert.ToInt64(xe.Element(csCHECKSUM).Value);
eCudafyDummyBehaviour behaviour = string.IsNullOrEmpty(behaviourStr) ? eCudafyDummyBehaviour.Default : (eCudafyDummyBehaviour)Enum.Parse(typeof(eCudafyDummyBehaviour), behaviourStr);
MethodInfo mi = null;
KernelMethodInfo kmi = null;
if(!string.IsNullOrEmpty(typeName) && !string.IsNullOrEmpty(assemblyFullName))
{
Assembly assembly = null;
try
{
assembly = Assembly.Load(assemblyFullName);
}
catch (FileNotFoundException)
{
directory = directory != null ? directory : string.Empty;
assemblyName = directory + Path.DirectorySeparatorChar + assemblyName;
if (File.Exists(assemblyName + ".dll"))
{
assembly = Assembly.LoadFrom(assemblyName + ".dll");
}
else if (File.Exists(assemblyName + ".exe"))
{
assembly = Assembly.LoadFrom(assemblyName + ".exe");
}
else if (!string.IsNullOrEmpty(assemblyPath))
{
assembly = Assembly.LoadFrom(assemblyPath);
}
else
throw;
}
if (assembly == null)
throw new CudafyException(CudafyException.csCOULD_NOT_LOAD_ASSEMBLY_X, assemblyFullName);
Type type = assembly.GetType(typeName);
if (type == null)
throw new CudafyException(CudafyException.csCOULD_NOT_FIND_TYPE_X_IN_ASSEMBLY_X, typeName, assemblyFullName);
mi = type.GetMethod(methodName, BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);
if (mi == null)
throw new CudafyException(CudafyException.csCOULD_NOT_FIND_METHOD_X_IN_TYPE_X_IN_ASSEMBLY_X, methodName, typeName, assemblyFullName);
kmi = new KernelMethodInfo(type, mi, methodType, isDummy == true ? true : false, behaviour, parentModule);
}
kmi.DeserializedChecksum = checksum;
return kmi;
}
示例15: ParseVersion1
private static SettingsConfigurationFile ParseVersion1(XElement rootE)
{
string identifier = rootE.TryGetAttributeValue("Identifier", null);
if (string.IsNullOrWhiteSpace(identifier))
{
return null;
}
int iSetting = 0;
List<SettingItem> settings = new List<SettingItem>();
foreach (XElement settingE in rootE.Elements("Setting"))
{
// Dissect the element and retrieve all attributes
string name = settingE.TryGetAttributeValue("Name", null);
if (string.IsNullOrWhiteSpace(name))
{
Logger.Instance.LogFormat(LogType.Warning, typeof(SettingsConfigurationFileParser), Properties.Resources.SettingItemInvalidName, iSetting + 1);
continue;
}
string typeName = settingE.TryGetAttributeValue("Type", null);
if (string.IsNullOrWhiteSpace(typeName))
{
Logger.Instance.LogFormat(LogType.Warning, typeof(SettingsConfigurationFileParser), Properties.Resources.SettingItemEmptyType, name);
continue;
}
if (!SupportedSettingTypes.Contains(typeName))
{
Logger.Instance.LogFormat(LogType.Warning, typeof(SettingsConfigurationFileParser), Properties.Resources.SettingItemInvalidType, typeName, string.Join(",", SupportedSettingTypes));
continue;
}
bool isNull = settingE.TryGetAttributeValue("IsNull", false);
// Read the setting value. If it contains a CDATA, then we need to process that first.
string valueString = null;
XNode valueNode = settingE.DescendantNodes().FirstOrDefault();
if (valueNode != null)
{
switch (valueNode.NodeType)
{
case System.Xml.XmlNodeType.CDATA:
case System.Xml.XmlNodeType.Text:
valueString = ((XText)valueNode).Value;
break;
default:
Logger.Instance.LogFormat(LogType.Warning, typeof(SettingsConfigurationFile), Properties.Resources.SettingsConfigurationEmbResInvalidValueContent, valueNode.NodeType, name);
break;
}
}
// TODO: This will work only with primitive types (String, Boolean etc.). This could be made extensible to allow storing other types as well.
Type type = Type.GetType(typeName);
object defaultValue = Convert.ChangeType(valueString, type, CultureInfo.InvariantCulture);
SettingItem settingItem = new SettingItem(name, defaultValue, defaultValue, type);
settings.Add(settingItem);
iSetting++;
}
return new SettingsConfigurationFile(identifier, settings);
}