示例#1
0
 ///<summary>
 /// Removes any property on this data object with the specified type and value
 ///</summary>
 ///<param name="type">The type of the property to be removed</param>
 ///<param name="value">The value of the property to be removed</param>
 ///<param name="lang">OPTIONAL: The language code of the property to be removed. This parameter is ignored if <paramref name="value"/> is an <see cref="IDataObject"/></param>
 ///<returns>This IDataObject to allow chained calls</returns>
 ///<remarks>If this object has no matching property, then this call is a no-op</remarks>
 public IDataObject RemoveProperty(IDataObject type, object value, string lang = null)
 {
     if (value is IDataObject)
     {
         RemoveDataObjectProperty(type, value as IDataObject);
     }
     else if (value is Uri)
     {
         RemoveDataObjectProperty(type, _store.MakeDataObject(value.ToString()));
     }
     else
     {
         if (type == null)
         {
             throw new ArgumentNullException("type");
         }
         if (value == null)
         {
             throw new ArgumentNullException("value");
         }
         string dataType  = RdfDatatypes.GetRdfDatatype(value.GetType());
         string litString = RdfDatatypes.GetLiteralString(value);
         RemoveLiteralProperty(type, litString, dataType, lang);
     }
     return(this);
 }
示例#2
0
        /// <summary>
        /// Sets the property of this object to the specified value
        /// </summary>
        /// <param name="type">The type of the property to set</param>
        /// <param name="value">The new value of the property</param>
        /// <param name="langCode">OPTIONAL : the language code for the new literal. This parameter is ignored if <paramref name="value"/> is an <see cref="IDataObject"/></param>
        /// <returns>This IDataObject to allow chained calls</returns>
        /// <remarks>This method will remove all existing properties of type <paramref name="type"/> from this data object
        /// and add a single replacement property of the same type with <paramref name="value"/> as the property value.</remarks>
        public IDataObject SetProperty(IDataObject type, object value, string langCode = null)
        {
            if (value is IDataObject)
            {
                return(SetRelatedObject(type, value as IDataObject));
            }
            if (value is ILiteralNode)
            {
                var lit = value as ILiteralNode;
                SetPropertyLiteral(type, lit.Value, lit.DataType.ToString(), lit.Language);
                return(this);
            }
            if (value is IUriNode)
            {
                var uri = value as IUriNode;
                return(SetRelatedObject(type, _store.MakeDataObject(uri.Uri.ToString())));
            }
            if (value is Uri)
            {
                return(SetRelatedObject(type, _store.MakeDataObject(value.ToString())));
            }
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }
            string dataType  = RdfDatatypes.GetRdfDatatype(value.GetType());
            string litString = RdfDatatypes.GetLiteralString(value);

            SetPropertyLiteral(type, litString, dataType, langCode);
            return(this);
        }
示例#3
0
        public void TestIntegerRoundtrip()
        {
            const int v        = -123456789;
            var       bsString = RdfDatatypes.GetLiteralString(v);
            var       bsParsed = (int)RdfDatatypes.ParseLiteralString(bsString, RdfDatatypes.Integer, null);

            Assert.That(bsParsed, Is.EqualTo(v));
        }
示例#4
0
        public void TestDoubleRoundtrip()
        {
            const double dbl      = 1.123456789D;
            var          bsString = RdfDatatypes.GetLiteralString(dbl);
            var          bsParsed = (double)RdfDatatypes.ParseLiteralString(bsString, RdfDatatypes.Double, null);

            Assert.That(bsParsed, Is.EqualTo(dbl));
        }
示例#5
0
        public void TestDateTimeRoundtrip()
        {
            var v        = new DateTime(2012, 03, 04, 09, 10, 11, 25, DateTimeKind.Utc);
            var bsString = RdfDatatypes.GetLiteralString(v);
            var parsed   = RdfDatatypes.ParseLiteralString(bsString, RdfDatatypes.DateTime, null);

            Assert.That(parsed, Is.EqualTo(v));
        }
示例#6
0
        public void TestBooleanRoundtrip()
        {
            var bsString = RdfDatatypes.GetLiteralString(true);

            Assert.That(RdfDatatypes.ParseLiteralString(bsString, RdfDatatypes.Boolean, null), Is.True);
            bsString = RdfDatatypes.GetLiteralString(false);
            Assert.That(RdfDatatypes.ParseLiteralString(bsString, RdfDatatypes.Boolean, null), Is.False);
        }
示例#7
0
        public void TestUnsignedByteRoundtrip()
        {
            const byte v        = 244;
            var        bsString = RdfDatatypes.GetLiteralString(v);
            var        bsParsed = (byte)RdfDatatypes.ParseLiteralString(bsString, RdfDatatypes.UnsignedByte, null);

            Assert.That(bsParsed, Is.EqualTo(v));
        }
示例#8
0
        public void TestUnsignedShortRoundtrip()
        {
            const ushort v        = 64000;
            var          bsString = RdfDatatypes.GetLiteralString(v);
            var          bsParsed = (ushort)RdfDatatypes.ParseLiteralString(bsString, RdfDatatypes.UnsignedShort, null);

            Assert.That(bsParsed, Is.EqualTo(v));
        }
示例#9
0
        public void TestUnsignedLongRoundtrip()
        {
            const ulong v        = 9876543210L;
            var         bsString = RdfDatatypes.GetLiteralString(v);
            var         bsParsed = (ulong)RdfDatatypes.ParseLiteralString(bsString, RdfDatatypes.UnsignedLong, null);

            Assert.That(bsParsed, Is.EqualTo(v));
        }
示例#10
0
        public void TestShortRoundtrip()
        {
            const short v        = -16384;
            var         bsString = RdfDatatypes.GetLiteralString(v);
            var         bsParsed = (short)RdfDatatypes.ParseLiteralString(bsString, RdfDatatypes.Short, null);

            Assert.That(bsParsed, Is.EqualTo(v));
        }
示例#11
0
        public void TestDecimalRoundtrip()
        {
            const decimal d        = 1.123456789M;
            var           bsString = RdfDatatypes.GetLiteralString(d);
            var           bsParsed = (decimal)RdfDatatypes.ParseLiteralString(bsString, RdfDatatypes.Decimal, null);

            Assert.That(bsParsed, Is.EqualTo(d));
        }
示例#12
0
        public void TestByteRoundtrip()
        {
            const sbyte v        = -64;
            var         bsString = RdfDatatypes.GetLiteralString(v);
            var         bsParsed = (sbyte)RdfDatatypes.ParseLiteralString(bsString, RdfDatatypes.Byte, null);

            Assert.That(bsParsed, Is.EqualTo(v));
        }
示例#13
0
        public void TestLongRoundtrip()
        {
            const long v        = -9876543210;
            var        bsString = RdfDatatypes.GetLiteralString(v);
            var        bsParsed = (long)RdfDatatypes.ParseLiteralString(bsString, RdfDatatypes.Long, null);

            Assert.That(bsParsed, Is.EqualTo(v));
        }
示例#14
0
        public void TestFloatRoundtrip()
        {
            const float v        = 1.12345F;
            var         bsString = RdfDatatypes.GetLiteralString(v);
            var         bsParsed = (float)RdfDatatypes.ParseLiteralString(bsString, RdfDatatypes.Float, null);

            Assert.That(bsParsed, Is.EqualTo(v));
        }
示例#15
0
        /// <summary>
        /// Sets the property of this object to the specified value
        /// </summary>
        /// <param name="type">The type of the property to set</param>
        /// <param name="value">The new value of the property</param>
        /// <param name="langCode">OPTIONAL : the language code for the new literal. This parameter is ignored if <paramref name="value"/> is an <see cref="IDataObject"/></param>
        /// <returns>This IDataObject to allow chained calls</returns>
        /// <remarks>This method will remove all existing properties of type <paramref name="type"/> from this data object
        /// and add a single replacement property of the same type with <paramref name="value"/> as the property value.</remarks>
        public IDataObject SetProperty(IDataObject type, object value, string langCode = null)
        {
            if (value is IDataObject)
            {
                return(SetRelatedObject(type, value as IDataObject));
            }
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }
            string dataType  = RdfDatatypes.GetRdfDatatype(value.GetType());
            string litString = RdfDatatypes.GetLiteralString(value);

            SetPropertyLiteral(type, litString, dataType, langCode);
            return(this);
        }
示例#16
0
 /// <summary>
 /// Adds a new property value to this object
 /// </summary>
 /// <param name="type">The type of the property to add</param>
 /// <param name="value">The value of the property</param>
 /// <param name="lang">OPTIONAL: The language code of the literal value. This parameter is ignored if <paramref name="value"/> is an <see cref="IDataObject"/></param>
 /// <returns>This IDataOjbect to allow chained calls</returns>
 public IDataObject AddProperty(IDataObject type, object value, string lang = null)
 {
     if (value is IDataObject)
     {
         AddDataObjectProperty(type, value as IDataObject);
     }
     else
     {
         if (type == null)
         {
             throw new ArgumentNullException("type");
         }
         if (value == null)
         {
             throw new ArgumentNullException("value");
         }
         string dataType  = RdfDatatypes.GetRdfDatatype(value.GetType());
         string litString = RdfDatatypes.GetLiteralString(value);
         AddLiteralProperty(type, litString, dataType, lang);
     }
     return(this);
 }