diff --git a/MiniMods/DataReader/DataReaderMinimod.cs b/MiniMods/DataReader/DataReaderMinimod.cs new file mode 100755 index 0000000..329033f --- /dev/null +++ b/MiniMods/DataReader/DataReaderMinimod.cs @@ -0,0 +1,130 @@ +using System; +using System.Data; + +namespace Minimod.DataReader +{ + /// + ///

Minimod.DataReader, Version 0.0.1, Copyright © Uwe Zimmermann, 2012

+ /// A minimod with some extension methods for . + ///
+ /// + /// Licensed under the Apache License, Version 2.0; you may not use this file except in compliance with the License. + /// http://www.apache.org/licenses/LICENSE-2.0 + /// + public static class DataReaderMinimod + { + /// + /// Gets the string value of the specified field. If the value is it returns null. + /// + /// An . + /// The name of the field. + /// A string containing the value of the specified field or null if the value is . + /// When parameter is null. + public static string GetStringOrNull(this IDataReader self, string name) + { + if (self == null) + { + throw new ArgumentNullException("self"); + } + + var ordinal = self.GetOrdinal(name); + + return self.IsDBNull(ordinal) ? null : self.GetString(ordinal); + } + + /// + /// Gets the string value of the specified field. If the value is it returns null. + /// + /// An . + /// The index of the field. + /// A string containing the value of the specified field or null if the value is . + /// When parameter is null. + public static string GetStringOrNull(this IDataReader self, int fieldIndex) + { + if (self == null) + { + throw new ArgumentNullException("self"); + } + + return self.IsDBNull(fieldIndex) ? null : self.GetString(fieldIndex); + } + + /// + /// Gets the value of the specified field as Nullable of . If the value is + /// it returns null. + /// + /// The type to return. It have to be a struct. + /// An . + /// The name of the field. + /// The value of the specified field or null if the value is . + /// When parameter is null. + public static TResult? GetNullableValue(this IDataReader self, string fieldName) where TResult : struct + { + if (self == null) + { + throw new ArgumentNullException("self"); + } + + var ordinal = self.GetOrdinal(fieldName); + + return self.IsDBNull(ordinal) ? null : (TResult?)self.GetValue(ordinal); + } + + /// + /// Gets the value of the specified field as Nullable of . If the value is + /// it returns null. + /// + /// The type to return. It have to be a struct. + /// An . + /// The index of the field. + /// The value of the specified field or null if the value is . + /// When parameter is null. + public static TResult? GetNullableValue(this IDataReader self, int fieldIndex) where TResult : struct + { + if (self == null) + { + throw new ArgumentNullException("self"); + } + + return self.IsDBNull(fieldIndex) ? null : (TResult?)self.GetValue(fieldIndex); + } + + /// + /// Gets the value of the specified field as . + /// + /// The type to return. It have to be a struct. + /// An . + /// The name of the field. + /// The value of the specified field or null if the value is . + /// When parameter is null. + public static TResult GetValue(this IDataReader self, string fieldName) where TResult : struct + { + if (self == null) + { + throw new ArgumentNullException("self"); + } + + var ordinal = self.GetOrdinal(fieldName); + + return (TResult)self.GetValue(ordinal); + } + + /// + /// Gets the value of the specified field as . + /// + /// The type to return. It have to be a struct. + /// An . + /// The index of the field. + /// The value of the specified field or null if the value is . + /// When parameter is null. + public static TResult GetValue(this IDataReader self, int fieldIndex) where TResult : struct + { + if (self == null) + { + throw new ArgumentNullException("self"); + } + + return (TResult)self.GetValue(fieldIndex); + } + } +} \ No newline at end of file diff --git a/MiniMods/DataReader/DataReaderMinimod.nuspec b/MiniMods/DataReader/DataReaderMinimod.nuspec new file mode 100755 index 0000000..e08a464 --- /dev/null +++ b/MiniMods/DataReader/DataReaderMinimod.nuspec @@ -0,0 +1,18 @@ + + + + Minimod.DataReader + 0.0.1 + Uwe Zimmermann + false + http://www.apache.org/licenses/LICENSE-2.0 + minimod + + A minimod with some extension methods for . + + A minimod with some extension methods for . + + + + + diff --git a/MiniMods/Minimod.csproj b/MiniMods/Minimod.csproj index d34304d..ee7e317 100644 --- a/MiniMods/Minimod.csproj +++ b/MiniMods/Minimod.csproj @@ -84,6 +84,7 @@ + ..\packages\Ix_Experimental-Main.1.1.10823\lib\Net4\System.Interactive.dll @@ -96,6 +97,7 @@ + @@ -160,6 +162,7 @@ +