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


C# XmlElement.ThrowIfNull方法代码示例

本文整理汇总了C#中System.Xml.XmlElement.ThrowIfNull方法的典型用法代码示例。如果您正苦于以下问题:C# XmlElement.ThrowIfNull方法的具体用法?C# XmlElement.ThrowIfNull怎么用?C# XmlElement.ThrowIfNull使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Xml.XmlElement的用法示例。


在下文中一共展示了XmlElement.ThrowIfNull方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Create

        /// <summary>
        /// Creates a data-form instance of the proper type from the specified
        /// XML element.
        /// </summary>
        /// <param name="element">The XML element to create the data-form instance
        /// from.</param>
        /// <returns>An initialized instance of a data-form class of the respectiv
        /// type which derives from the DataForm base class.</returns>
        /// <exception cref="ArgumentNullException">The element parameter is
        /// null.</exception>
        /// <exception cref="ArgumentException">The specified XML element is not a
        /// valid data-form element.</exception>
        public static DataForm Create(XmlElement element)
        {
            element.ThrowIfNull("element");
            if (element.Name != "x" || element.NamespaceURI != "jabber:x:data")
                throw new ArgumentException("Invalid root element: " + element.Name);
            string s = element.GetAttribute("type");
            if (String.IsNullOrEmpty(s))
                throw new ArgumentException("Missing 'type' attribute.");
            try
            {
                DataFormType type = Util.ParseEnum<DataFormType>(s);
                switch (type)
                {
                    case DataFormType.Form:
                        return new RequestForm(element);

                    case DataFormType.Submit:
                        return new SubmitForm(element);

                    case DataFormType.Cancel:
                        return new CancelForm(element);

                    case DataFormType.Result:
                        return new ResultForm(element);

                    default:
                        throw new ArgumentException("Invalid form type: " + type);
                }
            }
            catch (Exception e)
            {
                throw new XmlException("Invalid data-form element.", e);
            }
        }
开发者ID:agimenezwally,项目名称:Sharp.Xmpp,代码行数:46,代码来源:DataFormFactory.cs

示例2: Parse

		/// <summary>
		/// Parses the the specified negotiation offer or result.
		/// </summary>
		/// <param name="feature">The 'feature' element containing the data-form</param>
		/// <returns>An initialized data-form instance.</returns>
		/// <exception cref="ArgumentNullException">The feature parameter is
		/// null.</exception>
		/// <exception cref="ArgumentException">The feature parameter is not a
		/// valid 'feature' XML element, or the feature element contains invalid
		/// data.</exception>
		public static DataForm Parse(XmlElement feature) {
			feature.ThrowIfNull("feature");
			if (feature.Name != "feature" || feature.NamespaceURI !=
				"http://jabber.org/protocol/feature-neg" || feature["x"] == null) {
					throw new ArgumentException("Invalid XML 'feature' element.");
			}
			return DataFormFactory.Create(feature["x"]);
		}
开发者ID:BlueBasher,项目名称:S22.Xmpp,代码行数:18,代码来源:FeatureNegotiation.cs

示例3: Posts

 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="Element">Element containing post info</param>
 public Posts(XmlElement Element)
 {
     Element.ThrowIfNull("Element");
     PostList = new List<Post>();
     foreach (XmlNode Children in Element.ChildNodes)
     {
         if (Children.Name.Equals("post", StringComparison.CurrentCultureIgnoreCase))
             PostList.Add(new Post((XmlElement)Children));
     }
 }
开发者ID:summer-breeze,项目名称:ChengGouHui,代码行数:14,代码来源:Posts.cs

示例4: Tags

 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="Element">Element containing tags info</param>
 public Tags(XmlElement Element)
 {
     Element.ThrowIfNull("Element");
     TagList = new List<Tag>();
     foreach (XmlNode Children in Element.ChildNodes)
     {
         if (Children.Name.Equals("tag", StringComparison.CurrentCultureIgnoreCase))
             TagList.Add(new Tag((XmlElement)Children));
     }
 }
开发者ID:JKLFA,项目名称:Craig-s-Utility-Library,代码行数:14,代码来源:Tags.cs

示例5: Categories

 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="Element">Categories element</param>
 public Categories(XmlElement Element)
 {
     Element.ThrowIfNull("Element");
     CategoryList = new List<Category>();
     foreach (XmlNode Children in Element.ChildNodes)
     {
         if (Children.Name.Equals("category", StringComparison.CurrentCultureIgnoreCase))
             CategoryList.Add(new Category((XmlElement)Children));
     }
 }
开发者ID:summer-breeze,项目名称:ChengGouHui,代码行数:14,代码来源:Categories.cs

示例6: Authors

 public Authors(XmlElement Element)
 {
     Element.ThrowIfNull("Element");
     AuthorList = new List<Author>();
     foreach (XmlNode Children in Element.ChildNodes)
     {
         if (Children.Name.Equals("author", StringComparison.CurrentCultureIgnoreCase))
             AuthorList.Add(new Author((XmlElement)Children));
     }
 }
开发者ID:Adilson,项目名称:Craig-s-Utility-Library,代码行数:10,代码来源:Authors.cs

示例7: Author

 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="Element">XML element containing the author info</param>
 public Author(XmlElement Element)
 {
     Element.ThrowIfNull("Element");
     ID = Element.Attributes["id"] != null ? Element.Attributes["id"].Value : "";
     Email = Element.Attributes["email"] != null ? Element.Attributes["email"].Value : "";
     REF = Element.Attributes["ref"] != null ? Element.Attributes["ref"].Value : "";
     foreach (XmlNode Children in Element.ChildNodes)
     {
         if (Children.Name.Equals("title", StringComparison.CurrentCultureIgnoreCase))
             Title = Children.InnerText;
     }
 }
开发者ID:JKLFA,项目名称:Craig-s-Utility-Library,代码行数:16,代码来源:Author.cs

示例8: Category

 public Category(XmlElement Element)
 {
     Element.ThrowIfNull("Element");
     ID = Element.Attributes["id"] != null ? Element.Attributes["id"].Value : "";
     REF = Element.Attributes["ref"] != null ? Element.Attributes["ref"].Value : "";
     DateCreated = Element.Attributes["date-created"] != null ? DateTime.Parse(Element.Attributes["date-created"].Value, CultureInfo.InvariantCulture) : DateTime.Now;
     DateModified = Element.Attributes["date-modified"] != null ? DateTime.Parse(Element.Attributes["date-modified"].Value, CultureInfo.InvariantCulture) : DateTime.Now;
     ParentREF = Element.Attributes["parentref"] != null ? Element.Attributes["parentref"].Value : "";
     foreach (XmlNode Children in Element.ChildNodes)
     {
         if (Children.Name.Equals("title", StringComparison.CurrentCultureIgnoreCase))
             Title = Children.InnerText;
     }
 }
开发者ID:jerrymds,项目名称:Concord,代码行数:14,代码来源:Category.cs

示例9: Post

        public Post(XmlElement Element)
        {
            Element.ThrowIfNull("Element");
            DateCreated = DateTime.Now;
            DateModified = DateTime.Now;
            ID = Element.Attributes["id"] != null ? Element.Attributes["id"].Value : "";
            PostURL = Element.Attributes["post-url"] != null ? Element.Attributes["post-url"].Value : "";
            DateCreated = Element.Attributes["date-created"] != null ? DateTime.Parse(Element.Attributes["date-created"].Value, CultureInfo.InvariantCulture) : DateTime.MinValue;
            DateModified = Element.Attributes["date-modified"] != null ? DateTime.Parse(Element.Attributes["date-modified"].Value, CultureInfo.InvariantCulture) : DateCreated;

            foreach (XmlElement Children in Element.ChildNodes)
            {
                if (Children.Name.Equals("title", StringComparison.CurrentCultureIgnoreCase))
                {
                    Title = Children.InnerText;
                }
                else if (Children.Name.Equals("content", StringComparison.CurrentCultureIgnoreCase))
                {
                    Content = Children.InnerText;
                }
                else if (Children.Name.Equals("post-name", StringComparison.CurrentCultureIgnoreCase))
                {
                    PostName = Children.InnerText;
                }
                else if (Children.Name.Equals("excerpt", StringComparison.CurrentCultureIgnoreCase))
                {
                    Excerpt = Children.InnerText;
                }
                else if (Children.Name.Equals("authors", StringComparison.CurrentCultureIgnoreCase))
                {
                    Authors = new Authors(Children);
                }
                else if (Children.Name.Equals("categories", StringComparison.CurrentCultureIgnoreCase))
                {
                    Categories = new Categories(Children);
                }
                else if (Children.Name.Equals("tags", StringComparison.CurrentCultureIgnoreCase))
                {
                    Tags = new Tags(Children);
                }
                else if (Children.Name.Equals("comments", StringComparison.CurrentCultureIgnoreCase))
                {
                    Comments = new Comments(Children);
                }
            }
        }
开发者ID:bbqchickenrobot,项目名称:Craig-s-Utility-Library,代码行数:46,代码来源:Post.cs

示例10: Comment

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="Element">Element containing the post info</param>
        public Comment(XmlElement Element)
        {
            Element.ThrowIfNull("Element");
            DateCreated = Element.Attributes["date-created"] != null ? DateTime.Parse(Element.Attributes["date-created"].Value) : DateTime.MinValue;
            Approved = Element.Attributes["approved"] != null ? bool.Parse(Element.Attributes["approved"].Value) : false;
            UserName = Element.Attributes["user-name"] != null ? Element.Attributes["user-name"].Value : "";
            UserEmail = Element.Attributes["user-email"] != null ? Element.Attributes["user-email"].Value : "";
            UserIP = Element.Attributes["user-ip"] != null ? Element.Attributes["user-ip"].Value : "";
            UserURL = Element.Attributes["user-url"] != null ? Element.Attributes["user-url"].Value : "";

            foreach (XmlNode Children in Element.ChildNodes)
            {
                if (Children.Name.Equals("title", StringComparison.CurrentCultureIgnoreCase))
                    Title = Children.InnerText;
                else if (Children.Name.Equals("content", StringComparison.CurrentCultureIgnoreCase))
                    Content = Children.InnerText;
            }
        }
开发者ID:JKLFA,项目名称:Craig-s-Utility-Library,代码行数:22,代码来源:Comment.cs

示例11: XmppError

 /// <summary>
 /// Initializes a new Error instance from the specified XML element.
 /// </summary>
 /// <param name="error">The 'error' XML element to initialize this
 /// instance with.</param>
 /// <exception cref="ArgumentNullException">The error parameter is null.</exception>
 /// <exception cref="ArgumentException">The error parameter contains
 /// invalid XML data.</exception>
 internal XmppError(XmlElement error)
 {
     error.ThrowIfNull("error");
     // Verify mandatory error type attribute.
     ErrorType type = (ErrorType)Enum.Parse(typeof(ErrorType),
         error.GetAttribute("type"), true);
     // Look for mandatory error condition element.
     ErrorCondition? condition = null;
     foreach (var v in Enum.GetValues(typeof(ErrorCondition)))
     {
         string s = ErrorConditionToTagName((ErrorCondition)v);
         if (error[s] != null)
             condition = (ErrorCondition)v;
     }
     if (!condition.HasValue)
         throw new ArgumentException("The error XML element does not contain a " +
             "valid XMPP error condition element.");
     Data = error;
     Type = type;
     Condition = condition.Value;
 }
开发者ID:agimenezwally,项目名称:Sharp.Xmpp,代码行数:29,代码来源:XmppError.cs

示例12: DataField

 /// <summary>
 /// Initializes a new instance of the DataField class from the specified
 /// XML element.
 /// </summary>
 /// <param name="element">The XML 'field' element to initialize the instance
 /// with.</param>
 /// <exception cref="ArgumentNullException">The element parameter is
 /// null.</exception>
 /// <exception cref="ArgumentException">The specified XML element is not a
 /// valid data-field element.</exception>
 internal DataField(XmlElement element)
 {
     element.ThrowIfNull("element");
     this.element = element;
     try
     {
         // Call GetDataFieldType method to verify the 'type' attribute.
         GetDataFieldType();
     }
     catch (XmlException e)
     {
         throw new ArgumentException("The element parameter is not a valid " +
             "data-field.", e);
     }
 }
开发者ID:agimenezwally,项目名称:Sharp.Xmpp,代码行数:25,代码来源:DataField.cs

示例13: Tag

 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="Element">Element containing the tag info</param>
 public Tag(XmlElement Element)
 {
     Element.ThrowIfNull("Element");
     if (Element.Attributes["ref"] != null)
         REF = Element.Attributes["ref"].Value;
 }
开发者ID:AngelMarquez,项目名称:Craig-s-Utility-Library,代码行数:10,代码来源:Tag.cs

示例14: Stanza

 /// <summary>
 /// Initializes a new instance of the Stanza class using the specified
 /// XmlElement.
 /// </summary>
 /// <param name="element">The XmlElement to create the stanza from.</param>
 /// <exception cref="ArgumentNullException">The element parameter is
 /// null.</exception>
 protected Stanza(XmlElement element)
 {
     element.ThrowIfNull("element");
     this.element = element;
 }
开发者ID:agimenezwally,项目名称:Sharp.Xmpp,代码行数:12,代码来源:Stanza.cs

示例15: OptionFromElement

 /// <summary>
 /// Creates an Option instance from the specified XML element.
 /// </summary>
 /// <param name="element">The XML element to create an option from.</param>
 /// <returns>An initialized instance of the Option class.</returns>
 /// <exception cref="ArgumentNullException">The element parameter is
 /// null.</exception>
 /// <exception cref="ArgumentException">The specified XML element is not
 /// a valid 'option' element.</exception>
 private Option OptionFromElement(XmlElement element)
 {
     element.ThrowIfNull("element");
     string label = element.GetAttribute("label");
     if (label == string.Empty)
         label = null;
     if (element["value"] == null)
         throw new ArgumentException("Missing 'value' child.");
     string value = element["value"].InnerText;
     return new Option(value, label);
 }
开发者ID:REPLDigital,项目名称:Sharp.Xmpp,代码行数:20,代码来源:ListField.cs


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