Ejemplo n.º 1
0
 public void OlderRefNotEqualsNewerRef()
 {
     Ref older = new Ref(null);
     Ref newer = new Ref(null);
     Assert.IsFalse(older.Equals(newer));
     Assert.IsFalse(older == newer);
     Assert.IsTrue(older != newer);
 }
Ejemplo n.º 2
0
        private XmlQueryType FindFilterType(QilIterator variable, QilNode body)
        {
            XmlQueryType leftType;
            QilBinary    binary;

            if (body.XmlType.TypeCode == XmlTypeCode.None)
            {
                return(XmlQueryTypeFactory.None);
            }

            switch (body.NodeType)
            {
            case QilNodeType.False:
                return(XmlQueryTypeFactory.Empty);

            case QilNodeType.IsType:
                // If testing the type of "variable", then filter type can be restricted
                if (Ref.Equals(((QilTargetType)body).Source, variable))
                {
                    return(XmlQueryTypeFactory.AtMost(((QilTargetType)body).TargetType, variable.Binding.XmlType.Cardinality));
                }
                break;

            case QilNodeType.And:
                // Both And conditions can be used to restrict filter's type
                leftType = FindFilterType(variable, ((QilBinary)body).Left);
                if (leftType != null)
                {
                    return(leftType);
                }

                return(FindFilterType(variable, ((QilBinary)body).Right));

            case QilNodeType.Eq:
                // Restrict cardinality if position($iterator) = $pos is found
                binary = (QilBinary)body;
                if (binary.Left.NodeType == QilNodeType.PositionOf)
                {
                    if (Ref.Equals(((QilUnary)binary.Left).Child, variable))
                    {
                        return(XmlQueryTypeFactory.AtMost(variable.Binding.XmlType, XmlQueryCardinality.ZeroOrOne));
                    }
                }
                break;
            }

            return(null);
        }
        /// <summary>
        /// Bind to the specified MethodInfo.
        /// </summary>
        private void Bind(MethodInfo meth)
        {
            ParameterInfo[] paramInfo = meth.GetParameters();
            int             i;

            // Save the MethodInfo
            this.meth = meth;

            // Get the Clr type of each parameter
            this.argClrTypes = new Type[paramInfo.Length];
            for (i = 0; i < paramInfo.Length; i++)
            {
                this.argClrTypes[i] = GetClrType(paramInfo[i].ParameterType);
            }

            // Get the Clr type of the return value
            this.retClrType = GetClrType(this.meth.ReturnType);

            // Infer an Xml type for each Clr type
            this.argXmlTypes = new XmlQueryType[paramInfo.Length];
            for (i = 0; i < paramInfo.Length; i++)
            {
                this.argXmlTypes[i] = InferXmlType(this.argClrTypes[i]);

                if (this.namespaceUri.Length == 0)
                {
                    if (Ref.Equals(this.argXmlTypes[i], XmlQueryTypeFactory.NodeNotRtf))
                    {
                        this.argXmlTypes[i] = XmlQueryTypeFactory.Node;
                    }
                    else if (Ref.Equals(this.argXmlTypes[i], XmlQueryTypeFactory.NodeDodS))
                    {
                        this.argXmlTypes[i] = XmlQueryTypeFactory.NodeS;
                    }
                }
                else
                {
                    if (Ref.Equals(this.argXmlTypes[i], XmlQueryTypeFactory.NodeDodS))
                    {
                        this.argXmlTypes[i] = XmlQueryTypeFactory.NodeNotRtfS;
                    }
                }
            }

            // Infer an Xml type for the return Clr type
            this.retXmlType = InferXmlType(this.retClrType);
        }
Ejemplo n.º 4
0
        public void RDTest()
        {
            Ref <double> rd = Ref.Bind(0d);
            int          i  = 0;

            Assert.True(rd.Value == i);
            Assert.True(i == rd.Value);
            Assert.False(rd.RefValue == (object)i);
            Assert.False((object)i == rd.RefValue);
            Assert.False(rd == i);
            Assert.False(i == rd);

            Assert.False(rd.Value != i);
            Assert.False(i != rd.Value);
            Assert.True(rd.RefValue != (object)i);
            Assert.True((object)i != rd.RefValue);
            Assert.True(rd != i);
            Assert.True(i != rd);

            Assert.False(rd.Equals(i));
            Assert.False(i.Equals(rd));
        }
Ejemplo n.º 5
0
        public void RITest()
        {
            Ref <int> ri = Ref.Bind(0);
            int       i  = 0;

            Assert.True(ri.Value == i);
            Assert.True(i == ri.Value);
            Assert.False(ri.RefValue == (object)i);
            Assert.False((object)i == ri.RefValue);
            Assert.False(ri == i);
            Assert.False(i == ri);

            Assert.False(ri.Value != i);
            Assert.False(i != ri.Value);
            Assert.True(ri.RefValue != (object)i);
            Assert.True((object)i != ri.RefValue);
            Assert.True(ri != i);
            Assert.True(i != ri);

            Assert.True(ri.Equals(i));
            Assert.True(i.Equals(ri));
        }
        //-----------------------------------------------
        // QilVisitor overrides
        //-----------------------------------------------

        /// <summary>
        /// Visit all children of "parent", replacing each child with a copy of each child.
        /// </summary>
        protected override QilNode VisitChildren(QilNode parent)
        {
            XmlQueryType oldParentType = parent.XmlType;
            bool         recalcType    = false;

            // Visit children
            for (int i = 0; i < parent.Count; i++)
            {
                QilNode      oldChild = parent[i], newChild;
                XmlQueryType oldChildType = oldChild != null ? oldChild.XmlType : null;

                // Visit child
                if (IsReference(parent, i))
                {
                    newChild = VisitReference(oldChild);
                }
                else
                {
                    newChild = Visit(oldChild);
                }

                // Only replace child and recalculate type if oldChild != newChild or oldChild.XmlType != newChild.XmlType
                if (!Ref.Equals(oldChild, newChild) || (newChild != null && !Ref.Equals(oldChildType, newChild.XmlType)))
                {
                    recalcType = true;
                    parent[i]  = newChild;
                }
            }

            if (recalcType)
            {
                RecalculateType(parent, oldParentType);
            }

            return(parent);
        }
Ejemplo n.º 7
0
 public override bool Equals(VSMXBaseObject value)
 {
     return(Ref.Equals(value));
 }
Ejemplo n.º 8
0
 public void RefEqualsSelf()
 {
     #pragma warning disable 1718
     Ref r = new Ref(null);
     Assert.IsTrue(r.Equals(r));
     Assert.IsTrue(r == r);
     Assert.IsFalse(r != r);
     #pragma warning restore 1718
 }
Ejemplo n.º 9
0
 public void RefEqualsNull()
 {
     Ref r = new Ref(null);
     Ref other = null;
     Assert.IsFalse(r.Equals(other));
     Assert.IsFalse(r == other);
     Assert.IsTrue(r != other);
 }