Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>No</strong>, that is not good practice. You want to apply extension methods at the <strong>lowest possible point</strong>. I believe there a time and a place for (almost) everything, but extension methods <em>System.Object</em> would almost never be appropriate. You should be able to apply extension methods such as this much further down the inheritance stack. Otherwise it will clutter your intellisense and probably end up being used/depended-upon incorrectly by other developers.</p> <p>However, extension methods for data objects for dealing with Null values is a <strong>very good use</strong> of extension methods. Consider putting them right on you <em>OleDbDataReader</em>. I have a generic extension method called ValueOrDefault that . . . well, I'll just show it to you:</p> <pre><code>&lt;Extension()&gt; _ Public Function ValueOrDefault(Of T)(ByVal r As DataRow, ByVal fieldName As String) As T If r.IsNull(fieldName) Then If GetType(T) Is GetType(String) Then Return CType(CType("", Object), T) Else Return Nothing End If Else Return CType(r.Item(fieldName), T) End If End Function </code></pre> <p>That's VB, but you get the picture. This sucker saves me a ton of time and really makes for clean code when reading out of a datarow. <strong>You are on the right track</strong>, but your sense of spell is correct: you have the extension methods too high.</p> <p>Putting the extension methods into a separate namespace is better than nothing (this is a perfectly valid use of namespaces; Linq uses this), but you shouldn't have to. To make these methods apply to various db objects, apply the extension methods to <em>IDataRecord</em>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload