/// <summary> /// Tries to get the result of calling <see cref="IValuedNode.AsBoolean()">AsBoolean()</see> on a node throwing an error if the node is null. /// </summary> /// <param name="n">Node.</param> /// <exception cref="RdfQueryException">Thrown if the input is null of the specific valued node cannot be cast to a boolean.</exception> /// <returns></returns> public static bool AsSafeBoolean(this IValuedNode n) { if (n == null) { throw new RdfQueryException("Cannot cast a null to a boolean"); } return(n.AsBoolean()); }
private static object GetPrimitiveValue(IValuedNode valuedNode, IEdmPrimitiveType targetType, bool asNullable) { // TODO: Some sort of cast to nullable when necessary switch (targetType.PrimitiveKind) { case EdmPrimitiveTypeKind.Boolean: return(valuedNode.AsBoolean()); case EdmPrimitiveTypeKind.Byte: return((byte)valuedNode.AsInteger()); case EdmPrimitiveTypeKind.DateTime: return(valuedNode.AsDateTime()); case EdmPrimitiveTypeKind.Decimal: return(valuedNode.AsDecimal()); case EdmPrimitiveTypeKind.Double: return(valuedNode.AsDouble()); case EdmPrimitiveTypeKind.Int16: return((Int16)valuedNode.AsInteger()); case EdmPrimitiveTypeKind.Int32: return((Int32)valuedNode.AsInteger()); case EdmPrimitiveTypeKind.Int64: return(valuedNode.AsInteger()); case EdmPrimitiveTypeKind.String: return(valuedNode.AsString()); case EdmPrimitiveTypeKind.DateTimeOffset: return(valuedNode.AsDateTime()); default: throw new NotSupportedException( String.Format("Support for primitive type {0} has not been implemented yet", targetType.PrimitiveKind)); } }
private static object GetPrimitiveValue(IValuedNode valuedNode, IEdmPrimitiveType targetType, bool asNullable) { // TODO: Some sort of cast to nullable when necessary switch (targetType.PrimitiveKind) { case EdmPrimitiveTypeKind.Boolean: return valuedNode.AsBoolean(); case EdmPrimitiveTypeKind.Byte: return (byte) valuedNode.AsInteger(); case EdmPrimitiveTypeKind.DateTime: return valuedNode.AsDateTime(); case EdmPrimitiveTypeKind.Decimal: return valuedNode.AsDecimal(); case EdmPrimitiveTypeKind.Double: return valuedNode.AsDouble(); case EdmPrimitiveTypeKind.Int16: return (Int16) valuedNode.AsInteger(); case EdmPrimitiveTypeKind.Int32: return (Int32) valuedNode.AsInteger(); case EdmPrimitiveTypeKind.Int64: return valuedNode.AsInteger(); case EdmPrimitiveTypeKind.String: return valuedNode.AsString(); case EdmPrimitiveTypeKind.DateTimeOffset: return valuedNode.AsDateTime(); default: throw new NotSupportedException( String.Format("Support for primitive type {0} has not been implemented yet", targetType.PrimitiveKind)); } }