public void EnumerateAnnotationsWithoutAdding(XObject xo) { Assert.Null(xo.Annotation(typeof(object))); Assert.Null(xo.Annotation <object>()); Assert.Equal(expected: 0, actual: CountAnnotations <object>(xo)); Assert.Equal(expected: 0, actual: CountAnnotations <string>(xo)); }
public void AddIntAnnotation(XObject xo) { const int expected = 123456; xo.AddAnnotation(expected); ValidateAnnotations(xo, new object[] { expected }); Assert.Equal(expected, xo.Annotation <object>()); Assert.Equal(expected, (int)xo.Annotation(typeof(int))); Assert.Equal(expected, xo.Annotation(typeof(object))); }
public void AddStringAnnotation(XObject xo) { const string expected = "test string"; xo.AddAnnotation(expected); ValidateAnnotations(xo, new string[] { expected }); Assert.Equal(expected, xo.Annotation <string>()); Assert.Equal(expected, (string)xo.Annotation(typeof(string))); Assert.Equal(expected, xo.Annotation(typeof(object))); Assert.Equal(expected, xo.Annotation <object>()); }
public void AddGenericAnnotation(XObject xo) { Dictionary <string, string> d = new Dictionary <string, string>(); xo.AddAnnotation(d); ValidateAnnotations(xo, new Dictionary <string, string>[] { d }); Assert.Equal(d, xo.Annotation <Dictionary <string, string> >()); Assert.Equal(d, (Dictionary <string, string>)xo.Annotation(typeof(Dictionary <string, string>))); Assert.Equal(d, xo.Annotation <object>()); Assert.Equal(d, xo.Annotation(typeof(object))); }
public void AddIntAndStringAnnotation(XObject xo) { const string expectedStr = "<!@@63784sgdh111>"; const int expectedNum = 123456; xo.AddAnnotation(expectedStr); xo.AddAnnotation(expectedNum); ValidateAnnotations(xo, new object[] { expectedStr, expectedNum }); ValidateAnnotations(xo, new string[] { expectedStr }); Assert.Equal(expectedNum, (int)xo.Annotation(typeof(int))); Assert.Equal(expectedStr, xo.Annotation <string>()); Assert.Equal(expectedStr, (string)xo.Annotation(typeof(string))); }
public void AddInheritedAnnotation(XObject xo) { A a = new A(); B b = new B(); xo.AddAnnotation(a); xo.AddAnnotation(b); ValidateAnnotations(xo, new A[] { a, b }); ValidateAnnotations(xo, new B[] { b }); Assert.Equal(b, xo.Annotation <B>()); Assert.Equal(b, (B)xo.Annotation(typeof(B))); Assert.Equal(a, xo.Annotation <A>()); Assert.Equal(a, (A)xo.Annotation(typeof(A))); }
} // func XAttributeCreate /// <summary>Sucht die angegebene Annotation.</summary> /// <param name="x"></param> /// <param name="typeAnnotation"></param> /// <returns></returns> public static object FindAnnotation(this XObject x, Type typeAnnotation) { if (typeAnnotation == null || x == null) { return(null); } while (x != null) { object r = x.Annotation(typeAnnotation); if (r != null) { return(r); } if (x.Parent == null) { if (x is XDocument) { break; } else { x = x.Document; } } else { x = x.Parent; } } return(null); } // func FindAnnotation
public void AddAnnotationWithSameClassNameButDifferentNamespace(XObject xo) { DifferentNamespace.A a1 = new DifferentNamespace.A(); A a2 = new A(); xo.AddAnnotation(a1); xo.AddAnnotation(a2); ValidateAnnotations(xo, new DifferentNamespace.A[] { a1 }); ValidateAnnotations(xo, new A[] { a2 }); Assert.Equal(a1, xo.Annotation <DifferentNamespace.A>()); Assert.Equal(a1, (DifferentNamespace.A)xo.Annotation(typeof(DifferentNamespace.A))); Assert.Equal(a2, xo.Annotation <A>()); Assert.Equal(a2, (A)xo.Annotation(typeof(A))); }
/// <summary> /// Gets the first annotation object of the specified type, or creates a new one. /// </summary> /// <param name="self"></param> /// <param name="type"></param> /// <param name="create"></param> /// <returns></returns> public static object GetOrAddAnnotation(this XObject self, Type type, Func <object> create) { if (self == null) { ThrowHelper.ThrowArgumentNullException(nameof(self)); } if (type == null) { ThrowHelper.ThrowArgumentNullException(nameof(type)); } if (create == null) { ThrowHelper.ThrowArgumentNullException(nameof(create)); } var value = self.Annotation(type); if (value == null) { self.AddAnnotation(value = create()); } return(value); }
public void RemoveAnnotationWithSameClassNameButDifferentNamespace(XObject xo) { DifferentNamespace.A a1 = new DifferentNamespace.A(); A a2 = new A(); xo.AddAnnotation(a1); xo.AddAnnotation(a2); xo.RemoveAnnotations <DifferentNamespace.A>(); Assert.Equal(expected: 0, actual: CountAnnotations <DifferentNamespace.A>(xo)); ValidateAnnotations <A>(xo, new A[] { a2 }); Assert.Equal(a2, xo.Annotation <A>()); Assert.Equal(a2, (A)xo.Annotation(typeof(A))); xo.RemoveAnnotations(typeof(A)); Assert.Equal(expected: 0, actual: CountAnnotations <A>(xo)); }
public static TextRange GetTextRange(this XObject attribute) { var saa = attribute.Annotation <XmlAttributeAnnotation>(); if (saa == null) { return(null); } return(saa.TextRange); }
public static void SetTextRange(this XObject attribute, TextRange textRange) { var saa = attribute.Annotation <XmlAttributeAnnotation>(); if (saa == null) { saa = new XmlAttributeAnnotation(); attribute.AddAnnotation(saa); } saa.TextRange = textRange; }
public void RemoveInheritedAnnotation(XObject xo) { A a = new A(); B b = new B(); xo.AddAnnotation(a); xo.AddAnnotation(b); xo.RemoveAnnotations <B>(); ValidateAnnotations(xo, new A[] { a }); Assert.Equal(a, xo.Annotation <A>()); Assert.Equal(a, (A)xo.Annotation(typeof(A))); Assert.Equal(a, xo.Annotation <object>()); Assert.Equal(a, xo.Annotation(typeof(object))); Assert.Equal(0, CountAnnotations <B>(xo)); xo.RemoveAnnotations(typeof(A)); Assert.Equal(0, CountAnnotations <A>(xo)); }
internal static void SetModelItem(XObject xobject, EFObject efobject) { if (xobject.Annotation <EFObject>() == null) { xobject.AddAnnotation(efobject); } else { xobject.RemoveAnnotations <EFObject>(); xobject.AddAnnotation(efobject); } }
internal static EFObject GetModelItem(XObject xobject) { var mia = xobject.Annotation<EFObject>(); while (mia == null && xobject.Parent != null) { mia = xobject.Parent.Annotation<EFObject>(); xobject = xobject.Parent; } return mia; }
internal static void SetModelItem(XObject xobject, EFObject efobject) { if (xobject.Annotation<EFObject>() == null) { xobject.AddAnnotation(efobject); } else { xobject.RemoveAnnotations<EFObject>(); xobject.AddAnnotation(efobject); } }
internal static EFObject GetModelItem(XObject xobject) { var mia = xobject.Annotation <EFObject>(); while (mia == null && xobject.Parent != null) { mia = xobject.Parent.Annotation <EFObject>(); xobject = xobject.Parent; } return(mia); }
/// <summary> /// Gets the first annotation object of the specified type, or creates a new one. /// </summary> /// <param name="self"></param> /// <param name="type"></param> /// <returns></returns> public static object AnnotationOrCreate(this XObject self, Type type) { Contract.Requires <ArgumentNullException>(self != null); Contract.Requires <ArgumentNullException>(type != null); var value = self.Annotation(type); if (value == null) { self.AddAnnotation(value = Activator.CreateInstance(type)); } return(value); }
/// <summary> /// Gets the first annotation object of the specified type, or creates a new one. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="self"></param> /// <returns></returns> public static T AnnotationOrCreate <T>(this XObject self) where T : class, new() { Contract.Requires <ArgumentNullException>(self != null); var value = self.Annotation <T>(); if (value == null) { self.AddAnnotation(value = new T()); } return(value); }
internal static long GetNextIdentity(XObject element) { var annotation = element.Annotation<ModelAnnotation>(); if (annotation == null) { annotation = new ModelAnnotation(); element.AddAnnotation(annotation); } var nextIdentity = annotation.NextIdentity; annotation.NextIdentity = ++nextIdentity; return nextIdentity; }
/// <summary> /// Gets the first annotation object of the specified type, or creates a new one. /// </summary> /// <param name="self"></param> /// <param name="type"></param> /// <param name="create"></param> /// <returns></returns> public static object AnnotationOrCreate(this XObject self, Type type, Func <object> create) { Contract.Requires <ArgumentNullException>(self != null); Contract.Requires <ArgumentNullException>(type != null); Contract.Requires <ArgumentNullException>(create != null); var value = self.Annotation(type); if (value == null) { self.AddAnnotation(value = create()); } return(value); }
/// <summary> /// Gets the first annotation object of the specified type, or creates a new one. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="self"></param> /// <returns></returns> public static T AnnotationOrCreate <T>(this XObject self, Func <T> create) where T : class { Contract.Requires <ArgumentNullException>(self != null); Contract.Requires <ArgumentNullException>(create != null); var value = self.Annotation <T>(); if (value == null) { self.AddAnnotation(value = create()); } return(value); }
internal static long GetNextIdentity(XObject element) { var annotation = element.Annotation <ModelAnnotation>(); if (annotation == null) { annotation = new ModelAnnotation(); element.AddAnnotation(annotation); } var nextIdentity = annotation.NextIdentity; annotation.NextIdentity = ++nextIdentity; return(nextIdentity); }
/// <summary> /// Gets the first annotation object of the specified type, or creates a new one. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="self"></param> /// <returns></returns> public static T GetOrAddAnnotation <T>(this XObject self) where T : class, new() { if (self == null) { ThrowHelper.ThrowArgumentNullException(nameof(self)); } var value = self.Annotation <T>(); if (value == null) { self.AddAnnotation(value = new T()); } return(value); }
/// <summary> /// Gets the BaseUri of the <see cref="XObject" />. /// </summary> /// <param name="self"></param> /// <returns></returns> public static Uri GetXmlBaseUri(this XObject self) { if (self == null) { ThrowHelper.ThrowArgumentNullException(nameof(self)); } var baseUriAnno = self.Annotation <XmlBaseUriAnnotation>(); if (baseUriAnno?.BaseUri != null) { return(baseUriAnno.BaseUri); } var element = self as XElement; return(element != null?GetXmlBaseUri(element) : null); }
/// <summary> /// Gets the BaseUri of the <see cref="XObject"/>. /// </summary> /// <param name="self"></param> /// <returns></returns> public static Uri GetBaseUri(this XObject self) { Contract.Requires <ArgumentNullException>(self != null); var baseUriAnno = self.Annotation <BaseUriAnnotation>(); if (baseUriAnno != null && baseUriAnno.BaseUri != null) { return(baseUriAnno.BaseUri); } if (self is XElement) { return(GetBaseUri((XElement)self)); } return(null); }
private void ReplaceSchemaInfo(XObject o, XmlSchemaInfo schemaInfo) { schemaInfos ??= new Dictionary <XmlSchemaInfo, XmlSchemaInfo>(new XmlSchemaInfoEqualityComparer()); XmlSchemaInfo?si = o.Annotation <XmlSchemaInfo>(); if (si != null) { if (!schemaInfos.ContainsKey(si)) { schemaInfos.Add(si, si); } o.RemoveAnnotations <XmlSchemaInfo>(); } if (!schemaInfos.TryGetValue(schemaInfo, out si)) { si = schemaInfo; schemaInfos.Add(si, si); } o.AddAnnotation(si); }
/// <summary> /// Gets the first annotation object of the specified type, or creates a new one. /// </summary> /// <param name="self"></param> /// <param name="type"></param> /// <returns></returns> public static object GetOrAddAnnotation(this XObject self, Type type) { if (self == null) { ThrowHelper.ThrowArgumentNullException(nameof(self)); } if (type == null) { ThrowHelper.ThrowArgumentNullException(nameof(type)); } var value = self.Annotation(type); if (value == null) { self.AddAnnotation(value = Activator.CreateInstance(type)); } return(value); }
/// <summary> /// Gets the first annotation object of the specified type, or creates a new one. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="self"></param> /// <param name="create"></param> /// <returns></returns> public static T GetOrAddAnnotation <T>(this XObject self, Func <T> create) where T : class { if (self == null) { ThrowHelper.ThrowArgumentNullException(nameof(self)); } if (create == null) { ThrowHelper.ThrowArgumentNullException(nameof(create)); } var value = self.Annotation <T>(); if (value == null) { self.AddAnnotation(value = create()); } return(value); }
private void ReplaceSchemaInfo(XObject o, XmlSchemaInfo schemaInfo) { if (this.schemaInfos == null) { this.schemaInfos = new Dictionary <XmlSchemaInfo, XmlSchemaInfo>(new XmlSchemaInfoEqualityComparer()); } XmlSchemaInfo key = o.Annotation <XmlSchemaInfo>(); if (key != null) { if (!this.schemaInfos.ContainsKey(key)) { this.schemaInfos.Add(key, key); } o.RemoveAnnotations <XmlSchemaInfo>(); } if (!this.schemaInfos.TryGetValue(schemaInfo, out key)) { key = schemaInfo; this.schemaInfos.Add(key, key); } o.AddAnnotation(key); }
public override bool IsMatch(XObject obj) { return obj.Annotation<RepeatItemState>() != null; }
public bool IsMatch(XObject obj) { return obj.Annotation<IncludeScopeAnnotation>() != null; }
public void AddNullString(XObject xo) { Assert.Throws <ArgumentNullException>("annotation", () => xo.AddAnnotation((string)null)); Assert.Null(xo.Annotation <object>()); Assert.Throws <ArgumentNullException>("annotation", () => xo.AddAnnotation((string)null)); }
public void GetOneNull(XObject xo) { Assert.Throws <ArgumentNullException>("type", () => xo.Annotation(null)); Assert.Throws <ArgumentNullException>("type", () => xo.Annotation(null)); }
/// <summary> /// Get the source line information for the current element. Typically this information /// is set by the precompiler for each element that it encounters. /// </summary> /// <param name="node">Element to get source line information for.</param> /// <returns> /// The source line number used to author the element being processed or /// null if the preprocessor did not process the element or the node is /// not an element. /// </returns> public static SourceLineNumber GetFromXAnnotation(XObject node) { return(node.Annotation <SourceLineNumber>()); }