当前位置: 首页>>代码示例>>C#>>正文


C# XElement.TryGetAttributeValue方法代码示例

本文整理汇总了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", ":");
 }
开发者ID:Knatter33,项目名称:AlarmWorkflow,代码行数:11,代码来源:AreaDefinition.cs

示例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", ":");
 }
开发者ID:The-Stig,项目名称:AlarmWorkflow,代码行数:12,代码来源:AreaDefinition.cs

示例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;
        }
开发者ID:chartek,项目名称:graffiticms,代码行数:28,代码来源:CreatorInfo.cs

示例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);
            }
        }
开发者ID:Knatter33,项目名称:AlarmWorkflow,代码行数:35,代码来源:SectionDefinition.cs

示例5:

        object IAddressProvider.ParseXElement(XElement element)
        {
            string address = element.Value;
            string receiptType = element.TryGetAttributeValue("Type", MailingEntryObject.ReceiptType.To.ToString());

            return MailingEntryObject.FromAddress(address, receiptType);
        }
开发者ID:The-Stig,项目名称:AlarmWorkflow,代码行数:7,代码来源:MailingJobAddressProvider.cs

示例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);
            }
        }
开发者ID:The-Stig,项目名称:AlarmWorkflow,代码行数:23,代码来源:SectionDefinition.cs

示例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;
        }
开发者ID:happy5217744,项目名称:AlarmWorkflow,代码行数:10,代码来源:PushAddressProvider.cs

示例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;
            }
        }
开发者ID:Knatter33,项目名称:AlarmWorkflow,代码行数:18,代码来源:SectionParserDefinition.cs

示例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;
        }
开发者ID:chartek,项目名称:graffiticms,代码行数:15,代码来源:MessageInfo.cs

示例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;
        }
开发者ID:constructor-igor,项目名称:cudafy,代码行数:48,代码来源:KernelTypeInfo.cs

示例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;
        }
开发者ID:chartek,项目名称:graffiticms,代码行数:17,代码来源:CategoryInfo.cs

示例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);
        }
开发者ID:chartek,项目名称:graffiticms,代码行数:19,代码来源:CatalogInfo.cs

示例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);
                }
            }
        }
开发者ID:chartek,项目名称:graffiticms,代码行数:76,代码来源:ItemInfo.cs

示例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;
        }
开发者ID:JustasB,项目名称:cudafy,代码行数:55,代码来源:KernelMethodInfo.cs

示例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);
        }
开发者ID:The-Stig,项目名称:AlarmWorkflow,代码行数:65,代码来源:SettingsConfigurationFileParser.cs


注:本文中的System.Xml.Linq.XElement.TryGetAttributeValue方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。