本文整理汇总了C#中Element.AddAttribute方法的典型用法代码示例。如果您正苦于以下问题:C# Element.AddAttribute方法的具体用法?C# Element.AddAttribute怎么用?C# Element.AddAttribute使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Element
的用法示例。
在下文中一共展示了Element.AddAttribute方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddAttributes
protected void AddAttributes(Element el)
{
el.AddAttribute("type", "submit");
if (!string.IsNullOrEmpty(AccessKey))
el.AddAttribute("accesskey", AccessKey);
if (!Enabled)
el.AddAttribute("disabled", "disabled");
if (!string.IsNullOrEmpty(ToolTip))
el.AddAttribute("title", ToolTip);
if (!string.IsNullOrEmpty(CssClass))
el.AddAttribute("class", CssClass);
string style = Style.Value;
if (!string.IsNullOrEmpty(style))
el.AddAttribute("style", style);
}
示例2: ToElement
public static IElement ToElement(this HtmlNode self, INode parent)
{
if (self == null)
throw new ArgumentNullException("self");
if (parent == null)
throw new ArgumentNullException("parent");
var name = self.ToQualifiedName();
var element = new Element(parent, name);
foreach (var attribute in self.ToAttributes(element))
element.AddAttribute(attribute);
foreach (var child in self.ToChildren(element))
element.AddChild(child);
var customElement = GetCustomElement(element, parent, name);
if (customElement != null)
{
foreach (var attribute in self.ToAttributes(customElement))
customElement.AddAttribute(attribute);
foreach (var child in self.ToChildren(customElement))
customElement.AddChild(child);
return customElement;
}
return element;
}
示例3: ProcessAttributes
private void ProcessAttributes(Element element)
{
TypeBrowser browser = TypeBrowser.Create(element.GetType());
while (_reader.MoveToNextAttribute())
{
// Check for namespaces first
if (string.Equals("xmlns", _reader.Name, StringComparison.Ordinal))
{
// Set default namespace only on unknown elements
if (element is UnknownElement)
{
element.Namespaces.AddNamespace(string.Empty, _reader.Value);
}
}
else if (string.Equals("xmlns", _reader.Prefix, StringComparison.Ordinal))
{
element.Namespaces.AddNamespace(_reader.LocalName, _reader.Value);
}
else // just a normal attribute
{
PropertyInfo property = browser.FindAttribute(new XmlComponent(null, _reader.LocalName, null)); // Attributes never have namespace info.
if (property != null)
{
AssignValue(element, property, _reader.Value);
}
else
{
// Unknown, save for later serialization
element.AddAttribute(new XmlComponent(_reader));
}
}
}
}