Esempio n. 1
0
        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));
        }
Esempio n. 2
0
        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)));
        }
Esempio n. 3
0
        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>());
        }
Esempio n. 4
0
        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)));
        }
Esempio n. 5
0
        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)));
        }
Esempio n. 6
0
        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)));
        }
Esempio n. 7
0
        }         // 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
Esempio n. 8
0
        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)));
        }
Esempio n. 9
0
        /// <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);
        }
Esempio n. 10
0
        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));
        }
Esempio n. 11
0
        public static TextRange GetTextRange(this XObject attribute)
        {
            var saa = attribute.Annotation <XmlAttributeAnnotation>();

            if (saa == null)
            {
                return(null);
            }
            return(saa.TextRange);
        }
Esempio n. 12
0
        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;
        }
Esempio n. 13
0
        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));
        }
Esempio n. 14
0
 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);
     }
 }
Esempio n. 17
0
        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);
        }
Esempio n. 18
0
        /// <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);
        }
Esempio n. 19
0
        /// <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);
        }
Esempio n. 20
0
        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;
        }
Esempio n. 21
0
        /// <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);
        }
Esempio n. 22
0
        /// <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);
        }
Esempio n. 23
0
        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);
        }
Esempio n. 24
0
        /// <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);
        }
Esempio n. 25
0
        /// <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);
        }
Esempio n. 26
0
        /// <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);
        }
Esempio n. 27
0
        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);
        }
Esempio n. 28
0
        /// <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);
        }
Esempio n. 29
0
        /// <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);
        }
Esempio n. 30
0
        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);
        }
Esempio n. 31
0
 public override bool IsMatch(XObject obj)
 {
     return obj.Annotation<RepeatItemState>() != null;
 }
Esempio n. 32
0
 public bool IsMatch(XObject obj)
 {
     return obj.Annotation<IncludeScopeAnnotation>() != null;
 }
Esempio n. 33
0
 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));
 }
Esempio n. 34
0
 public void GetOneNull(XObject xo)
 {
     Assert.Throws <ArgumentNullException>("type", () => xo.Annotation(null));
     Assert.Throws <ArgumentNullException>("type", () => xo.Annotation(null));
 }
Esempio n. 35
0
 /// <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>());
 }