///<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); }
/// <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); }
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)); }
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)); }
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)); }
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); }
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)); }
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)); }
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)); }
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)); }
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)); }
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)); }
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)); }
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)); }
/// <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); }
/// <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); }