private void setRoot(XObject root) { if (root is XDocument) _current = ((XDocument)root).Root; else _current = root; }
public bool Serialize(IMemberContext source, XObject target, IAdviceRequester adviceRequester) { if (source == null) throw new ArgumentNullException("source"); if (target.NodeType != XmlNodeType.Element) throw new ArgumentException("Parameter must be an XML element.", "target"); var elem = (XElement)target; IObjectContext sourceObject = source.GetValue(); if (sourceObject == null || sourceObject.GetObject() == null) { if (_isNullableStrategy.IsNullable(source, elem, adviceRequester)) { elem.Add(Constants.XsiNilAttribute); return true; } return false; } List<IMapping<IMemberContext, XObject>> mappings = _mapper.MapForSerialization(source, elem, adviceRequester) .ToList(); if (mappings == null) throw new ArgumentException("Unable to map source '" + source + "' and target '" + target + "'."); SerializeRecursively(elem, mappings, adviceRequester); return true; }
private XObject FindObject(string id, XObject root) { var o = root.FindLocal(id); if (o == null) throw new InvalidOperationException(string.Format("Iterator '{0}' could not find obect id: '{1}'", this.Id, id)); return o; }
public ParseDefinitionFileException(string message, XObject source) : base(GetMessage(message, source)) { _source = source; Line = (source as IXmlLineInfo).LineNumber; Position = (source as IXmlLineInfo).LinePosition; }
public static void AreEqual(XObject expected, XObject actual) { if (expected is XDocument) { expected = ((XDocument)expected).Root; } if (actual is XDocument) { actual = ((XDocument)actual).Root; } if (expected == null && actual == null) { return; } if (expected == null) { RaiseAssertFailure(null, actual); return; } if (actual == null) { RaiseAssertFailure(expected, null); return; } if (expected.GetType() != actual.GetType()) { RaiseAssertFailure(expected, actual); return; } AssertEqualValues(expected, actual); }
public static DateTimeOffset? InstantOrNull(XObject elem) { string value = StringValueOrNull(elem); return String.IsNullOrEmpty(value) ? (DateTimeOffset?)null : PrimitiveTypeConverter.ConvertTo<DateTimeOffset>(value); }
public XObject CreateInstance(XObject placeholder) { var instance = TemplateObject.Copy(); CopyAttributes(placeholder, instance); // move subcomponents from the placeholder to the new instance while(placeholder.Subcomponents != null && placeholder.Subcomponents.Count > 0) { var subcomponent = placeholder.Subcomponents[0]; placeholder.Subcomponents.RemoveAt(0); instance.Subcomponents.Add(subcomponent); } var parent = placeholder.Parent; // replace the placeholder with the new instance int instanceIndex = parent.Subcomponents.IndexOf(placeholder); parent.Subcomponents.RemoveAt(instanceIndex); parent.Subcomponents.Insert(instanceIndex, instance); ReplaceParameters(instance, placeholder.ClassParams); return instance; }
public override void InitHierarchy() { this.TemplateObject = this.Subcomponents.Find(o => !(o is XResourceBundle)); this.Subcomponents.Remove(TemplateObject); base.InitHierarchy(); }
public static bool BindLiteralOrReference(ParserContext context, XObject xmlObject, string xmlValue, PropertyInfo boundProperty) { object convertedLiteralValue; if (LiteralTypeConverter.TryConvert(boundProperty.PropertyType, xmlValue, out convertedLiteralValue)) { if (BindExpression(context, xmlObject, xmlValue, boundProperty)) { return true; } BindFinalValue(boundProperty, context.FrameworkItem, convertedLiteralValue, xmlObject, true); return true; } if (xmlObject is XAttribute) { if (BindExpression(context, xmlObject, xmlValue, boundProperty)) { return true; } DelayedBind(context, xmlObject, xmlValue, boundProperty); return true; } return false; }
public void CopyAttributes(XObject src, XObject dest) { dest.Id = src.Id; //dest.Class = src.Class; dest.Enabled = src.Enabled; // Element var srcElement = src as XElement; if (srcElement != null) { var destElement = (XElement)dest; destElement.Bounds = srcElement.Bounds; if (srcElement.backColor.HasValue) destElement.BackColor = srcElement.BackColor; if (srcElement.Rotation != 0) destElement.Rotation = srcElement.Rotation; } // IHasPoints var srcHasPoints = src as IHasPoints; if (srcHasPoints != null && srcHasPoints.Points != 0) { ((IHasPoints)dest).Points = srcHasPoints.Points; } var srcEnemy = src as XEnemy; if (srcEnemy != null && srcEnemy.DamageSpecified) { ((XEnemy)dest).Damage = srcEnemy.Damage; } }
public Type GetActualType(XObject source, IMemberContext target, IAdviceRequester adviceRequester) { return Converters .Select(c => c.GetActualType(source, target, adviceRequester)) .Where(t => t != null) .FirstOrDefault(); }
public object Parse(Type type, XObject config, bool isAssignableTypeAllowed, XmlLocation childLocation, IContext context) { var xel = config as XElement; if (xel == null) throw new TestLibsException($"Couldn't cast following config to XElement:\n{config}"); return xel; }
/// <summary> /// Initializes a new instance. /// </summary> /// <param name="xml"></param> /// <param name="context"></param> /// <param name="xpath"></param> internal Binding(XObject xml, EvaluationContext context, string xpath) : this(xml, context, context.CompileXPath(xml, xpath)) { Contract.Requires<ArgumentNullException>(xml != null); Contract.Requires<ArgumentNullException>(context != null); Contract.Requires<ArgumentNullException>(xpath != null); }
public int? GetNodeCount(XObject xml, string xpath) { if(xml == null) { return null; } if(xml.Document == null) { return null; } if(xml.Document.Root == null) { return null; } try { var namespaceResolver = new SimpleXmlNamespaceResolver(xml.Document); var results = (IEnumerable)xml.Document.XPathEvaluate(xpath, namespaceResolver); return results.OfType<XObject>().Count(); } catch(Exception) { return null; } }
public IDeserializer Select(XObject source, IMemberContext target, IAdviceRequester adviceRequester) { return Selectors .Select(s => s.Select(source, target, adviceRequester)) .Where(d => d != null) .FirstOrDefault(); }
public ISerializer Select(IMemberContext source, XObject target, IAdviceRequester adviceRequester) { if (target.NodeType != XmlNodeType.Element) return null; return _serializer; }
internal override void UpdateProgress(UpdateParameters p) { if (this.objects != null) { for(int i = 0; i < this.objects.Count; i++) { var obj = this.objects[i]; if (obj.Enabled) { this.Current = this.objects[i]; this.UpdateChildren(p); } } } else { p.ScreenEngine.RootComponent.TraveseTree(o => { if (this.TypeFilterType.IsAssignableFrom(o.GetType())) { if (o.Enabled) { this.Current = o; this.UpdateChildren(p); } } }); } }
protected virtual IDeserializer Select(XObject source, IMemberContext target, Type type, IAdviceRequester adviceRequester) { var typeCode = Type.GetTypeCode(type); switch (typeCode) { case TypeCode.Empty: case TypeCode.DBNull: return null; case TypeCode.Object: if (target.ContractType == typeof(TimeSpan)) break; if (target.ContractType == typeof(string)) break; if (target.ContractType.IsNullable()) break; return null; } if (source == null) return GetDeserializer(type); if (source.NodeType == XmlNodeType.Element && !((XElement)source).HasElements) return GetDeserializer(type); if (source.NodeType == XmlNodeType.Attribute) return GetDeserializer(type); return null; }
internal Tuple<bool, bool> CanExecute( XObject selectedElement, object docView, object singleViewModelSelection, object propertiesCompartment, bool isSingleSelection) { return _canExecute == null ? new Tuple<bool, bool>(true, true) : _canExecute(selectedElement, docView, singleViewModelSelection, propertiesCompartment, isSingleSelection); }
public EventsHelper(XObject x) { _root = x; _root.Changing += new EventHandler<XObjectChangeEventArgs>(Changing); _root.Changed += new EventHandler<XObjectChangeEventArgs>(Changed); _events = new Queue<EventItem>(); }
public void Deserialize(XObject source, IMemberContext target, IAdviceRequester adviceRequester) { if (source == null) return; if (source.NodeType != XmlNodeType.Element) throw new ArgumentException("Parameter must be an XML element.", "source"); if (_log.IsDebugEnabled) _log.Debug("Deserializing " + source.ToFriendlyName() + " into " + target + "."); var elem = (XElement)source; Type targetType = _typeConverter.GetActualType(source, target, adviceRequester); if (targetType == null) throw new ArgumentException("Unable to get target type for target '" + target + "'."); IObjectContext targetObject = _objectContextFactory.CreateForDeserialization(target, targetType, adviceRequester); if (targetObject == null) throw new ArgumentException("Unable to create target object for target '" + target + "'."); target.SetValue(targetObject); List<IMapping<XObject, IMemberContext>> mappings = _mapper.MapForDeserialization(elem, target, adviceRequester) .ToList(); if (mappings == null) throw new ArgumentException("Unable to map source '" + source + "' and target '" + target + "'."); DeserializeRecursively(mappings, adviceRequester); target.CommitChanges(); }
public override void AddSubcomponent(string name, XObject sub) { if (this.Levels == null) this.Levels = new List<XLevelInfo>(); this.Levels.Add((XLevelInfo)sub); }
public override IDeserializer Select(XObject source, IMemberContext target, IAdviceRequester adviceRequester) { var contractTypeFromAttr = GetContractTypeFromAttributes(source, target); if (contractTypeFromAttr == null) return null; return Select(source, target, contractTypeFromAttr, adviceRequester); }
public virtual TextSpan GetTextSpanForXObject(XObject xobject, Uri uri) { Debug.Assert(uri != null, "uri != null"); return xobject != null ? GetXmlModel(uri).GetTextSpan(xobject) : new TextSpan(); }
/// <summary> /// Initializes a new instance. /// </summary> /// <param name="xml"></param> /// <param name="evaluationContext"></param> public EvaluationXsltContext( XObject xml, EvaluationContext evaluationContext) : this(xml.Exports().GetExportedValue<IXsltContextFunctionProvider>(), xml, evaluationContext) { Contract.Requires<ArgumentNullException>(xml != null); Contract.Requires<ArgumentNullException>(evaluationContext != null); }
/// <summary> /// Initializes a new instance. /// </summary> /// <param name="xml"></param> public ModelItem(XObject xml) { Contract.Requires<ArgumentNullException>(xml != null); this.xml = xml; this.model = new Lazy<Model>(() => xml.Document.Annotation<Model>()); this.instance = new Lazy<Instance>(() => xml.Document.Annotation<Instance>()); this.state = new Lazy<ModelItemState>(() => xml.AnnotationOrCreate<ModelItemState>()); }
public BindingItem(PropertyInfo boundProperty, XObject xmlObject, string xmlValue, IFrameworkItem parentItem, BimlFile bimlFile, ITemplateInstance templateInstance) { BoundProperty = boundProperty; XObject = xmlObject; XValue = xmlValue; ParentItem = parentItem; BimlFile = bimlFile; TemplateInstance = templateInstance; }
public MultipleMatchesAdviceRequestedEventArgs(XElement source, IObjectContext targetOwner, IMemberContext target, IEnumerable<XObject> matches, XObject selectedMatch) : base(CommonAdviceTypes.MultipleMatches) { Source = source; TargetOwner = targetOwner; Target = target; Matches = (matches ?? Enumerable.Empty<XObject>()).ToList(); SelectedMatch = selectedMatch; }
public XPathNavigator(XObject obj) { _obj = obj; _nameTable = new NameTable(); _nameTable.Add(string.Empty); _nameTable.Add("http://www.w3.org/2000/xmlns/"); _nameTable.Add("http://www.w3.org/XML/1998/namespace"); }
bool IsValid(XObject obj) { return(obj.AnnotationOrCreate <ValidityAnnotation>(() => new ValidityAnnotation(true)).Valid); }
void SelectPath(int depth, bool contents) { //clone the parser and put it in tree mode Parser treeParser = this.tracker.Engine.GetTreeParser(); //locate the node List <XObject> path = new List <XObject> (treeParser.Nodes); //note: list is backwards, and we want ignore the root XDocument XObject ob = path [path.Count - (depth + 2)]; XNode node = ob as XNode; XElement el = node as XElement; //hoist this as it may not be cheap to evaluate (P/Invoke), but won't be changing during the loop int textLen = Editor.Length; //run the parser until the tag's closed, or we move to its sibling or parent if (node != null) { while (node.NextSibling == null && treeParser.Position < textLen && treeParser.Nodes.Peek() != ob.Parent) { char c = Editor.GetCharAt(treeParser.Position); treeParser.Push(c); if (el != null && el.IsClosed && el.ClosingTag.IsComplete) { break; } } } else { while (ob.Region.End < ob.Region.Start && treeParser.Position < textLen && treeParser.Nodes.Peek() != ob.Parent) { char c = Editor.GetCharAt(treeParser.Position); treeParser.Push(c); } } if (el == null) { MonoDevelop.Core.LoggingService.LogDebug("Selecting {0}", ob.Region); EditorSelect(ob.Region); } else if (el.IsClosed) { MonoDevelop.Core.LoggingService.LogDebug("Selecting {0}-{1}", el.Region.Start, el.ClosingTag.Region.End); if (el.IsSelfClosing) { contents = false; } //pick out the locations, with some offsets to account for the parsing model DomLocation s = contents? el.Region.End : el.Region.Start; DomLocation e = contents? el.ClosingTag.Region.Start : el.ClosingTag.Region.End; EditorSelect(new DomRegion(s, e)); } else { MonoDevelop.Core.LoggingService.LogDebug("No end tag found for selection"); } }
public XObject[] GetValueAsNodeArray(XObject node) { return(null); }
// change back to protected once we can remove the XML Editor workaround internal void SetXObject(XObject xobject) { _xobject = xobject; }
/// <summary> /// Recupera l'esspressione xpath di un determinato XObject /// </summary> /// <param name="xobj">Oggetto da valutare</param> /// <returns>xpath in formato stringa</returns> public static string GetXPath(this XObject xobj) { if (xobj.Parent == null) { var doc = xobj as XDocument; if (doc != null) { return("."); } var el = xobj as XElement; if (el != null) { return("/" + NameWithPredicate(el)); } XText xt = xobj as XText; if (xt != null) { return(null); } XComment com = xobj as XComment; if (com != null) { return ("/" + ( com .Document .Nodes() .OfType <XComment>() .Count() != 1 ? "comment()[" + (com .NodesBeforeSelf() .OfType <XComment>() .Count() + 1) + "]" : "comment()" )); } XProcessingInstruction pi = xobj as XProcessingInstruction; if (pi != null) { return ("/" + ( pi.Document.Nodes() .OfType <XProcessingInstruction>() .Count() != 1 ? "processing-instruction()[" + (pi .NodesBeforeSelf() .OfType <XProcessingInstruction>() .Count() + 1) + "]" : "processing-instruction()" )); } return(null); } else { XElement el = xobj as XElement; if (el != null) { return ("/" + el .Ancestors() .InDocumentOrder() .Select(NameWithPredicate) .StrCat("/") + NameWithPredicate(el)); } XAttribute at = xobj as XAttribute; if (at != null) { return ("/" + at .Parent .AncestorsAndSelf() .InDocumentOrder() .Select(NameWithPredicate) .StrCat("/") + "@" + GetQName(at)); } XComment com = xobj as XComment; if (com != null) { return ("/" + com .Parent .AncestorsAndSelf() .InDocumentOrder() .Select(NameWithPredicate) .StrCat("/") + ( com .Parent .Nodes() .OfType <XComment>() .Count() != 1 ? "comment()[" + (com .NodesBeforeSelf() .OfType <XComment>() .Count() + 1) + "]" : "comment()" )); } XCData cd = xobj as XCData; if (cd != null) { return ("/" + cd .Parent .AncestorsAndSelf() .InDocumentOrder() .Select(NameWithPredicate) .StrCat("/") + ( cd .Parent .Nodes() .OfType <XText>() .Count() != 1 ? "text()[" + (cd .NodesBeforeSelf() .OfType <XText>() .Count() + 1) + "]" : "text()" )); } XText tx = xobj as XText; if (tx != null) { return ("/" + tx .Parent .AncestorsAndSelf() .InDocumentOrder() .Select(NameWithPredicate) .StrCat("/") + ( tx .Parent .Nodes() .OfType <XText>() .Count() != 1 ? "text()[" + (tx .NodesBeforeSelf() .OfType <XText>() .Count() + 1) + "]" : "text()" )); } XProcessingInstruction pi = xobj as XProcessingInstruction; if (pi != null) { return ("/" + pi .Parent .AncestorsAndSelf() .InDocumentOrder() .Select(NameWithPredicate) .StrCat("/") + ( pi .Parent .Nodes() .OfType <XProcessingInstruction>() .Count() != 1 ? "processing-instruction()[" + (pi .NodesBeforeSelf() .OfType <XProcessingInstruction>() .Count() + 1) + "]" : "processing-instruction()" )); } return(null); } }
public string GetXpathName(XObject node, IDictionary <string, string> namespacePrefixes) { return("text()"); }
public override TextSpan GetTextSpan(XObject node) { throw new NotImplementedException(); }
/** * <summary>Populates a PDF file with contents.</summary> */ private void Populate( Document document, XObject form ) { // 1. Add a page to the document! Page page = new Page(document); // Instantiates the page inside the document context. document.Pages.Add(page); // Puts the page in the pages collection. // 2. Create a content composer for the content stream! PrimitiveComposer composer = new PrimitiveComposer(page); // 3. Inserting contents... SizeF pageSize = page.Size; // 3.1. Showing the form on the page... { SizeF formSize = form.Size; // Form 1. composer.ShowXObject( form, new PointF(pageSize.Width / 2, pageSize.Height / 2), GeomUtils.Scale(formSize, new SizeF(300, 0)), XAlignmentEnum.Center, YAlignmentEnum.Middle, 45 ); // Form 2. composer.ShowXObject( form, new PointF(0, pageSize.Height), GeomUtils.Scale(formSize, new SizeF(0, 300)), XAlignmentEnum.Left, YAlignmentEnum.Bottom, 0 ); // Form 3. composer.ShowXObject( form, new PointF(pageSize.Width, pageSize.Height), new SizeF(80, 200), XAlignmentEnum.Right, YAlignmentEnum.Bottom, 0 ); } // 3.2. Showing the comments on the page... { BlockComposer blockComposer = new BlockComposer(composer); RectangleF frame = new RectangleF( 18, 18, pageSize.Width * .5f, pageSize.Height * .5f ); blockComposer.Begin(frame, XAlignmentEnum.Justify, YAlignmentEnum.Top); StandardType1Font bodyFont = new StandardType1Font( document, StandardType1Font.FamilyEnum.Courier, true, false ); composer.SetFont(bodyFont, 24); blockComposer.ShowText("Page-to-form sample"); SizeF breakSize = new SizeF(0, 8); blockComposer.ShowBreak(breakSize); composer.SetFont(bodyFont, 8); blockComposer.ShowText("This sample shows how to convert a page to a reusable form that can be placed multiple times on other pages scaling, rotating, anchoring and aligning it."); blockComposer.ShowBreak(breakSize); blockComposer.ShowText("On this page you can see some of the above-mentioned transformations:"); breakSize.Width = 8; blockComposer.ShowBreak(breakSize); blockComposer.ShowText("1. anchored to the center of the page, rotated by 45 degrees counterclockwise, 300 point wide (preserved proportions);"); blockComposer.ShowBreak(breakSize); blockComposer.ShowText("2. anchored to the bottom-left corner of the page, 300 point high (preserved proportions);"); blockComposer.ShowBreak(breakSize); blockComposer.ShowText("3. anchored to the bottom-right of the page, 80 point wide and 200 point high (altered proportions)."); blockComposer.End(); } // 4. Flush the contents into the content stream! composer.Flush(); }
private void Throw(string message, XObject @object = null) { ThrowInvalidOperation(message, @object ?? _current); }
protected void Throw(string message, XObject @object = null) { ThrowInvalidOperation(message, @object ?? Current); }
public void GetAllNull(XObject xo) { AssertExtensions.Throws <ArgumentNullException>("type", () => xo.Annotations(null)); AssertExtensions.Throws <ArgumentNullException>("type", () => xo.Annotations(null)); }
public void AddNull(XObject xo) { AssertExtensions.Throws <ArgumentNullException>("annotation", () => xo.AddAnnotation(null)); Assert.Null(xo.Annotation <object>()); AssertExtensions.Throws <ArgumentNullException>("annotation", () => xo.AddAnnotation(null)); }
/// <summary> /// Serializes the <see cref="XNode"/> to a JSON string. /// </summary> /// <param name="node">The node to convert to JSON.</param> /// <returns>A JSON string of the XNode.</returns> public static string SerializeXNode(XObject node) { return(SerializeXNode(node, Formatting.None)); }
/// <summary> /// Serializes the <see cref="XNode"/> to a JSON string using formatting. /// </summary> /// <param name="node">The node to convert to JSON.</param> /// <param name="formatting">Indicates how the output is formatted.</param> /// <returns>A JSON string of the XNode.</returns> public static string SerializeXNode(XObject node, Formatting formatting) { return(SerializeXNode(node, formatting, false)); }
public XObject GetValueAsNode(XObject node) { return GetNodePropertyValue(node, _propertyName); }
public override bool KeyPress(Gdk.Key key, char keyChar, Gdk.ModifierType modifier) { Tracker.UpdateEngine(); if (razorDocument == null) { return(NonCSharpCompletion(key, keyChar, modifier)); } var n = Tracker.Engine.Nodes.Peek(); if (prevNode is RazorExpression && !(n is RazorExpression)) { updateNeeded = true; } prevNode = n; var state = Tracker.Engine.CurrentState; int off = document.Editor.Caret.Offset; char previousChar = off > 0 ? document.Editor.GetCharAt(off - 1) : ' '; char beforePrevious = off > 1 ? document.Editor.GetCharAt(off - 2) : ' '; // Determine completion context here, before calling base method to set the context correctly // Rule out Razor comments, html, transition sign (@) and e-mail addresses if (state is RazorCommentState || (previousChar != '@' && !(state is RazorState)) || keyChar == '@' || (previousChar == '@' && Char.IsLetterOrDigit(beforePrevious))) { return(NonCSharpCompletion(key, keyChar, modifier)); } // Determine if we are inside generics if (previousChar == '<') { var codeState = state as RazorCodeFragmentState; if (codeState == null || !codeState.IsInsideGenerics) { return(NonCSharpCompletion(key, keyChar, modifier)); } } // Determine whether we begin an html tag or generics else if (keyChar == '<' && (n is XElement || !Char.IsLetterOrDigit(previousChar))) { return(NonCSharpCompletion(key, keyChar, modifier)); } // Determine whether we are inside html text or in code else if (previousChar != '@' && n is XElement && !(state is RazorSpeculativeState) && !(state is RazorExpressionState)) { return(NonCSharpCompletion(key, keyChar, modifier)); } // We're in C# context InitializeCodeCompletion(); SwitchToHidden(); bool result; try { result = base.KeyPress(key, keyChar, modifier); if (EnableParameterInsight && (keyChar == ',' || keyChar == ')') && CanRunParameterCompletionCommand()) { base.RunParameterCompletionCommand(); } } finally { SwitchToReal(); } return(result); }
/// <summary> /// Handles the NaN value. /// </summary> /// <param name="propertyInfo">The property information.</param> /// <param name="xmlObject">The XML object.</param> /// <param name="propertyType">Type of the property.</param> /// <param name="propertyPath">The property path.</param> /// <param name="propertyValue">The property value.</param> protected override void HandleNaNValue(PropertyInfo propertyInfo, XObject xmlObject, Type propertyType, string propertyPath, string propertyValue) { AddProjectionProperty(propertyPath); }
/// <summary> /// Handles the null value. /// </summary> /// <param name="propertyInfo">The property information.</param> /// <param name="xmlObject">The XML object.</param> /// <param name="propertyType">Type of the property.</param> /// <param name="propertyPath">The property path.</param> /// <param name="propertyValue">The property value.</param> protected override void HandleNullValue(PropertyInfo propertyInfo, XObject xmlObject, Type propertyType, string propertyPath, string propertyValue) { UnsetProperty(propertyInfo, propertyPath); }
public async Task <IViewComponentResult> InvokeAsync(XType xtype, XObject xobject, XPropertyInfo property, char key, int index) { return(View(new _XPropertyInfoModel(null, property, key, index))); }
public object GetValueAsFragment(XObject node) { return null; }
public XObjectWrapper(XObject xmlObject) { _xmlObject = xmlObject; }
static XElement \u206D([In] XObject obj0) { // ISSUE: unable to decompile the method. }
// Token: 0x06000FD1 RID: 4049 RVA: 0x0005045C File Offset: 0x0004E65C public Class_397(XObject arg_0) { this.field_0 = arg_0; }
public void RemoveAnnotationTwice(XObject xo) { xo.RemoveAnnotations <object>(); xo.RemoveAnnotations <object>(); Assert.Equal(expected: 0, actual: CountAnnotations <object>(xo)); }
/// <summary> /// Adds content to the <c><head></c> section, such as title, meta, /// link and script elements. /// </summary> public virtual void AddHeadContent(XObject content) { headElements.Add(content); }
/// <summary> /// Serializes the <see cref="XNode"/> to a JSON string. /// </summary> /// <param name="node">The node to convert to JSON.</param> /// <param name="formatting">Indicates how the output is formatted.</param> /// <returns>A JSON string of the XNode.</returns> public static string SerializeXNode(XObject node, Formatting formatting) { XmlNodeConverter converter = new XmlNodeConverter(); return(SerializeObject(node, formatting, converter)); }
public static string GetXPath(this XObject xobj) { if (xobj.Parent == null) { var doc = xobj as XDocument; if (doc != null) { return("."); } var el = xobj as XElement; if (el != null) { return("/" + NameWithPredicate(el)); } var xt = xobj as XText; if (xt != null) { return(null); } // //the following doesn't work because the XPath data //model doesn't include white space text nodes that //are children of the document. // //return // "/" + // ( // xt // .Document // .Nodes() // .OfType<XText>() // .Count() != 1 ? // "text()[" + // (xt // .NodesBeforeSelf() // .OfType<XText>() // .Count() + 1) + "]" : // "text()" // ); // var com = xobj as XComment; if (com != null && com.Document != null) { return ("/" + ( com .Document .Nodes() .OfType <XComment>() .Count() != 1 ? "comment()[" + (com .NodesBeforeSelf() .OfType <XComment>() .Count() + 1) + "]" : "comment()" )); } var pi = xobj as XProcessingInstruction; if (pi != null) { return ("/" + ( pi.Document != null && pi.Document.Nodes().OfType <XProcessingInstruction>().Count() != 1 ? "processing-instruction()[" + (pi .NodesBeforeSelf() .OfType <XProcessingInstruction>() .Count() + 1) + "]" : "processing-instruction()" )); } return(null); } else { var el = xobj as XElement; if (el != null) { return ("/" + el .Ancestors() .InDocumentOrder() .Select(e => NameWithPredicate(e)) .StrCat("/") + NameWithPredicate(el)); } var at = xobj as XAttribute; if (at != null && at.Parent != null) { return ("/" + at .Parent .AncestorsAndSelf() .InDocumentOrder() .Select(e => NameWithPredicate(e)) .StrCat("/") + "@" + GetQName(at)); } var com = xobj as XComment; if (com != null && com.Parent != null) { return ("/" + com .Parent .AncestorsAndSelf() .InDocumentOrder() .Select(e => NameWithPredicate(e)) .StrCat("/") + ( com .Parent .Nodes() .OfType <XComment>() .Count() != 1 ? "comment()[" + (com .NodesBeforeSelf() .OfType <XComment>() .Count() + 1) + "]" : "comment()" )); } var cd = xobj as XCData; if (cd != null && cd.Parent != null) { return ("/" + cd .Parent .AncestorsAndSelf() .InDocumentOrder() .Select(e => NameWithPredicate(e)) .StrCat("/") + ( cd .Parent .Nodes() .OfType <XText>() .Count() != 1 ? "text()[" + (cd .NodesBeforeSelf() .OfType <XText>() .Count() + 1) + "]" : "text()" )); } var tx = xobj as XText; if (tx != null && tx.Parent != null) { return ("/" + tx .Parent .AncestorsAndSelf() .InDocumentOrder() .Select(e => NameWithPredicate(e)) .StrCat("/") + ( tx .Parent .Nodes() .OfType <XText>() .Count() != 1 ? "text()[" + (tx .NodesBeforeSelf() .OfType <XText>() .Count() + 1) + "]" : "text()" )); } var pi = xobj as XProcessingInstruction; if (pi != null && pi.Parent != null) { return ("/" + pi .Parent .AncestorsAndSelf() .InDocumentOrder() .Select(e => NameWithPredicate(e)) .StrCat("/") + ( pi .Parent .Nodes() .OfType <XProcessingInstruction>() .Count() != 1 ? "processing-instruction()[" + (pi .NodesBeforeSelf() .OfType <XProcessingInstruction>() .Count() + 1) + "]" : "processing-instruction()" )); } return(null); } }
public XNodeNavigator(XNode node, XmlNameTable?nameTable) { _source = node; _nameTable = nameTable != null ? nameTable : CreateNameTable(); }
public XNodeNavigator(XNodeNavigator other) { _source = other._source; _parent = other._parent; _nameTable = other._nameTable; }
public static XObject SerializeSingleValue(Type type, string xmlField, object value, bool onlyIdForObjects, bool useAttribute, bool selfOnlySerialization, bool parentSelfOnlySerialization) { if (value == null) { return(null); } XObject returnVal = null; if (type == typeof(Boolean)) { if ((Boolean)value) { returnVal = BusinessObjectHelper.CreateXObject(xmlField, "1", useAttribute); } else { returnVal = BusinessObjectHelper.CreateXObject(xmlField, "0", useAttribute); } } else if (type == typeof(String) || type == typeof(Int32) || type == typeof(Int32?)) { returnVal = BusinessObjectHelper.CreateXObject(xmlField, value.ToString(), useAttribute); } else if (type == typeof(Decimal) || type == typeof(Decimal?)) { returnVal = BusinessObjectHelper.CreateXObject(xmlField, ((Decimal)value).ToString(CultureInfo.InvariantCulture), useAttribute); } else if (type == typeof(Guid) || type == typeof(Guid?)) { returnVal = BusinessObjectHelper.CreateXObject(xmlField, ((Guid)value).ToUpperString(), useAttribute); } else if (type == typeof(DateTime) || type == typeof(DateTime?)) { returnVal = BusinessObjectHelper.CreateXObject(xmlField, ((DateTime)value).ToIsoString(), useAttribute); } else if (type == typeof(XElement)) { XElement xValue = (XElement)value; if ((xValue.FirstNode is XElement || xValue.HasAttributes || xValue.Name.LocalName != "value") && !useAttribute) { returnVal = BusinessObjectHelper.CreateXObject(xmlField, value, useAttribute); } else if (!useAttribute) { returnVal = BusinessObjectHelper.CreateXObject(xmlField, xValue.Value, useAttribute); } else { returnVal = BusinessObjectHelper.CreateXObject(xmlField, xValue.ToString(SaveOptions.DisableFormatting), useAttribute); } } else if (typeof(IBusinessObject).IsAssignableFrom(type)) { if (!parentSelfOnlySerialization || !selfOnlySerialization) { IBusinessObject obj = (IBusinessObject)value; if (onlyIdForObjects) { returnVal = BusinessObjectHelper.CreateXObject(xmlField, obj.Id.Value.ToUpperString(), useAttribute); } else { returnVal = BusinessObjectHelper.CreateXObject(xmlField, obj.Serialize(selfOnlySerialization), useAttribute); } } else { return(null); } } else if (type.IsEnum) { returnVal = BusinessObjectHelper.CreateXObject(xmlField, (int)value, useAttribute); } else if (typeof(ISerializableBusinessObjectContainer).IsAssignableFrom(type)) { if (!parentSelfOnlySerialization && !selfOnlySerialization) { XElement xel = ((ISerializableBusinessObjectContainer)value).Serialize(); xel.Name = xmlField; returnVal = xel; } else { return(null); } } else { throw new InvalidOperationException("Unknown type to serialize"); } return(returnVal); }
public static void BindFinalValue(PropertyInfo property, object parentItem, object value, XObject sourceXObject, bool definition) { sourceXObject.AddAnnotation(value); Type propertyType = property.PropertyType; if (CommonUtility.IsContainerOf(typeof(ICollection<object>), propertyType) && propertyType.GetGenericArguments()[0].IsAssignableFrom(value.GetType())) { object collection = property.GetValue(parentItem, null); MethodInfo addMethod = collection.GetType().GetMethod("Add"); addMethod.Invoke(collection, new[] { value }); } else if (propertyType.IsAssignableFrom(value.GetType())) { property.SetValue(parentItem, value, null); } else { // TODO: Message.Error("No Binding Mechanism Worked"); } var mappingProvider = value as IXObjectMappingProvider; if (mappingProvider != null && definition) { mappingProvider.BoundXObject = new XObjectMapping(sourceXObject, property.Name); } }