Example #1
0
        public void FromName_should_create_from_type_and_qualified_name()
        {
            Template <StatusBuilder> a = Template.FromName <StatusBuilder>(NamespaceUri.Parse("http://ns.example.com/2012").GetName("A"));
            var sb = a.CreateInstance();

            Assert.Equal(4, sb.ErrorCode);
        }
Example #2
0
        public void GetTemplateNames_should_obtain_names_nominal()
        {
            IEnumerable <QualifiedName> names = App.GetTemplateNames(typeof(StatusBuilder));

            Assert.Contains(NamespaceUri.Parse("http://ns.example.com/2012") + "A", names);
            Assert.Contains(NamespaceUri.Parse("http://ns.example.com/2012") + "B", names);
        }
Example #3
0
        public void GetTemplateName_should_be_reflexive_from_FromName()
        {
            var name = NamespaceUri.Parse("http://ns.example.com/2012").GetName("A");
            Template <StatusBuilder> a = Template.FromName <StatusBuilder>(name);

            Assert.Equal(name, Template.GetTemplateName(a));
        }
Example #4
0
 public override int GetHashCode()
 {
     unchecked
     {
         return(((NamespaceUri?.GetHashCode() ?? 0) * 397) ^ (Version != null ? Version.GetHashCode() : 0));
     }
 }
        // FDG ***** DO override GetHashCode whenever you override Equals.

        /// <summary>
        /// Gets the hash code for this instance of an OpenXmlAttribute structure.
        /// </summary>
        /// <returns>The hash code for this instance of an OpenXmlAttribute structure.</returns>
        public override int GetHashCode()
        {
            int hashCode = 0;

            if (LocalName != null)
            {
                hashCode ^= LocalName.GetHashCode();
            }

            if (NamespaceUri != null)
            {
                hashCode ^= NamespaceUri.GetHashCode();
            }

            if (Prefix != null)
            {
                hashCode ^= Prefix.GetHashCode();
            }

            if (Value != null)
            {
                hashCode ^= Value.GetHashCode();
            }

            return(hashCode);
        }
Example #6
0
        public void GetXmlNamespace_should_get_xmlns_from_clrnamespaces()
        {
            AssemblyInfo ai = AssemblyInfo.GetAssemblyInfo(typeof(TypeReference).GetTypeInfo().Assembly);

            Assert.Equal(NamespaceUri.Parse(Xmlns.Core2008), ai.GetXmlNamespace("Carbonfrost.Commons.Core"));
            Assert.Equal(NamespaceUri.Parse(Xmlns.Core2008), ai.GetXmlNamespace("Carbonfrost.Commons.Core.Runtime"));
        }
        public void GetProvider_gets_provider_names_by_qualified_name()
        {
            var name = NamespaceUri.Create(Xmlns.Core2008) + "properties";
            var cs1  = App.GetProvider <StreamingSource>(name);

            Assert.Same(StreamingSource.Properties, cs1);
        }
Example #8
0
        public void ChangeNamespace_should_change_nominal()
        {
            QualifiedName n  = QualifiedName.Create(NamespaceUri.Default, "default");
            NamespaceUri  nu = NamespaceUri.Create("https://example.com");

            n = n.ChangeNamespace(nu);
            Assert.Same(nu, n.Namespace);
        }
Example #9
0
        public void XmlNamespaces_should_get_known_namespaces()
        {
            Assembly a    = typeof(TypeReference).GetTypeInfo().Assembly;
            var      info = AssemblyInfo.GetAssemblyInfo(a);

            Assert.Equal(new [] {
                NamespaceUri.Parse(Xmlns.Core2008)
            }, info.XmlNamespaces.ToArray());
        }
Example #10
0
        public void GetXmlNamespaces_should_get_clr_namespaces_from_xmlns()
        {
            AssemblyInfo ai  = AssemblyInfo.GetAssemblyInfo(typeof(TypeReference).GetTypeInfo().Assembly);
            var          all = ai.GetClrNamespaces(NamespaceUri.Parse(Xmlns.Core2008));

            Assert.Contains("Carbonfrost.Commons.Core", all);
            Assert.Contains("Carbonfrost.Commons.Core.Runtime", all);

            Assert.DoesNotContain("Carbonfrost.Commons.ComponentModel.Annotations", all);
        }
        public override object ConvertFromString(string text, Type destinationType, IValueSerializerContext context)
        {
            var s = text;

            if (s != null)
            {
                return(NamespaceUri.Parse(s));
            }

            return(base.ConvertFromString(text, destinationType, context));
        }
Example #12
0
        public override Boolean Equals(INode otherNode)
        {
            var otherElement = otherNode as IElement;

            if (otherElement != null)
            {
                return(NamespaceUri.Is(otherElement.NamespaceUri) &&
                       _attributes.AreEqual(otherElement.Attributes) &&
                       base.Equals(otherNode));
            }

            return(false);
        }
Example #13
0
        public static IEnumerable <Type> GetTypesByNamespaceUri(
            this Assembly assembly, NamespaceUri namespaceUri)
        {
            if (assembly == null)
            {
                throw new ArgumentNullException(nameof(assembly));
            }
            if (namespaceUri == null)
            {
                throw new ArgumentNullException(nameof(namespaceUri));
            }

            return(assembly.GetTypesHelper().Select(t => t.AsType()).Where(t => t.GetQualifiedName().Namespace == namespaceUri));
        }
Example #14
0
        public void Equals_normalizes_in_comparisons(string x, string y)
        {
            Assert.Equal(NamespaceUri.Create(x), NamespaceUri.Create(y));

            Assert.True(NamespaceUri.Equals(
                            NamespaceUri.Create(x),
                            NamespaceUri.Create(y),
                            NamespaceUriComparison.Default
                            ));

            Assert.False(NamespaceUri.Equals(
                             NamespaceUri.Create(x),
                             NamespaceUri.Create(y),
                             NamespaceUriComparison.Ordinal
                             ));
        }
Example #15
0
        public static QualifiedName GetQualifiedName(this Type type)
        {
            if (type == null)
            {
                throw new ArgumentNullException(nameof(type));
            }
            var tt = type.GetTypeInfo();

            if (tt.IsGenericParameter || (tt.IsGenericType && !tt.IsGenericTypeDefinition))
            {
                throw RuntimeFailure.QualifiedNameCannotBeGeneratedFromConstructed("type");
            }

            AssemblyInfo ai    = AssemblyInfo.GetAssemblyInfo(tt.Assembly);
            NamespaceUri xmlns = ai.GetXmlNamespace(tt.Namespace);

            return(xmlns + QualName(type));
        }
        private static QualifiedName ImpliedName(PropertyTreeNavigator nav, PropertyTreeMetaObject target)
        {
            QualifiedName qualifiedName = nav.QualifiedName;

            if (nav.IsExpressNamespace)
            {
                return(qualifiedName);
            }

            NamespaceUri impliedNS = Utility.GetXmlnsNamespaceSafe(target.ComponentType);

            if (impliedNS == null)
            {
                return(qualifiedName);
            }
            else
            {
                return(qualifiedName.ChangeNamespace(impliedNS));
            }
        }
Example #17
0
        private ISparqlExpression BuildSparqlFilter(SingleValueNode filterNode, string suffix = "")
        {
            NodeFactory nodeFactory = new NodeFactory();

            if (filterNode.GetType() == typeof(SingleValueFunctionCallNode))
            {
                return(BuildFunctionExpression(filterNode as SingleValueFunctionCallNode));
            }
            else if (filterNode.GetType() == typeof(SingleValuePropertyAccessNode))
            {
                return(new VariableTerm($"?{(filterNode as SingleValuePropertyAccessNode).Property.Name}{suffix}"));
            }
            else if (filterNode.GetType() == typeof(ConstantNode))
            {
                return(new ConstantTerm(CreateLiteralNode(filterNode as ConstantNode)));
            }
            else if (filterNode.GetType() == typeof(ConvertNode))
            {
                var convert = filterNode as ConvertNode;
                if (convert.Source is SingleValueFunctionCallNode)
                {
                    return(BuildSparqlFilter(convert.Source as SingleValueFunctionCallNode, suffix));
                }
                else if (convert.Source is ConstantNode)
                {
                    return(new ConstantTerm(CreateLiteralNode(convert.Source as ConstantNode)));
                }
                else if (convert.Source is SingleValuePropertyAccessNode)
                {
                    var varName = (convert.Source as SingleValuePropertyAccessNode).Property.Name;
                    if (varName.ToLower() == "localid")
                    {
                        var node = LiteralExtensions.ToLiteral(NamespaceUri.ToString().Length + 1, nodeFactory);
                        varName = EdmNodeList[EdmNodeList.Count - 1].Name;
                        return((new UnaryExpressionFilter(
                                    new SubStrFunction(new StrFunction(new VariableTerm($"?{varName}{suffix}")),
                                                       (new ConstantTerm(node))))).Expression);
                    }
                    else
                    {
                        return(new VariableTerm($"?{varName}{suffix}"));
                    }
                }
            }
            else if (filterNode.GetType() == typeof(BinaryOperatorNode))
            {
                var binaryOperator = filterNode as BinaryOperatorNode;
                var left           = BuildSparqlFilter(binaryOperator.Left, suffix);
                var right          = BuildSparqlFilter(binaryOperator.Right, suffix);

                if (binaryOperator.OperatorKind == BinaryOperatorKind.And)
                {
                    return(new AndExpression(left, right));
                }
                else if (binaryOperator.OperatorKind == BinaryOperatorKind.Or)
                {
                    return(new OrExpression(left, right));
                }
                else if (binaryOperator.OperatorKind == BinaryOperatorKind.Equal)
                {
                    return(new EqualsExpression(left, right));
                }
                else if (binaryOperator.OperatorKind == BinaryOperatorKind.NotEqual)
                {
                    return(new NotEqualsExpression(left, right));
                }
                else if (binaryOperator.OperatorKind == BinaryOperatorKind.GreaterThan)
                {
                    return(new GreaterThanExpression(left, right));
                }
                else if (binaryOperator.OperatorKind == BinaryOperatorKind.GreaterThanOrEqual)
                {
                    return(new GreaterThanOrEqualToExpression(left, right));
                }
                else if (binaryOperator.OperatorKind == BinaryOperatorKind.LessThan)
                {
                    return(new LessThanExpression(left, right));
                }
                else if (binaryOperator.OperatorKind == BinaryOperatorKind.LessThanOrEqual)
                {
                    return(new LessThanOrEqualToExpression(left, right));
                }
                else if (binaryOperator.OperatorKind == BinaryOperatorKind.Add)
                {
                    return(new AdditionExpression(left, right));
                }
                else if (binaryOperator.OperatorKind == BinaryOperatorKind.Subtract)
                {
                    return(new SubtractionExpression(left, right));
                }
                else if (binaryOperator.OperatorKind == BinaryOperatorKind.Divide)
                {
                    return(new DivisionExpression(left, right));
                }
                else if (binaryOperator.OperatorKind == BinaryOperatorKind.Multiply)
                {
                    return(new MultiplicationExpression(left, right));
                }
            }
            else if (filterNode.GetType() == typeof(UnaryOperatorNode))
            {
                var unaryOperator = filterNode as UnaryOperatorNode;
                if (unaryOperator.OperatorKind == UnaryOperatorKind.Not)
                {
                    return(new NotEqualsExpression(BuildSparqlFilter(unaryOperator.Operand, suffix),
                                                   new ConstantTerm(LiteralExtensions.ToLiteral(true, nodeFactory))));
                }
            }
            return(null);
        }
Example #18
0
		public override int GetHashCode ()
		{
			return (NamespaceUri?.GetHashCode () ?? 0)
				+ (TypeName?.GetHashCode () ?? 0);
		}
Example #19
0
 public override int GetHashCode()
 {
     return((NamespaceUri?.GetHashCode() ?? 0)
            + (LocalName?.GetHashCode() ?? 0));
 }
Example #20
0
        public void FromName_test_known_qualified_name(string name)
        {
            var qn = NamespaceUri.Create(Xmlns.Core2008) + name;

            Assert.NotNull(StreamingSource.FromName(qn));
        }
Example #21
0
 public override int GetHashCode()
 {
     return(LocalName.GetHashCode() ^ NamespaceUri.GetHashCode() << 8);
 }
Example #22
0
 public override int GetHashCode()
 {
     return(NamespaceUri.GetHashCode() + Name.GetHashCode());
 }
Example #23
0
 public override int GetHashCode()
 {
     unchecked {
         return(9 * NamespaceUri.GetHashCode());
     }
 }
Example #24
0
 internal static string GetDefaultPrefix(NamespaceUri ns,
                                         Assembly assembly)
 {
     return(AssemblyInfo.GetAssemblyInfo(assembly)
            .GetXmlNamespacePrefix(ns));
 }