📄 tagelement.cs
字号:
namespace Imps.Utils.TagParser
{
using System;
using System.ComponentModel;
using System.Text;
public class TagElement : TagNode
{
protected HtmlAttributeCollection mAttributes;
protected bool mIsExplicitlyTerminated;
protected bool mIsTerminated;
protected string mName;
protected TagNodeCollection mNodes;
public TagElement(string name)
{
this.mNodes = new TagNodeCollection(this);
this.mAttributes = new HtmlAttributeCollection(this);
this.mName = name;
this.mIsTerminated = false;
}
public float GetAtributeFloat(string attributeName, float defaultValue)
{
float num = defaultValue;
TagAttribute attribute = this.Attributes[attributeName];
if ((attribute != null) && !float.TryParse(attribute.Value, ref num))
{
return defaultValue;
}
return num;
}
public bool GetAttributeBoolen(string attributeName, bool defauleValue)
{
bool flag = defauleValue;
TagAttribute attribute = this.Attributes[attributeName];
if ((attribute != null) && !bool.TryParse(attribute.Value, ref flag))
{
return defauleValue;
}
return flag;
}
public int GetAttributeInt(string attributeName, int defauleValue)
{
int num = defauleValue;
TagAttribute attribute = this.Attributes[attributeName];
if ((attribute != null) && !int.TryParse(attribute.Value, ref num))
{
return defauleValue;
}
return num;
}
public string GetAttributeString(string attributeName, string defauleValue)
{
string text = defauleValue;
TagAttribute attribute = this.Attributes[attributeName];
if (attribute != null)
{
text = attribute.Value;
}
return text;
}
public override string ToString()
{
string text = "<" + this.mName;
foreach (TagAttribute attribute in this.Attributes)
{
text = text + " " + attribute.ToString();
}
return (text + ">");
}
[Category("General"), Description("The set of attributes associated with this element")]
public HtmlAttributeCollection Attributes
{
get
{
return this.mAttributes;
}
}
[Category("Output")]
public override string HTML
{
get
{
StringBuilder builder = new StringBuilder();
builder.Append("<" + this.mName);
foreach (TagAttribute attribute in this.Attributes)
{
builder.Append(" " + attribute.HTML);
}
if (this.Nodes.Count > 0)
{
builder.Append(">");
foreach (TagNode node in this.Nodes)
{
builder.Append(node.HTML);
}
builder.Append("</" + this.mName + ">");
}
else if (this.IsExplicitlyTerminated)
{
builder.Append("></" + this.mName + ">");
}
else if (this.IsTerminated)
{
builder.Append("/>");
}
else
{
builder.Append(">");
}
return builder.ToString();
}
}
internal bool IsExplicitlyTerminated
{
get
{
return this.mIsExplicitlyTerminated;
}
set
{
this.mIsExplicitlyTerminated = value;
}
}
internal bool IsTerminated
{
get
{
if (this.Nodes.Count > 0)
{
return false;
}
return (this.mIsTerminated | this.mIsExplicitlyTerminated);
}
set
{
this.mIsTerminated = value;
}
}
[Category("General"), Description("The name of the tag/element")]
public string Name
{
get
{
return this.mName;
}
set
{
this.mName = value;
}
}
[Category("General"), Description("The set of child nodes")]
public TagNodeCollection Nodes
{
get
{
if (base.IsText())
{
throw new InvalidOperationException("An HtmlText node does not have child nodes");
}
return this.mNodes;
}
}
internal bool NoEscaping
{
get
{
if (!"script".Equals(this.Name.ToLower()))
{
return "style".Equals(this.Name.ToLower());
}
return true;
}
}
[Description("A concatination of all the text associated with this element"), Category("General")]
public override string Text
{
get
{
StringBuilder builder = new StringBuilder();
foreach (TagNode node in this.Nodes)
{
builder.Append(node.Text);
}
return builder.ToString();
}
}
[Category("Output")]
public override string XHTML
{
get
{
if ("html".Equals(this.mName) && (this.Attributes["xmlns"] == null))
{
this.Attributes.Add(new TagAttribute("xmlns", "http://www.w3.org/1999/xhtml"));
}
StringBuilder builder = new StringBuilder();
builder.Append("<" + this.mName.ToLower());
foreach (TagAttribute attribute in this.Attributes)
{
builder.Append(" " + attribute.XHTML);
}
if (this.IsTerminated)
{
builder.Append("/>");
}
else if (this.Nodes.Count > 0)
{
builder.Append(">");
foreach (TagNode node in this.Nodes)
{
builder.Append(node.XHTML);
}
builder.Append("</" + this.mName.ToLower() + ">");
}
else
{
builder.Append("/>");
}
return builder.ToString();
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -