本文整理汇总了C#中System.Xml.Linq.XElement.AddAnnotation方法的典型用法代码示例。如果您正苦于以下问题:C# XElement.AddAnnotation方法的具体用法?C# XElement.AddAnnotation怎么用?C# XElement.AddAnnotation使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Xml.Linq.XElement
的用法示例。
在下文中一共展示了XElement.AddAnnotation方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CloneWithAnnotation
private static XObject CloneWithAnnotation(XNode node)
{
XElement element = node as XElement;
if (element != null)
{
XElement newElement = new XElement(element.Name,
element.Attributes(),
element.Nodes().Select(n => CloneWithAnnotation(n)));
if (element.Annotation<MatchSemaphore>() != null)
newElement.AddAnnotation(element.Annotation<MatchSemaphore>());
}
return node;
}
示例2: AddUvmlAnnotations
/// <summary>
/// Adds UVML annotations to the specified UVML element tree.
/// </summary>
/// <param name="dataSourceTypeName">The name of the data source wrapper associated with this tree.</param>
/// <param name="root">The root of the UVML element tree to annotate.</param>
public static void AddUvmlAnnotations(String dataSourceTypeName, XElement root)
{
Contract.RequireNotEmpty(dataSourceTypeName, nameof(dataSourceTypeName));
Contract.Require(root, nameof(root));
var templates = 0;
if (root.Annotation<UvmlMetadataAnnotation>() != null)
return;
root.AddAnnotation(new UvmlMetadataAnnotation());
AddUvmlAnnotations(dataSourceTypeName, root, ref templates);
}
示例3: GetInstance
public static ASupportElement GetInstance(XElement definition)
{
Type eType = ElementType (definition);
if (eType != null) {
if (definition.Annotation (eType) != null)
return definition.Annotation (eType) as ASupportElement;
else {
var instance = Activator.CreateInstance (eType, new object[] { definition });
definition.AddAnnotation (instance);
return instance as ASupportElement;
}
} else
return null;
}
示例4: Translate
public BamlElement Translate(XamlContext ctx, BamlNode node, BamlElement parent) {
var record = (ConstructorParameterTypeRecord)((BamlRecordNode)node).Record;
var elem = new XElement(ctx.GetXamlNsName("TypeExtension", parent.Xaml));
elem.AddAnnotation(ctx.ResolveType(0xfd4d)); // Known type - TypeExtension
var bamlElem = new BamlElement(node);
bamlElem.Xaml = elem;
parent.Xaml.Element.Add(elem);
var type = ctx.ResolveType(record.TypeId);
var typeName = ctx.ToString(parent.Xaml, type);
elem.Add(new XElement(ctx.GetPseudoName("Ctor"), typeName));
return bamlElem;
}
示例5: TranslateDefer
public BamlElement TranslateDefer(XamlContext ctx, BamlNode node, BamlElement parent) {
var record = (DefAttributeKeyTypeRecord)((BamlRecordNode)node).Record;
var type = ctx.ResolveType(record.TypeId);
var typeName = ctx.ToString(parent.Xaml, type);
var key = (XamlResourceKey)node.Annotation;
var bamlElem = new BamlElement(node);
bamlElem.Xaml = new XElement(ctx.GetXamlNsName("Key", parent.Xaml));
parent.Xaml.Element.Add(bamlElem.Xaml.Element);
var typeElem = new XElement(ctx.GetXamlNsName("TypeExtension", parent.Xaml));
typeElem.AddAnnotation(ctx.ResolveType(0xfd4d)); // Known type - TypeExtension
typeElem.Add(new XElement(ctx.GetPseudoName("Ctor"), typeName));
bamlElem.Xaml.Element.Add(typeElem);
key.KeyElement = bamlElem;
return bamlElem;
}
示例6: AddEventXElementShouldBeNotifiedWithAnnotations
public void AddEventXElementShouldBeNotifiedWithAnnotations()
{
var el = new XElement("test");
bool changedNotification = false;
var handler = new EventHandler<XObjectChangeEventArgs>(
(sender, cea) =>
{
changedNotification = true;
}
);
el.AddAnnotation(new object());
el.Changed += handler;
var child = new XElement("test2");
el.Add(child);
Assert.True(changedNotification);
changedNotification = false;
child.Add(new XAttribute("a", "b"));
Assert.True(changedNotification);
}
示例7: Translate
public BamlElement Translate(XamlContext ctx, BamlNode node, BamlElement parent) {
var record = (PropertyTypeReferenceRecord)((BamlRecordNode)node).Record;
var attr = ctx.ResolveProperty(record.AttributeId);
var type = ctx.ResolveType(record.TypeId);
var typeName = ctx.ToString(parent.Xaml, type);
var elem = new BamlElement(node);
var elemAttr = ctx.ResolveProperty(record.AttributeId);
elem.Xaml = new XElement(elemAttr.ToXName(ctx, null));
elem.Xaml.Element.AddAnnotation(elemAttr);
parent.Xaml.Element.Add(elem.Xaml.Element);
var typeElem = new XElement(ctx.GetXamlNsName("TypeExtension", parent.Xaml));
typeElem.AddAnnotation(ctx.ResolveType(0xfd4d)); // Known type - TypeExtension
typeElem.Add(new XElement(ctx.GetPseudoName("Ctor"), typeName));
elem.Xaml.Element.Add(typeElem);
elemAttr.DeclaringType.ResolveNamespace(elem.Xaml, ctx);
elem.Xaml.Element.Name = elemAttr.ToXName(ctx, null);
return elem;
}
示例8: ProcessHyperlinkToBookmark
private static object ProcessHyperlinkToBookmark(WordprocessingDocument wordDoc, HtmlConverterSettings settings, XElement element)
{
var style = new Dictionary<string, string>();
var a = new XElement(Xhtml.a,
new XAttribute("href", "#" + (string) element.Attribute(W.anchor)),
element.Elements(W.r).Select(run => ConvertRun(wordDoc, settings, run)));
style.Add("text-decoration", "none");
a.AddAnnotation(style);
return a;
}
示例9: CreateBorderDivs
private static object CreateBorderDivs(WordprocessingDocument wordDoc, HtmlConverterSettings settings, IEnumerable<XElement> elements)
{
return elements.GroupAdjacent(e =>
{
var pBdr = e.Elements(W.pPr).Elements(W.pBdr).FirstOrDefault();
if (pBdr != null)
{
var indStr = string.Empty;
var ind = e.Elements(W.pPr).Elements(W.ind).FirstOrDefault();
if (ind != null)
indStr = ind.ToString(SaveOptions.DisableFormatting);
return pBdr.ToString(SaveOptions.DisableFormatting) + indStr;
}
return e.Name == W.tbl ? "table" : string.Empty;
})
.Select(g =>
{
if (g.Key == string.Empty)
{
return (object) GroupAndVerticallySpaceNumberedParagraphs(wordDoc, settings, g, 0m);
}
if (g.Key == "table")
{
return g.Select(gc => ConvertToHtmlTransform(wordDoc, settings, gc, false, 0));
}
var pPr = g.First().Elements(W.pPr).First();
var pBdr = pPr.Element(W.pBdr);
var style = new Dictionary<string, string>();
GenerateBorderStyle(pBdr, W.top, style, BorderType.Paragraph);
GenerateBorderStyle(pBdr, W.right, style, BorderType.Paragraph);
GenerateBorderStyle(pBdr, W.bottom, style, BorderType.Paragraph);
GenerateBorderStyle(pBdr, W.left, style, BorderType.Paragraph);
var currentMarginLeft = 0m;
var ind = pPr.Element(W.ind);
if (ind != null)
{
var leftInInches = (decimal?) ind.Attribute(W.left)/1440m ?? 0;
var hangingInInches = -(decimal?) ind.Attribute(W.hanging)/1440m ?? 0;
currentMarginLeft = leftInInches + hangingInInches;
style.AddIfMissing("margin-left",
currentMarginLeft > 0m
? string.Format(NumberFormatInfo.InvariantInfo, "{0:0.00}in", currentMarginLeft)
: "0");
}
var div = new XElement(Xhtml.div,
GroupAndVerticallySpaceNumberedParagraphs(wordDoc, settings, g, currentMarginLeft));
div.AddAnnotation(style);
return div;
})
.ToList();
}
示例10: ConvertRun
/*
* Handle:
* - b
* - bdr
* - caps
* - color
* - dstrike
* - highlight
* - i
* - position
* - rFonts
* - shd
* - smallCaps
* - spacing
* - strike
* - sz
* - u
* - vanish
* - vertAlign
*
* Don't handle:
* - em
* - emboss
* - fitText
* - imprint
* - kern
* - outline
* - shadow
* - w
*
*/
private static object ConvertRun(WordprocessingDocument wordDoc, HtmlConverterSettings settings, XElement run)
{
var rPr = run.Element(W.rPr);
if (rPr == null)
return run.Elements().Select(e => ConvertToHtmlTransform(wordDoc, settings, e, false, 0m));
// hide all content that contains the w:rPr/w:webHidden element
if (rPr.Element(W.webHidden) != null)
return null;
var style = DefineRunStyle(run);
object content = run.Elements().Select(e => ConvertToHtmlTransform(wordDoc, settings, e, false, 0m));
// Wrap content in h:sup or h:sub elements as necessary.
if (rPr.Element(W.vertAlign) != null)
{
XElement newContent = null;
var vertAlignVal = (string)rPr.Elements(W.vertAlign).Attributes(W.val).FirstOrDefault();
switch (vertAlignVal)
{
case "superscript":
newContent = new XElement(Xhtml.sup, content);
break;
case "subscript":
newContent = new XElement(Xhtml.sub, content);
break;
}
if (newContent != null && newContent.Nodes().Any())
content = newContent;
}
var langAttribute = GetLangAttribute(run);
XEntity runStartMark;
XEntity runEndMark;
DetermineRunMarks(run, rPr, style, out runStartMark, out runEndMark);
if (style.Any() || langAttribute != null || runStartMark != null)
{
style.AddIfMissing("margin", "0");
style.AddIfMissing("padding", "0");
var xe = new XElement(Xhtml.span,
langAttribute,
runStartMark,
content,
runEndMark);
xe.AddAnnotation(style);
content = xe;
}
return content;
}
示例11: SerializeXElement
// typeScope is applied for child items, rather than obj itself.
private XElement SerializeXElement(object obj, Type defaultType, XName name, SerializationScope typeScope)
{
Debug.Assert(obj != null && defaultType != null && name != null);
var objType = obj.GetType();
var objTypeName = _Builder.GlobalScope.GetName(objType);
if (objTypeName == null)
throw new NotSupportedException(string.Format(Prompts.UnregisteredType, objType, _Builder.GlobalScope));
var s = _Builder.GetSerializer(objType);
var e = new XElement(name);
//如果名义类型和实际类型不同,则注明实际类型。
//如果是 TypeScope 中未定义的类型,则使用对应的元素名,而不使用 xsi:type
if (name != objTypeName && objType != defaultType)
{
//先将 XName 加入批注,到根节点中处理。
e.AddAnnotation(objTypeName);
}
//一般不会调用到此处,除非 obj 是根部节点,或是集合中的一项。
if (s == null)
throw new NotSupportedException(string.Format(Prompts.UnregisteredType, objType, typeScope));
EnterObjectSerialization(obj);
s.Serialize(e, obj, this, typeScope);
ExitObjectSerialization(obj);
return e;
}
示例12: ConvertRun
//.........这里部分代码省略.........
{
style.AddIfMissing("font-weight", "normal");
}
// W.strike
if (getBoolProp(rPr, W.strike) || getBoolProp(rPr, W.dstrike))
{
var newContent = new XElement(Xhtml.s, content);
if (newContent.Nodes().Any())
content = newContent;
style.AddIfMissing("text-decoration", "line-through");
}
// W.vertAlign
if (rPr.Element(W.vertAlign) != null && (string)rPr.Elements(W.vertAlign).Attributes(W.val).FirstOrDefault() == "superscript")
{
var newContent = new XElement(Xhtml.sup, content);
if (newContent.Nodes().Any())
content = newContent;
}
if (rPr.Element(W.vertAlign) != null && (string)rPr.Elements(W.vertAlign).Attributes(W.val).FirstOrDefault() == "subscript")
{
var newContent = new XElement(Xhtml.sub, content);
if (newContent.Nodes().Any())
content = newContent;
}
var rtl = rPr.Element(W.rtl);
var isRtl = rtl != null;
var paragraph = run.Ancestors(W.p).FirstOrDefault();
var paraBidi = paragraph
.Elements(W.pPr)
.Elements(W.bidi)
.Where(b => b.Attribute(W.val) == null || b.Attribute(W.val).ToBoolean() == true)
.FirstOrDefault();
var paraIsBidi = paraBidi != null;
string lang = null;
if (languageType == "western")
lang = (string)rPr.Elements(W.lang).Attributes(W.val).FirstOrDefault();
else if (languageType == "bidi")
lang = (string)rPr.Elements(W.lang).Attributes(W.bidi).FirstOrDefault();
else if (languageType == "eastAsia")
lang = (string)rPr.Elements(W.lang).Attributes(W.eastAsia).FirstOrDefault();
// only do the following for text runs.
XEntity runStartMark = null;
XEntity runEndMark = null;
// Can't add directional marks if the font-family is symbol - they are visible, and display as a ?
bool addDirectionalMarks = true;
if (style.ContainsKey("font-family"))
{
if (style["font-family"].ToLower() == "symbol")
addDirectionalMarks = false;
}
if (addDirectionalMarks)
{
if (run.Element(W.t) != null)
{
if (isRtl)
{
runStartMark = new XEntity("#x200f"); // RLM
runEndMark = new XEntity("#x200f"); // RLM
}
else
{
if (paraIsBidi)
{
runStartMark = new XEntity("#x200e"); // LRM
runEndMark = new XEntity("#x200e"); // LRM
}
}
}
}
string defaultLanguage = "en-US"; // todo need to get defaultLanguage
if (lang == null)
lang = defaultLanguage;
XAttribute langAttribute = new XAttribute("lang", lang);
if (lang == defaultLanguage)
langAttribute = null;
if (style.Any() || isRtl || langAttribute != null)
{
style.AddIfMissing("margin", "0in");
style.AddIfMissing("padding", "0in");
var xe = new XElement(Xhtml.span,
langAttribute,
runStartMark,
content,
runEndMark);
xe.AddAnnotation(style);
content = xe;
}
return content;
}
示例13: ProcessTableRow
private static object ProcessTableRow(WordprocessingDocument wordDoc, HtmlConverterSettings settings, XElement element,
decimal currentMarginLeft)
{
var style = new Dictionary<string, string>();
int? trHeight = (int?) element.Elements(W.trPr).Elements(W.trHeight).Attributes(W.val).FirstOrDefault();
if (trHeight != null)
style.AddIfMissing("height",
string.Format(NumberFormatInfo.InvariantInfo, "{0:0.00}in", (decimal) trHeight/1440m));
var htmlRow = new XElement(Xhtml.tr,
element.Elements().Select(e => ConvertToHtmlTransform(wordDoc, settings, e, false, currentMarginLeft)));
if (style.Any())
htmlRow.AddAnnotation(style);
return htmlRow;
}
示例14: ProcessTable
private static object ProcessTable(WordprocessingDocument wordDoc, HtmlConverterSettings settings, XElement element, decimal currentMarginLeft)
{
var style = new Dictionary<string, string>();
style.AddIfMissing("border-collapse", "collapse");
style.AddIfMissing("border", "none");
var bidiVisual = element.Elements(W.tblPr).Elements(W.bidiVisual).FirstOrDefault();
var tblW = element.Elements(W.tblPr).Elements(W.tblW).FirstOrDefault();
if (tblW != null)
{
var type = (string)tblW.Attribute(W.type);
if (type != null && type == "pct")
{
var w = (int)tblW.Attribute(W._w);
style.AddIfMissing("width", (w / 50) + "%");
}
}
var tblInd = element.Elements(W.tblPr).Elements(W.tblInd).FirstOrDefault();
if (tblInd != null)
{
var tblIndType = (string)tblInd.Attribute(W.type);
if (tblIndType != null)
{
if (tblIndType == "dxa")
{
var width = (decimal?)tblInd.Attribute(W._w);
if (width != null)
{
style.AddIfMissing("margin-left",
width > 0m
? string.Format(NumberFormatInfo.InvariantInfo, "{0}pt", width / 20m)
: "0");
}
}
}
}
var tableDirection = bidiVisual != null ? new XAttribute("dir", "rtl") : new XAttribute("dir", "ltr");
style.AddIfMissing("margin-bottom", ".001pt");
var table = new XElement(Xhtml.table,
// TODO: Revisit and make sure the omission is covered by appropriate CSS.
// new XAttribute("border", "1"),
// new XAttribute("cellspacing", 0),
// new XAttribute("cellpadding", 0),
tableDirection,
element.Elements().Select(e => ConvertToHtmlTransform(wordDoc, settings, e, false, currentMarginLeft)));
table.AddAnnotation(style);
var jc = (string)element.Elements(W.tblPr).Elements(W.jc).Attributes(W.val).FirstOrDefault() ?? "left";
XAttribute dir = null;
XAttribute jcToUse = null;
if (bidiVisual != null)
{
dir = new XAttribute("dir", "rtl");
if (jc == "left")
jcToUse = new XAttribute("align", "right");
else if (jc == "right")
jcToUse = new XAttribute("align", "left");
else if (jc == "center")
jcToUse = new XAttribute("align", "center");
}
else
{
jcToUse = new XAttribute("align", jc);
}
var tableDiv = new XElement(Xhtml.div,
dir,
jcToUse,
table);
return tableDiv;
}
示例15: ObjectToElement
//.........这里部分代码省略.........
try {
INakedObjectAdapter value = oneToOneAssociation.GetNakedObject(nakedObjectAdapter);
// a null value would be a programming error, but we protect
// against it anyway
if (value == null) {
continue;
}
ITypeSpec valueNos = value.Spec;
// XML
NofMetaModel.SetAttributesForValue(xmlValueElement, valueNos.ShortName);
bool notEmpty = (value.TitleString().Length > 0);
if (notEmpty) {
string valueStr = value.TitleString();
xmlValueElement.Add(new XText(valueStr));
}
else {
NofMetaModel.SetIsEmptyAttribute(xmlValueElement, true);
}
}
catch (Exception) {
Log.Warn("objectToElement(NO): " + DoLog("field", fieldName) + ": getField() threw exception - skipping XML generation");
}
// XSD
xsdFieldElement = Schema.CreateXsElementForNofValue(xsElement, xmlValueElement);
}
else if (oneToOneAssociation != null) {
Log.Debug("objectToElement(NO): " + DoLog("field", fieldName) + " is IOneToOneAssociation");
XElement xmlReferenceElement = xmlFieldElement; // more meaningful locally scoped name
try {
INakedObjectAdapter referencedNakedObjectAdapter = oneToOneAssociation.GetNakedObject(nakedObjectAdapter);
string fullyQualifiedClassName = field.ReturnSpec.FullName;
// XML
NofMetaModel.SetAttributesForReference(xmlReferenceElement, Schema.Prefix, fullyQualifiedClassName);
if (referencedNakedObjectAdapter != null) {
NofMetaModel.AppendNofTitle(xmlReferenceElement, referencedNakedObjectAdapter.TitleString());
}
else {
NofMetaModel.SetIsEmptyAttribute(xmlReferenceElement, true);
}
}
catch (Exception) {
Log.Warn("objectToElement(NO): " + DoLog("field", fieldName) + ": getAssociation() threw exception - skipping XML generation");
}
// XSD
xsdFieldElement = Schema.CreateXsElementForNofReference(xsElement, xmlReferenceElement, oneToOneAssociation.ReturnSpec.FullName);
}
else if (oneToManyAssociation != null) {
Log.Debug("objectToElement(NO): " + DoLog("field", fieldName) + " is IOneToManyAssociation");
XElement xmlCollectionElement = xmlFieldElement; // more meaningful locally scoped name
try {
INakedObjectAdapter collection = oneToManyAssociation.GetNakedObject(nakedObjectAdapter);
ITypeOfFacet facet = collection.GetTypeOfFacetFromSpec();
IObjectSpecImmutable referencedTypeNos = facet.GetValueSpec(collection, metamodelManager.Metamodel);
string fullyQualifiedClassName = referencedTypeNos.FullName;
// XML
NofMetaModel.SetNofCollection(xmlCollectionElement, Schema.Prefix, fullyQualifiedClassName, collection, nakedObjectManager);
}
catch (Exception) {
Log.Warn("objectToElement(NO): " + DoLog("field", fieldName) + ": get(obj) threw exception - skipping XML generation");
}
// XSD
xsdFieldElement = Schema.CreateXsElementForNofCollection(xsElement, xmlCollectionElement, oneToManyAssociation.ReturnSpec.FullName);
}
else {
Log.Info("objectToElement(NO): " + DoLog("field", fieldName) + " is unknown type; ignored");
continue;
}
if (xsdFieldElement != null) {
xmlFieldElement.AddAnnotation(xsdFieldElement);
}
// XML
Log.Debug("objectToElement(NO): invoking mergeTree for field");
MergeTree(element, xmlFieldElement);
// XSD
if (xsdFieldElement != null) {
Log.Debug("objectToElement(NO): adding XS element for field to schema");
Schema.AddFieldXsElement(xsElement, xsdFieldElement);
}
}
return place;
}