コード例 #1
0
 public MultisetField(string name, IonValue value)
 {
     Debug.Assert(name != null);
     _name  = name;
     _value = value;
     Count  = 0;
 }
コード例 #2
0
ファイル: IonInt.cs プロジェクト: truongle2211/IonDotnet
        public override bool IsEquivalentTo(IonValue other)
        {
            if (!(other is IonInt oInt))
            {
                return(false);
            }
            if (NullFlagOn())
            {
                return(oInt.IsNull);
            }
            if (oInt.IsNull)
            {
                return(false);
            }
            if (oInt.IntegerSize != IntegerSize)
            {
                return(false);
            }
            switch (IntegerSize)
            {
            case IntegerSize.Int:
                return(IntValue == oInt.IntValue);

            case IntegerSize.Long:
                return(LongValue == oInt.LongValue);

            case IntegerSize.BigInteger:
                return(BigIntegerValue == oInt.BigIntegerValue);

            default:
                return(false);
            }
        }
コード例 #3
0
ファイル: IonFloat.cs プロジェクト: dhhoang/IonDotnet
        public override bool IsEquivalentTo(IonValue other)
        {
            if (!base.IsEquivalentTo(other))
            {
                return(false);
            }

            var oFloat = (IonFloat)other;

            if (NullFlagOn())
            {
                return(oFloat.IsNull);
            }
            if (oFloat.IsNull)
            {
                return(false);
            }

            if (PrivateHelper.IsNegativeZero(_d) ^ PrivateHelper.IsNegativeZero(oFloat._d))
            {
                return(false);
            }

            return(EqualityComparer <double> .Default.Equals(oFloat.Value, Value));
        }
コード例 #4
0
        /// <inheritdoc />
        /// <remarks>
        /// Struct equivalence is an expensive operation.
        /// </remarks>
        public override bool IsEquivalentTo(IonValue other)
        {
            if (!(other is IonStruct otherStruct))
            {
                return(false);
            }
            if (NullFlagOn())
            {
                return(other.IsNull);
            }
            if (other.IsNull || otherStruct.Count != Count)
            {
                return(false);
            }

            if (_values.Count != otherStruct._values.Count)
            {
                return(false);
            }

            var multiset = ToMultiset();

            foreach (var v2 in otherStruct._values)
            {
                var field = new MultisetField(v2.FieldNameSymbol.Text, v2);
                if (!multiset.TryGetValue(field, out var mapped) || mapped.Count == 0)
                {
                    return(false);
                }
                mapped.Count--;
            }

            return(true);
        }
コード例 #5
0
ファイル: IonDecimal.cs プロジェクト: dhhoang/IonDotnet
        public override bool IsEquivalentTo(IonValue other)
        {
            if (!base.IsEquivalentTo(other))
            {
                return(false);
            }

            var otherDec = (IonDecimal)other;

            if (NullFlagOn())
            {
                return(otherDec.IsNull);
            }
            if (other.IsNull)
            {
                return(false);
            }

            if (BigDecimalValue.IsNegativeZero ^ otherDec.BigDecimalValue.IsNegativeZero)
            {
                return(false);
            }

            if (otherDec.BigDecimalValue.Scale > 0 || BigDecimalValue.Scale > 0)
            {
                //precision matters, make sure that this has the same precision
                return(BigDecimalValue.Scale == otherDec.BigDecimalValue.Scale &&
                       BigDecimalValue.IntVal == otherDec.BigDecimalValue.IntVal);
            }

            //this only compares values
            return(BigDecimalValue == otherDec.BigDecimalValue);
        }
コード例 #6
0
ファイル: IonStruct.cs プロジェクト: dhhoang/IonDotnet
 public MultisetField(SymbolToken name, IonValue value)
 {
     Debug.Assert(name != null);
     _name  = name;
     _value = value;
     Count  = 0;
 }
コード例 #7
0
ファイル: IonValue.cs プロジェクト: dhhoang/IonDotnet
        /// <summary>
        /// Returns true if this value is equivalent to the other, false otherwise.
        /// </summary>
        /// <param name="other">The other value.</param>
        /// <remarks>
        /// Equivalency is determined by whether the <see cref="IonValue"/> objects has the same annotations,
        /// hold equal values, or in the case of container, they contain equivalent sets of children.
        /// </remarks>
        public virtual bool IsEquivalentTo(IonValue other)
        {
            if (other == null || Type != other.Type)
            {
                return(false);
            }

            var otherAnnotations = other._annotations;

            if (_annotations == null)
            {
                return(otherAnnotations == null || otherAnnotations.Count == 0);
            }

            if (otherAnnotations == null || otherAnnotations.Count != _annotations.Count)
            {
                return(false);
            }

            for (int i = 0, l = _annotations.Count; i < l; i++)
            {
                if (!_annotations[i].IsEquivalentTo(otherAnnotations[i]))
                {
                    return(false);
                }
            }

            return(true);
        }
コード例 #8
0
ファイル: IonString.cs プロジェクト: truongle2211/IonDotnet
 public override bool IsEquivalentTo(IonValue other)
 {
     if (!(other is IonString otherString))
     {
         return(false);
     }
     return(StringVal == otherString.StringVal);
 }
コード例 #9
0
ファイル: IonStruct.cs プロジェクト: dhhoang/IonDotnet
        public override bool Contains(IonValue item)
        {
            if (NullFlagOn() || item is null)
            {
                return(false);
            }

            Debug.Assert(_values != null);
            return(item.Container == this);
        }
コード例 #10
0
 public override bool IsEquivalentTo(IonValue other)
 {
     if (!(other is IonBlob otherBlob))
     {
         return(false);
     }
     if (NullFlagOn())
     {
         return(otherBlob.IsNull);
     }
     return(!otherBlob.IsNull && otherBlob.Bytes().SequenceEqual(Bytes()));
 }
コード例 #11
0
ファイル: IonDecimal.cs プロジェクト: truongle2211/IonDotnet
 public override bool IsEquivalentTo(IonValue other)
 {
     if (!(other is IonDecimal otherDec))
     {
         return(false);
     }
     if (NullFlagOn())
     {
         return(otherDec.IsNull);
     }
     return(!otherDec.IsNull && otherDec.DecimalValue == DecimalValue);
 }
コード例 #12
0
        public override bool IsEquivalentTo(IonValue other)
        {
            if (!(other is IonTimestamp oTimestamp))
            {
                return(false);
            }
            if (NullFlagOn())
            {
                return(other.IsNull);
            }

            return(!other.IsNull && _timestamp == oTimestamp._timestamp);
        }
コード例 #13
0
        public override bool IsEquivalentTo(IonValue other)
        {
            if (!(other is IonFloat oFloat))
            {
                return(false);
            }

            if (NullFlagOn())
            {
                return(oFloat.IsNull);
            }

            return(!oFloat.IsNull && EqualityComparer <double> .Default.Equals(oFloat.Value, Value));
        }
コード例 #14
0
ファイル: IonSymbol.cs プロジェクト: truongle2211/IonDotnet
        public override bool IsEquivalentTo(IonValue other)
        {
            if (!(other is IonSymbol oSymbol))
            {
                return(false);
            }

            if (NullFlagOn())
            {
                return(oSymbol.IsNull);
            }

            return(!oSymbol.IsNull && oSymbol.StringVal == StringValue);
        }
コード例 #15
0
        public override bool IsEquivalentTo(IonValue other)
        {
            if (!(other is IonBool otherBool))
            {
                return(false);
            }

            if (NullFlagOn())
            {
                return(otherBool.IsNull);
            }

            return(!otherBool.IsNull && otherBool.Value == Value);
        }
コード例 #16
0
        public override bool IsEquivalentTo(IonValue other)
        {
            if (!base.IsEquivalentTo(other))
            {
                return(false);
            }

            var otherBool = (IonBool)other;

            if (NullFlagOn())
            {
                return(otherBool.IsNull);
            }

            return(!otherBool.IsNull && otherBool.Value == Value);
        }
コード例 #17
0
ファイル: IonStruct.cs プロジェクト: dhhoang/IonDotnet
        /// <summary>
        /// Add a new value to this struct.
        /// </summary>
        /// <param name="fieldName">Field name</param>
        /// <param name="value">Ion value to add.</param>
        /// <exception cref="ArgumentNullException">When field name is null.</exception>
        /// <exception cref="ContainedValueException">If the value is already child of a container.</exception>
        public void Add(string fieldName, IonValue value)
        {
            if (fieldName is null)
            {
                throw new ArgumentNullException(nameof(fieldName));
            }
            ThrowIfLocked();
            ThrowIfNull();
            if (value.Container != null)
            {
                throw new ContainedValueException(value);
            }

            value.FieldNameSymbol = new SymbolToken(fieldName, SymbolToken.UnknownSid);
            value.Container       = this;
            _values.Add(value);
        }
コード例 #18
0
ファイル: IonStruct.cs プロジェクト: dhhoang/IonDotnet
        public override bool Remove(IonValue item)
        {
            ThrowIfNull();
            ThrowIfLocked();
            if (item == null)
            {
                throw new ArgumentNullException(nameof(item));
            }

            if (item.Container != this)
            {
                return(false);
            }

            Debug.Assert(item.FieldNameSymbol != default && _values != null);
            _values.Remove(item);
            item.Container       = null;
            item.FieldNameSymbol = default;
            return(true);
        }
コード例 #19
0
ファイル: IonStruct.cs プロジェクト: dhhoang/IonDotnet
        public void Add(SymbolToken symbol, IonValue value)
        {
            if (symbol.Text != null)
            {
                Add(symbol.Text, value);
                return;
            }

            if (symbol.Sid < 0)
            {
                throw new ArgumentException("symbol has no text or sid", nameof(symbol));
            }
            ThrowIfLocked();
            ThrowIfNull();
            if (value.Container != null)
            {
                throw new ContainedValueException(value);
            }

            value.FieldNameSymbol = symbol;
            value.Container       = this;
            _values.Add(value);
        }
コード例 #20
0
ファイル: IonValue.cs プロジェクト: truongle2211/IonDotnet
 /// <summary>
 /// Returns true if this value is equivalent to the other, false otherwise.
 /// </summary>
 /// <param name="other">The other value.</param>
 /// <remarks>
 /// Equivalency is determined by whether the <see cref="IonValue"/> objects hold equal values, or
 /// in the case of container, they contain equivalent sets of children.
 /// </remarks>
 public abstract bool IsEquivalentTo(IonValue other);
コード例 #21
0
ファイル: IonDatagram.cs プロジェクト: truongle2211/IonDotnet
 /// <inheritdoc />
 /// <summary>
 /// Use strict reference equality for datagram.
 /// </summary>
 public override bool IsEquivalentTo(IonValue other) => other == this;
コード例 #22
0
 public override bool IsEquivalentTo(IonValue other) => other is IonNull;
コード例 #23
0
ファイル: IonStruct.cs プロジェクト: dhhoang/IonDotnet
 public override void Add(IonValue item)
 => throw new NotSupportedException("Cannot add a value to a struct without field name");