<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/'><id>tag:blogger.com,1999:blog-4419504829140208150.post5622196743974963825..comments</id><updated>2010-08-06T20:25:36.417-07:00</updated><category term='active directory'/><category term='RoleProvider'/><category term='custom configuration section'/><category term='Bamboo'/><category term='job adverts'/><category term='Kaspersky'/><category term='programming maxims'/><category term='Cisco'/><category term='unrecognized element'/><category term='Women'/><category term='Apple'/><category term='c# 3.0'/><category term='ASP.NET'/><category term='EnumHelper'/><category term='c#'/><category term='Touch Pad'/><category term='pointers'/><category term='VPN'/><category term='Visual Studio 2008'/><category term='Magic Pad'/><category term='XmlTextWriter'/><category term='iPod'/><category term='attributes'/><category term='classes'/><category term='HR'/><category term='History'/><category term='windows services'/><category term='friend'/><category term='iMac'/><category term='variables'/><category term='vb.net'/><category term='web.config'/><category term='autodidactic'/><category term='by ref'/><category term='ConfigurationElementCollection'/><category term='iis'/><category term='authentication'/><category term='refactor'/><category term='Enumeration Helper'/><category term='Serializer'/><category term='abuse'/><category term='school'/><category term='VS2008'/><category term='Data Access Layer'/><category term='protected'/><category term='iPhone'/><category term='iTunes'/><category term='codeSubDirectories'/><category term='Kathy Sierra'/><category term='Ten years ago today'/><category term='ConfigurationElement'/><category term='app.config'/><category term='Installation'/><category term='.NET'/><category term='compilation error'/><category term='MacBook'/><category term='education'/><category term='reflection'/><category term='Microsoft'/><category term='MVC'/><category term='public'/><category term='net'/><category term='Technology'/><category term='asynchronous'/><category term='cache'/><category term='debugging'/><category term='MBP'/><category term='montessori'/><category term='nUnit'/><category term='serialization'/><category term='IDE'/><category term='Serialize'/><category term='access modifiers'/><category term='iis6'/><category term='Augmented Reality'/><category term='extension methods'/><category term='csharp'/><category term='creative writing'/><category term='Deserialize'/><category term='self-educated'/><category term='domain'/><category term='windows'/><category term='AnyConnect'/><category term='Wacom'/><category term='APP_Code'/><category term='hgweb'/><category term='DAL'/><category term='Unit Testing'/><category term='self-education'/><category term='debug'/><category term='extensions'/><category term='Future Technology'/><category term='MembershipProviderCollection'/><category term='MembershipProvider'/><category term='delegates'/><category term='private'/><category term='Data Access'/><category term='personnel'/><category term='ConfigurationManager.GetSection'/><category term='generics'/><category term='career'/><category term='adverts'/><category term='Tablet'/><category term='caching'/><category term='Enum'/><category term='c# 4.0'/><category term='mercurial'/><category term='Touchpad'/><category term='by val'/><category term='Enumerations'/><title type='text'>Comments on EndsWithSaurus...: Cleaning up my data access layer with generics and...</title><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://www.endswithsaurus.com/feeds/5622196743974963825/comments/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4419504829140208150/5622196743974963825/comments/default'/><link rel='alternate' type='text/html' href='http://www.endswithsaurus.com/2010/07/cleaning-up-my-dal-with-generics-and.html'/><author><name>BenAlabaster</name><uri>http://www.blogger.com/profile/08985426843666999422</uri><email>noreply@blogger.com</email><gd:image xmlns:gd='http://schemas.google.com/g/2005' rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>11</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-4419504829140208150.post-6488632301893775864</id><published>2010-08-06T20:25:36.417-07:00</published><updated>2010-08-06T20:25:36.417-07:00</updated><title type='text'>I like your change.</title><content type='html'>I like your change.</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4419504829140208150/5622196743974963825/comments/default/6488632301893775864'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4419504829140208150/5622196743974963825/comments/default/6488632301893775864'/><link rel='alternate' type='text/html' href='http://www.endswithsaurus.com/2010/07/cleaning-up-my-dal-with-generics-and.html?showComment=1281151536417#c6488632301893775864' title=''/><author><name>whileicompile</name><uri>http://whileicompile.wordpress.com/</uri><email>noreply@blogger.com</email><gd:image xmlns:gd='http://schemas.google.com/g/2005' rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img1.blogblog.com/img/openid16-rounded.gif'/></author><thr:in-reply-to xmlns:thr='http://purl.org/syndication/thread/1.0' href='http://www.endswithsaurus.com/2010/07/cleaning-up-my-dal-with-generics-and.html' ref='tag:blogger.com,1999:blog-4419504829140208150.post-5622196743974963825' source='http://www.blogger.com/feeds/4419504829140208150/posts/default/5622196743974963825' type='text/html'/><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='blogger.itemClass' value='pid-1951086704'/></entry><entry><id>tag:blogger.com,1999:blog-4419504829140208150.post-6507826387661300620</id><published>2010-08-06T20:21:26.088-07:00</published><updated>2010-08-06T20:21:26.088-07:00</updated><title type='text'>Hey, I just reread my last comment, and in number ...</title><content type='html'>Hey, I just reread my last comment, and in number 3, I misspoke, &amp;quot;nullable value&amp;quot; should read &amp;quot;nullable type&amp;quot;.&lt;br /&gt;&lt;br /&gt;Anyway, here&amp;#39;s a small console app that I wrote to test it. Notice on the last call to your extension method, it passes in &amp;#39;int?&amp;#39; ... that&amp;#39;s the part that&amp;#39;s got the problem, since the call to Convert.ChangeType() falls apart doing a conversion to typeof(int?) or any nullable type for that matter.&lt;br /&gt;&lt;br /&gt;http://pastebin.com/P5fAUEPp&lt;br /&gt;&lt;br /&gt;PS-If I can&amp;#39;t delete my previous post, the reason there are two is for the formatting &amp;amp; the dropped characters in my previous comment.</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4419504829140208150/5622196743974963825/comments/default/6507826387661300620'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4419504829140208150/5622196743974963825/comments/default/6507826387661300620'/><link rel='alternate' type='text/html' href='http://www.endswithsaurus.com/2010/07/cleaning-up-my-dal-with-generics-and.html?showComment=1281151286088#c6507826387661300620' title=''/><author><name>whileicompile</name><uri>http://whileicompile.wordpress.com/</uri><email>noreply@blogger.com</email><gd:image xmlns:gd='http://schemas.google.com/g/2005' rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img1.blogblog.com/img/openid16-rounded.gif'/></author><thr:in-reply-to xmlns:thr='http://purl.org/syndication/thread/1.0' href='http://www.endswithsaurus.com/2010/07/cleaning-up-my-dal-with-generics-and.html' ref='tag:blogger.com,1999:blog-4419504829140208150.post-5622196743974963825' source='http://www.blogger.com/feeds/4419504829140208150/posts/default/5622196743974963825' type='text/html'/><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='blogger.itemClass' value='pid-1951086704'/></entry><entry><id>tag:blogger.com,1999:blog-4419504829140208150.post-8655703994477140086</id><published>2010-08-06T20:08:46.692-07:00</published><updated>2010-08-06T20:08:46.692-07:00</updated><title type='text'>Okay, I see the issue now, here&amp;#39;s a fix that a...</title><content type='html'>Okay, I see the issue now, here&amp;#39;s a fix that accounts for that:&lt;br /&gt;&lt;br /&gt;public static T GetValue&amp;lt;T&amp;gt;(this IDataReader reader, string fieldName)&lt;br /&gt;{&lt;br /&gt;  object value = reader[fieldName];&lt;br /&gt;  if (value == null || DBNull.Value.Equals(value))&lt;br /&gt;    return default(T);&lt;br /&gt;  return (T)Convert.ChangeType(value, Nullable.GetUnderlyingType(typeof(T)) ?? typeof(T));&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Because a the default of a nullable type is null, all you&amp;#39;ve got to do is check the underlying type in the Convert.ChangeType line to have it return the correct type.</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4419504829140208150/5622196743974963825/comments/default/8655703994477140086'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4419504829140208150/5622196743974963825/comments/default/8655703994477140086'/><link rel='alternate' type='text/html' href='http://www.endswithsaurus.com/2010/07/cleaning-up-my-dal-with-generics-and.html?showComment=1281150526692#c8655703994477140086' title=''/><author><name>BenAlabaster</name><uri>http://www.blogger.com/profile/08985426843666999422</uri><email>noreply@blogger.com</email><gd:image xmlns:gd='http://schemas.google.com/g/2005' rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://1.bp.blogspot.com/_nJgl5bSQrHA/SRs8E-Dc2AI/AAAAAAAAAAM/t_FH5Wrk0eg/s1600-R/n771240219_5461.jpg'/></author><thr:in-reply-to xmlns:thr='http://purl.org/syndication/thread/1.0' href='http://www.endswithsaurus.com/2010/07/cleaning-up-my-dal-with-generics-and.html' ref='tag:blogger.com,1999:blog-4419504829140208150.post-5622196743974963825' source='http://www.blogger.com/feeds/4419504829140208150/posts/default/5622196743974963825' type='text/html'/><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='blogger.itemClass' value='pid-319607845'/></entry><entry><id>tag:blogger.com,1999:blog-4419504829140208150.post-176363509159693158</id><published>2010-08-06T19:49:13.582-07:00</published><updated>2010-08-06T19:49:13.582-07:00</updated><title type='text'>Hey, I just reread my last comment, and in number ...</title><content type='html'>Hey, I just reread my last comment, and in number 3, I misspoke, &amp;quot;nullable value&amp;quot; should read &amp;quot;nullable type&amp;quot;.&lt;br /&gt;&lt;br /&gt;Anyway, here&amp;#39;s a small console app that I wrote to test it.  Notice on the last call to your extension method, it passes in &amp;#39;int?&amp;#39; ... that&amp;#39;s the part that&amp;#39;s got the problem, since the call to Convert.ChangeType() falls apart doing a conversion to typeof(int?) or any nullable type for that matter.&lt;br /&gt;&lt;br /&gt;//-----------------------------------&lt;br /&gt;using System;&lt;br /&gt;using System.Data;&lt;br /&gt;using System.Data.SqlClient;&lt;br /&gt;&lt;br /&gt;namespace NullableExtensionMethodTest&lt;br /&gt;{&lt;br /&gt;    class Program&lt;br /&gt;    {&lt;br /&gt;        static void Main(string[] args)&lt;br /&gt;        {&lt;br /&gt;            try&lt;br /&gt;            {&lt;br /&gt;                using (SqlConnection cn = new SqlConnection(@&amp;quot;Data Source=.;Database=master;Integrated Security=SSPI;&amp;quot;))&lt;br /&gt;                {&lt;br /&gt;                    cn.Open();&lt;br /&gt;                    using (SqlCommand cmd = new SqlCommand(&amp;quot;select top 1 id, name from sysobjects where xtype=&amp;#39;U&amp;#39;&amp;quot;, cn))&lt;br /&gt;                    using (IDataReader dr = cmd.ExecuteReader())&lt;br /&gt;                    {&lt;br /&gt;                        if (!dr.Read())&lt;br /&gt;                        {&lt;br /&gt;                            Console.WriteLine(&amp;quot;No results&amp;quot;);&lt;br /&gt;                            return;&lt;br /&gt;                        }&lt;br /&gt;&lt;br /&gt;                        Console.WriteLine(&amp;quot;-- GetNullableValue()&amp;quot;);&lt;br /&gt;                        Console.Write(&amp;quot;Retrieving id ...&amp;quot;);&lt;br /&gt;                        int? nullableVariable = dr.GetNullableValue(&amp;quot;id&amp;quot;);&lt;br /&gt;                        string name = dr[&amp;quot;name&amp;quot;].ToString();&lt;br /&gt;                        if (!nullableVariable.HasValue)&lt;br /&gt;                            Console.WriteLine(&amp;quot;**ERROR** ... null value returned&amp;quot;);&lt;br /&gt;                        else&lt;br /&gt;                            Console.WriteLine(&amp;quot;Success - [{0}] {1}&amp;quot;, nullableVariable.ToString(), name);&lt;br /&gt;&lt;br /&gt;                        Console.WriteLine(&amp;quot;-- GetValue() - non-null type&amp;quot;);&lt;br /&gt;                        Console.Write(&amp;quot;Retrieving id ...&amp;quot;);&lt;br /&gt;                        int nonNullableVariable = dr.GetValue(&amp;quot;id&amp;quot;);&lt;br /&gt;                        name = dr[&amp;quot;name&amp;quot;].ToString();&lt;br /&gt;                        Console.WriteLine(&amp;quot;Success - [{0}] {1}&amp;quot;, nonNullableVariable.ToString(), name);&lt;br /&gt;&lt;br /&gt;                        Console.WriteLine(&amp;quot;-- GetValue() - non-null type&amp;quot;);&lt;br /&gt;                        Console.Write(&amp;quot;Retrieving id ...&amp;quot;);&lt;br /&gt;                        nullableVariable = dr.GetValue(&amp;quot;id&amp;quot;);&lt;br /&gt;                        name = dr[&amp;quot;name&amp;quot;].ToString();&lt;br /&gt;                        Console.WriteLine(&amp;quot;Success - [{0}] {1}&amp;quot;, nullableVariable.ToString(), name);&lt;br /&gt;                    }&lt;br /&gt;                }&lt;br /&gt;            }&lt;br /&gt;            catch (Exception ex)&lt;br /&gt;            {&lt;br /&gt;                Console.WriteLine(&amp;quot;-- Error --&amp;quot;);&lt;br /&gt;                Console.Write(ex.ToString());&lt;br /&gt;            }&lt;br /&gt;            finally&lt;br /&gt;            {&lt;br /&gt;                Console.WriteLine(&amp;quot;\n\nPress any key to exit...&amp;quot;);&lt;br /&gt;                Console.ReadKey();&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    public static class DataReaderExtension&lt;br /&gt;    {&lt;br /&gt;        public static T? GetNullableValue(this IDataReader reader, string fieldName)&lt;br /&gt;            where T : struct&lt;br /&gt;        {&lt;br /&gt;            object value = reader[fieldName];&lt;br /&gt;            if (value == null)&lt;br /&gt;                return null;&lt;br /&gt;            if (DBNull.Value.Equals(value))&lt;br /&gt;                return null;&lt;br /&gt;            return (T)Convert.ChangeType(value, typeof(T));&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        public static T GetValue(this IDataReader reader, string fieldName)&lt;br /&gt;        {&lt;br /&gt;            object value = reader[fieldName];&lt;br /&gt;            if (value == null || DBNull.Value.Equals(value))&lt;br /&gt;                return default(T);&lt;br /&gt;            return (T)Convert.ChangeType(value, typeof(T));&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;}</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4419504829140208150/5622196743974963825/comments/default/176363509159693158'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4419504829140208150/5622196743974963825/comments/default/176363509159693158'/><link rel='alternate' type='text/html' href='http://www.endswithsaurus.com/2010/07/cleaning-up-my-dal-with-generics-and.html?showComment=1281149353582#c176363509159693158' title=''/><author><name>whileicompile</name><uri>http://whileicompile.wordpress.com/</uri><email>noreply@blogger.com</email><gd:image xmlns:gd='http://schemas.google.com/g/2005' rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img1.blogblog.com/img/openid16-rounded.gif'/></author><thr:in-reply-to xmlns:thr='http://purl.org/syndication/thread/1.0' href='http://www.endswithsaurus.com/2010/07/cleaning-up-my-dal-with-generics-and.html' ref='tag:blogger.com,1999:blog-4419504829140208150.post-5622196743974963825' source='http://www.blogger.com/feeds/4419504829140208150/posts/default/5622196743974963825' type='text/html'/><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='blogger.itemClass' value='pid-1951086704'/></entry><entry><id>tag:blogger.com,1999:blog-4419504829140208150.post-8480693414338694470</id><published>2010-08-03T08:40:16.995-07:00</published><updated>2010-08-03T08:40:16.995-07:00</updated><title type='text'>I did notice however that if (somehow) you managed...</title><content type='html'>I did notice however that if (somehow) you managed to get a nullable value (i.e. Nullable) into one of the fields of your IDataReader, the code would bomb out attempting to do the conversion.  I don&amp;#39;t know if it&amp;#39;s even possible for an IDataReader field to return either null or a nullable value (i.e Nullable) though.  So I&amp;#39;m not sure if this is even relevant.</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4419504829140208150/5622196743974963825/comments/default/8480693414338694470'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4419504829140208150/5622196743974963825/comments/default/8480693414338694470'/><link rel='alternate' type='text/html' href='http://www.endswithsaurus.com/2010/07/cleaning-up-my-dal-with-generics-and.html?showComment=1280850016995#c8480693414338694470' title=''/><author><name>BenAlabaster</name><uri>http://www.blogger.com/profile/08985426843666999422</uri><email>noreply@blogger.com</email><gd:image xmlns:gd='http://schemas.google.com/g/2005' rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://1.bp.blogspot.com/_nJgl5bSQrHA/SRs8E-Dc2AI/AAAAAAAAAAM/t_FH5Wrk0eg/s1600-R/n771240219_5461.jpg'/></author><thr:in-reply-to xmlns:thr='http://purl.org/syndication/thread/1.0' href='http://www.endswithsaurus.com/2010/07/cleaning-up-my-dal-with-generics-and.html' ref='tag:blogger.com,1999:blog-4419504829140208150.post-5622196743974963825' source='http://www.blogger.com/feeds/4419504829140208150/posts/default/5622196743974963825' type='text/html'/><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='blogger.itemClass' value='pid-319607845'/></entry><entry><id>tag:blogger.com,1999:blog-4419504829140208150.post-6439563199581547625</id><published>2010-08-03T07:07:42.950-07:00</published><updated>2010-08-03T07:07:42.950-07:00</updated><title type='text'>returning default(T) will allow for nullable value...</title><content type='html'>returning default(T) will allow for nullable values to be passed back in the same way that it will pass null back for values that allow null and default values for those that don&amp;#39;t, i.e. DateTime and Int.</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4419504829140208150/5622196743974963825/comments/default/6439563199581547625'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4419504829140208150/5622196743974963825/comments/default/6439563199581547625'/><link rel='alternate' type='text/html' href='http://www.endswithsaurus.com/2010/07/cleaning-up-my-dal-with-generics-and.html?showComment=1280844462950#c6439563199581547625' title=''/><author><name>BenAlabaster</name><uri>http://www.blogger.com/profile/08985426843666999422</uri><email>noreply@blogger.com</email><gd:image xmlns:gd='http://schemas.google.com/g/2005' rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://1.bp.blogspot.com/_nJgl5bSQrHA/SRs8E-Dc2AI/AAAAAAAAAAM/t_FH5Wrk0eg/s1600-R/n771240219_5461.jpg'/></author><thr:in-reply-to xmlns:thr='http://purl.org/syndication/thread/1.0' href='http://www.endswithsaurus.com/2010/07/cleaning-up-my-dal-with-generics-and.html' ref='tag:blogger.com,1999:blog-4419504829140208150.post-5622196743974963825' source='http://www.blogger.com/feeds/4419504829140208150/posts/default/5622196743974963825' type='text/html'/><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='blogger.itemClass' value='pid-319607845'/></entry><entry><id>tag:blogger.com,1999:blog-4419504829140208150.post-5129042854704270030</id><published>2010-08-03T07:06:13.819-07:00</published><updated>2010-08-03T07:06:13.819-07:00</updated><title type='text'>Okay, I&amp;#39;ll admit I hadn&amp;#39;t tested for that ...</title><content type='html'>Okay, I&amp;#39;ll admit I hadn&amp;#39;t tested for that scenario as I&amp;#39;ve never seen an actual null value come back from a database, I&amp;#39;ve only ever seen DBNull.Value come back which my code excerpt worked for (well, all bar the naming issue with my transcription into the post). In order to account for true null values, I&amp;#39;d modify the code ever so slightly:&lt;br /&gt;&lt;br /&gt;public static T GetValue&amp;lt;T&amp;gt;(this IDataReader reader, string fieldName)&lt;br /&gt;{&lt;br /&gt;  object value = reader[fieldName];&lt;br /&gt;  if (value == null || DBNull.Value.Equals(value))&lt;br /&gt;    return default(T);&lt;br /&gt;  return (T)Convert.ChangeType(value, typeof(T));&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;That should now account for null, DBNull and nullable types without the need for a second method to handle nullable types.</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4419504829140208150/5622196743974963825/comments/default/5129042854704270030'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4419504829140208150/5622196743974963825/comments/default/5129042854704270030'/><link rel='alternate' type='text/html' href='http://www.endswithsaurus.com/2010/07/cleaning-up-my-dal-with-generics-and.html?showComment=1280844373819#c5129042854704270030' title=''/><author><name>BenAlabaster</name><uri>http://www.blogger.com/profile/08985426843666999422</uri><email>noreply@blogger.com</email><gd:image xmlns:gd='http://schemas.google.com/g/2005' rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://1.bp.blogspot.com/_nJgl5bSQrHA/SRs8E-Dc2AI/AAAAAAAAAAM/t_FH5Wrk0eg/s1600-R/n771240219_5461.jpg'/></author><thr:in-reply-to xmlns:thr='http://purl.org/syndication/thread/1.0' href='http://www.endswithsaurus.com/2010/07/cleaning-up-my-dal-with-generics-and.html' ref='tag:blogger.com,1999:blog-4419504829140208150.post-5622196743974963825' source='http://www.blogger.com/feeds/4419504829140208150/posts/default/5622196743974963825' type='text/html'/><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='blogger.itemClass' value='pid-319607845'/></entry><entry><id>tag:blogger.com,1999:blog-4419504829140208150.post-3483186483141984442</id><published>2010-08-03T06:57:03.813-07:00</published><updated>2010-08-03T06:57:03.813-07:00</updated><title type='text'></title><content type='html'>This comment has been removed by the author.</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4419504829140208150/5622196743974963825/comments/default/3483186483141984442'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4419504829140208150/5622196743974963825/comments/default/3483186483141984442'/><author><name>BenAlabaster</name><uri>http://www.blogger.com/profile/08985426843666999422</uri><email>noreply@blogger.com</email><gd:image xmlns:gd='http://schemas.google.com/g/2005' rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://1.bp.blogspot.com/_nJgl5bSQrHA/SRs8E-Dc2AI/AAAAAAAAAAM/t_FH5Wrk0eg/s1600-R/n771240219_5461.jpg'/></author><thr:in-reply-to xmlns:thr='http://purl.org/syndication/thread/1.0' href='http://www.endswithsaurus.com/2010/07/cleaning-up-my-dal-with-generics-and.html' ref='tag:blogger.com,1999:blog-4419504829140208150.post-5622196743974963825' source='http://www.blogger.com/feeds/4419504829140208150/posts/default/5622196743974963825' type='text/html'/><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='blogger.contentRemoved' value='true'/><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='blogger.itemClass' value='pid-319607845'/></entry><entry><id>tag:blogger.com,1999:blog-4419504829140208150.post-9063106181874141245</id><published>2010-08-02T18:52:04.372-07:00</published><updated>2010-08-02T18:52:04.372-07:00</updated><title type='text'>Ok, a couple things:
1. dr vs rdr ... makes sense,...</title><content type='html'>Ok, a couple things:&lt;br /&gt;1. dr vs rdr ... makes sense, I was just wondering.&lt;br /&gt;2. I think the variable in your sample (and mine) should be reader not rdr (see the parameter)&lt;br /&gt;&lt;br /&gt;But mostly&lt;br /&gt;3. You can&amp;#39;t pass in a nullable value into your method, because it dies on Convert.ChangeType()&lt;br /&gt;&lt;br /&gt;I changed my method a bit when I tried to compile it.&lt;br /&gt;public static T? GetNullableValue(this IDataReader reader, string fieldName)&lt;br /&gt;    where T : struct&lt;br /&gt;{&lt;br /&gt;    object value = reader[fieldName];&lt;br /&gt;    if (value == null)&lt;br /&gt;        return null;&lt;br /&gt;    if (DBNull.Value.Equals(value))&lt;br /&gt;        return null;&lt;br /&gt;    return (T)Convert.ChangeType(value, typeof(T));&lt;br /&gt;}</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4419504829140208150/5622196743974963825/comments/default/9063106181874141245'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4419504829140208150/5622196743974963825/comments/default/9063106181874141245'/><link rel='alternate' type='text/html' href='http://www.endswithsaurus.com/2010/07/cleaning-up-my-dal-with-generics-and.html?showComment=1280800324372#c9063106181874141245' title=''/><author><name>John MacIntyre</name><uri>http://www.blogger.com/profile/12186404975439029623</uri><email>noreply@blogger.com</email><gd:image xmlns:gd='http://schemas.google.com/g/2005' rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:in-reply-to xmlns:thr='http://purl.org/syndication/thread/1.0' href='http://www.endswithsaurus.com/2010/07/cleaning-up-my-dal-with-generics-and.html' ref='tag:blogger.com,1999:blog-4419504829140208150.post-5622196743974963825' source='http://www.blogger.com/feeds/4419504829140208150/posts/default/5622196743974963825' type='text/html'/><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='blogger.itemClass' value='pid-1331376592'/></entry><entry><id>tag:blogger.com,1999:blog-4419504829140208150.post-111097132074259226</id><published>2010-08-02T16:48:54.842-07:00</published><updated>2010-08-02T16:48:54.842-07:00</updated><title type='text'>In the context of your naming schema, you&amp;#39;re u...</title><content type='html'>In the context of your naming schema, you&amp;#39;re using letters to represent words, i.e. D = Data, R = Reader; In the context of my naming schema for these code exerpts, it&amp;#39;s phonetic shortening rdr = ReaDeR.  &amp;quot;dr&amp;quot; or &amp;quot;rdr&amp;quot; makes little difference to me, it&amp;#39;s a schema that I often use habitually and the single extra character doesn&amp;#39;t cost me any time as my fingers type rdr on autopilot.&lt;br /&gt;&lt;br /&gt;Going on to your point about the return type being a Nullable&amp;lt;T&amp;gt;, this is automatically inferred with my method example as you call it using the generic nullable, i.e.:&lt;br /&gt;&lt;br /&gt;int? val = dr.GetValue&amp;lt;int?&amp;gt;(&amp;quot;fieldX&amp;quot;);&lt;br /&gt;&lt;br /&gt;It will return whatever type you tell it needs to be returned.  When you apply a value to a nullable, it still returns the value as a nullable type.  In my testing, everything worked just fine.</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4419504829140208150/5622196743974963825/comments/default/111097132074259226'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4419504829140208150/5622196743974963825/comments/default/111097132074259226'/><link rel='alternate' type='text/html' href='http://www.endswithsaurus.com/2010/07/cleaning-up-my-dal-with-generics-and.html?showComment=1280792934842#c111097132074259226' title=''/><author><name>BenAlabaster</name><uri>http://www.blogger.com/profile/08985426843666999422</uri><email>noreply@blogger.com</email><gd:image xmlns:gd='http://schemas.google.com/g/2005' rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://1.bp.blogspot.com/_nJgl5bSQrHA/SRs8E-Dc2AI/AAAAAAAAAAM/t_FH5Wrk0eg/s1600-R/n771240219_5461.jpg'/></author><thr:in-reply-to xmlns:thr='http://purl.org/syndication/thread/1.0' href='http://www.endswithsaurus.com/2010/07/cleaning-up-my-dal-with-generics-and.html' ref='tag:blogger.com,1999:blog-4419504829140208150.post-5622196743974963825' source='http://www.blogger.com/feeds/4419504829140208150/posts/default/5622196743974963825' type='text/html'/><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='blogger.itemClass' value='pid-319607845'/></entry><entry><id>tag:blogger.com,1999:blog-4419504829140208150.post-4442661717029042017</id><published>2010-08-02T09:25:27.912-07:00</published><updated>2010-08-02T09:25:27.912-07:00</updated><title type='text'>I prefer the passing the field name syntax into th...</title><content type='html'>I prefer the passing the field name syntax into the method as well.&lt;br /&gt;&lt;br /&gt;I wonder if modifying this for nullable types wouldn&amp;#39;t be useful as well.  Say something like this?&lt;br /&gt;&lt;br /&gt;public static T? GetNullableValue(this IDataReader reader, &lt;br /&gt;                            string fieldName)&lt;br /&gt;{&lt;br /&gt;    object value = rdr[fieldName];&lt;br /&gt;    if (value == null)&lt;br /&gt;        return null;&lt;br /&gt;    if (DbNull.Value.Equals(value))&lt;br /&gt;        return null;&lt;br /&gt;    return (T)Convert.ChangeType(value, typeof(T));&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;BTW-What is the first &amp;#39;r&amp;#39; in the IDataReader variable stand for?  I usually just use dr.</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4419504829140208150/5622196743974963825/comments/default/4442661717029042017'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4419504829140208150/5622196743974963825/comments/default/4442661717029042017'/><link rel='alternate' type='text/html' href='http://www.endswithsaurus.com/2010/07/cleaning-up-my-dal-with-generics-and.html?showComment=1280766327912#c4442661717029042017' title=''/><author><name>John</name><uri>http://johnmacintyre.myopenid.com/</uri><email>noreply@blogger.com</email><gd:image xmlns:gd='http://schemas.google.com/g/2005' rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img1.blogblog.com/img/openid16-rounded.gif'/></author><thr:in-reply-to xmlns:thr='http://purl.org/syndication/thread/1.0' href='http://www.endswithsaurus.com/2010/07/cleaning-up-my-dal-with-generics-and.html' ref='tag:blogger.com,1999:blog-4419504829140208150.post-5622196743974963825' source='http://www.blogger.com/feeds/4419504829140208150/posts/default/5622196743974963825' type='text/html'/><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='blogger.itemClass' value='pid-1334722456'/></entry></feed>
