本文整理汇总了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);
}
}
示例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"]);
}
示例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));
}
}
示例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));
}
}
示例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));
}
}
示例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));
}
}
示例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;
}
}
示例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;
}
}
示例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);
}
}
}
示例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;
}
}
示例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;
}
示例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);
}
}
示例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;
}
示例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;
}
示例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);
}