本文整理汇总了C#中Attributes.Add方法的典型用法代码示例。如果您正苦于以下问题:C# Attributes.Add方法的具体用法?C# Attributes.Add怎么用?C# Attributes.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Attributes
的用法示例。
在下文中一共展示了Attributes.Add方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: handlesBaseUri
public void handlesBaseUri()
{
Tag tag = Tag.ValueOf("a");
Attributes attribs = new Attributes();
attribs.Add("relHref", "/foo");
attribs.Add("absHref", "http://bar/qux");
Element noBase = new Element(tag, "", attribs);
Assert.AreEqual("", noBase.AbsUrl("relHref")); // with no base, should NOT fallback to href attrib, whatever it is
Assert.AreEqual("http://bar/qux", noBase.AbsUrl("absHref")); // no base but valid attrib, return attrib
Element withBase = new Element(tag, "http://foo/", attribs);
Assert.AreEqual("http://foo/foo", withBase.AbsUrl("relHref")); // construct abs from base + rel
Assert.AreEqual("http://bar/qux", withBase.AbsUrl("absHref")); // href is abs, so returns that
Assert.AreEqual("", withBase.AbsUrl("noval"));
Element dodgyBase = new Element(tag, "wtf://no-such-protocol/", attribs);
Assert.AreEqual("http://bar/qux", dodgyBase.AbsUrl("absHref")); // base fails, but href good, so get that
Assert.AreEqual("", dodgyBase.AbsUrl("relHref")); // base fails, only rel href, so return nothing
}
示例2: UpdateCurrentAttributes
public void UpdateCurrentAttributes()
{
currentAtt = new Attributes();
currentAtt.Add(baseAtt);
currentAtt.Add(equipAtt);
currentAtt.Add(buffAtt);
currentAtt.MovementSpeed = Mathf.Clamp(currentAtt.MovementSpeed, minMovementSpeed, maxMovementSpeed);
currentAtt.AttackSpeed = Mathf.Clamp(currentAtt.AttackSpeed, minAttackSpeed, maxAttackSpeed);
GetComponent<MovementFSM>().UpdateMovementSpeed(currentAtt.MovementSpeed);
currentHP = Mathf.Clamp(currentHP, 0, currentAtt.Health);
currentResource = Mathf.Clamp(currentResource, 0, currentAtt.Resource);
}
示例3: GetEnforcedAttributes
public Attributes GetEnforcedAttributes(string tagName)
{
Attributes attrs = new Attributes();
TagName tag = TagName.ValueOf(tagName);
if (_enforcedAttributes.ContainsKey(tag))
{
Dictionary<AttributeKey, AttributeValue> keyVals = _enforcedAttributes[tag];
foreach (KeyValuePair<AttributeKey, AttributeValue> entry in keyVals)
{
attrs.Add(entry.Key.ToString(), entry.Value.ToString());
}
}
return attrs;
}
示例4: Process
public override bool Process(Token t, TreeBuilder tb)
{
switch (t.Type)
{
case Token.TokenType.Character:
Token.Character c = t.AsCharacter();
if (c.Data.Equals(_nullString))
{
// todo confirm that check
tb.Error(this);
return false;
}
else if (IsWhitespace(c))
{
tb.ReconstructFormattingElements();
tb.Insert(c);
}
else
{
tb.ReconstructFormattingElements();
tb.Insert(c);
tb.FramesetOk(false);
}
break;
case Token.TokenType.Comment:
tb.Insert(t.AsComment());
break;
case Token.TokenType.Doctype:
tb.Error(this);
return false;
case Token.TokenType.StartTag:
Token.StartTag startTag = t.AsStartTag();
string name = startTag.Name();
if (name.Equals("html"))
{
tb.Error(this);
// merge attributes onto real html
Element html = tb.Stack.First.Value;
foreach (NSoup.Nodes.Attribute attribute in startTag.Attributes)
{
if (!html.HasAttr(attribute.Key))
{
html.Attributes.Add(attribute);
}
}
}
else if (StringUtil.In(name, "base", "basefont", "bgsound", "command", "link", "meta", "noframes", "script", "style", "title"))
{
return tb.Process(t, InHead);
}
else if (name.Equals("body"))
{
tb.Error(this);
LinkedList<Element> stack = tb.Stack;
if (stack.Count == 1 || (stack.Count > 2 && !stack.ElementAt(1).NodeName.Equals("body")))
{
// only in fragment case
return false; // ignore
}
else
{
tb.FramesetOk(false);
Element body = stack.ElementAt(1);
foreach (NSoup.Nodes.Attribute attribute in startTag.Attributes)
{
if (!body.HasAttr(attribute.Key))
{
body.Attributes.Add(attribute);
}
}
}
}
else if (name.Equals("frameset"))
{
tb.Error(this);
LinkedList<Element> stack = tb.Stack;
if (stack.Count == 1 || (stack.Count > 2 && !stack.ElementAt(1).NodeName.Equals("body")))
{
// only in fragment case
return false; // ignore
}
else if (!tb.FramesetOk())
{
return false; // ignore frameset
}
else
{
Element second = stack.ElementAt(1);
if (second.Parent != null)
second.Remove();
// pop up to html element
while (stack.Count > 1)
{
stack.RemoveLast();
}
tb.Insert(startTag);
tb.Transition(InFrameset);
}
//.........这里部分代码省略.........
示例5: writeSignatureFile
/** Write a .SF file with a digest of the specified manifest. */
private static void writeSignatureFile(Manifest manifest, Stream out_)
{
Manifest sf = new Manifest();
Attributes main = sf.MainAttributes;
main.Add("Signature-Version", "1.0");
main.Add("Created-By", "1.0 (Android SignApk)");
DigestOutputStream digestStream = new DigestOutputStream("SHA1");
StreamWriter print = new StreamWriter(digestStream, new UTF8Encoding());
// Digest of the entire manifest
manifest.Write(digestStream);
print.Flush();
main.Add("SHA1-Digest-Manifest", Convert.ToBase64String(digestStream.Hash));
IDictionary<String, Attributes> entries = manifest.Entries;
foreach (var entry in entries)
{
// Digest of the manifest stanza for this entry.
print.Write("Name: " + entry.Key + "\r\n");
foreach (var att in entry.Value)
{
print.Write(att.Key + ": " + att.Value + "\r\n");
}
print.Write("\r\n");
print.Flush();
Attributes sfAttr = new Attributes();
sfAttr.Add("SHA1-Digest", Convert.ToBase64String(digestStream.Hash));
sf.Entries.Add(entry.Key, sfAttr);
}
sf.Write(out_);
// A bug in the java.util.jar implementation of Android platforms
// up to version 1.6 will cause a spurious IOException to be thrown
// if the length of the signature file is a multiple of 1024 bytes.
// As a workaround, add an extra CRLF in this case.
if ((out_.Length % 1024) == 0)
{
var b = Encoding.UTF8.GetBytes("\r\n");
out_.Write(b, 0, b.Length);
}
}
示例6: addOtacert
/**
* Add a copy of the public key to the archive; this should
* exactly match one of the files in_
* /system/etc/security/otacerts.zip on the device. (The same
* cert can be extracted from the CERT.RSA file but this is much
* easier to get at.)
*/
private static void addOtacert(ZipOutputStream outputJar,
X509Certificate2 certificate,
DateTime timestamp,
Manifest manifest)
{
HashAlgorithm md = HashAlgorithm.Create("SHA1");
byte[] b = certificate.Export(X509ContentType.Cert);
JarEntry je = new JarEntry(OTACERT_NAME);
je.DateTime = timestamp;
je.Size = b.Length;
outputJar.PutNextEntry(je);
outputJar.Write(b, 0, b.Length);
Attributes attr = new Attributes();
attr.Add("SHA1-Digest", Convert.ToBase64String(md.ComputeHash(b)));
manifest.Entries.Add(OTACERT_NAME, attr);
}
示例7: CreateSafeElement
private ElementMeta CreateSafeElement(Element sourceEl)
{
string sourceTag = sourceEl.TagName();
Attributes destAttrs = new Attributes();
Element dest = new Element(Tag.ValueOf(sourceTag), sourceEl.BaseUri, destAttrs);
int numDiscarded = 0;
Attributes sourceAttrs = sourceEl.Attributes;
foreach (NSoup.Nodes.Attribute sourceAttr in sourceAttrs)
{
if (_whitelist.IsSafeAttribute(sourceTag, sourceEl, sourceAttr))
destAttrs.Add(sourceAttr);
else
numDiscarded++;
}
Attributes enforcedAttrs = _whitelist.GetEnforcedAttributes(sourceTag);
foreach (NSoup.Nodes.Attribute item in enforcedAttrs)
{
destAttrs.Add(item);
}
return new ElementMeta(dest, numDiscarded);
}