當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。