<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" media="screen" href="/styles/xslt/rss.xslt"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:media="http://search.yahoo.com/mrss/" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:c9="http://channel9.msdn.com">
<channel>
	<title>Channel 9 Forums - Tech Off - Generic Base class problem</title>
	<atom:link rel="self" type="application/rss+xml" href="http://channel9.msdn.com/Forums/rss"></atom:link>
	<image>
		<url>http://mschnlnine.vo.llnwd.net/d1/Dev/App_Themes/C9/images/feedimage.png</url>
		<title>Channel 9 Forums - Tech Off - Generic Base class problem</title>
		<link>http://channel9.msdn.com/Forums</link>
	</image>
	<description>Channel 9 keeps you up to date with the latest news and behind the scenes info from Microsoft that developers love to keep up with. From LINQ to SilverLight – Watch videos and hear about all the cool technologies coming and the people behind them.</description>
	<link>http://channel9.msdn.com/Forums</link>
	<language>en</language>
	<pubDate>Sun, 19 May 2013 02:19:26 GMT</pubDate>
	<lastBuildDate>Sun, 19 May 2013 02:19:26 GMT</lastBuildDate>
	<generator>Rev9</generator>
	<c9:totalResults>4</c9:totalResults>
	<c9:pageCount>-4</c9:pageCount>
	<c9:pageSize>-1</c9:pageSize>
	<item>
		<title>Tech Off - Generic Base class problem</title>
		<description><![CDATA[<p>I'm wondering if anyone has some insight to this problem.<br>
<br>
I'm working with a business object base class that uses generics to return strongly typed data for some of the static methods.<br>
<br>
public class BusinessObjectBase&lt;T&gt;<br>
{<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;public static IList&lt;T&gt; GetAList()<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;IList&lt;T&gt;&nbsp;listOfBusinessObjects = new List&lt;T&gt;();<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// code to populate the list.<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return listOfBusinessObjects<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>
}<br>
<br>
The business object base class of course does a lot more but this is a good example why I decided to use generics.<br>
<br>
I have a deriving class Customer:<br>
<br>
public class Customer : BusinessObjectBase&lt;Customer&gt;<br>
{<br>
}<br>
<br>
First this seems overly redundant specifying the type for the business base right after the declaration of the Customer&nbsp;type, but it sure beats passing the Customer type to every generic static method. Probably look something like this.<br>
<br>
IList&lt;Customer&gt; customers = Customer.GetAList&lt;Customer&gt;();<br>
<br>
So adding the generic to the base class made sense. This looks a lot cleaner:<br>
<br>
IList&lt;Customer&gt; customers = Customer.GetAList();<br>
<br>
I ran into this problem however. I wanted to add a bunch of specific things to the Customer class, but since I have other applications that use the Customer class, I decided to derive from it.<br>
<br>
public class SpecialCustomer: Customer<br>
{<br>
}<br>
<br>
This worked great until I wanted to call the static methods on the base class.<br>
<br>
IList&lt;SpecialCustomer&gt; specialCustomers = SpecialCustomer.GetAList();<br>
<br>
The compiler notified me that SpecialCustomer.GetAList() actually returned IList&lt;Customer&gt;. WHAT! Yep, SpecialCustomer implements Customer which implements BusinessObjectBase&lt;Customer&gt;. This was apparently obvious to everyone but me.
<br>
<br>
So Is there anyway to resolve this. I certainly cant add a generic to Customer.<br>
<br>
public class Customer&lt;T&gt; : BusinessObjectBase &lt;T&gt;<br>
{<br>
}<br>
<br>
It'd work for SpecialCustomer:<br>
<br>
public class SpecialCustomer: Customer&lt;SpecialCustomer&gt; {}<br>
<br>
But just cause you can do it, doesn't mean it's to be done. That would look sweet defining a regular customer.<br>
<br>
Customer customer = new Customer&lt;Customer&lt;Customer&lt; Customer&lt;Customer&lt;Customer&lt;Customer&lt;Customer&lt; Customer&lt;Customer&lt;Customer... Ugh...<br>
<br>
Being a&nbsp;noob sux <img src='http://ecn.channel9.msdn.com/o9/content/images/emoticons/emotion-7.gif' alt='Perplexed' /></p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/251259-Generic-Base-class-problem/251259#251259</link>
		<pubDate>Sun, 07 Jan 2007 00:25:55 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/251259-Generic-Base-class-problem/251259#251259</guid>
		<dc:creator>JoshB</dc:creator>
		<slash:comments>4</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/JoshB/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - Generic Base class problem</title>
		<description><![CDATA[<p>Hey JoshB,<br>
<br>
Generics are awsome, but they can cause you some grief if you don't watch out.<br>
<br>
One way you can take care of this problem is to hide the implementation of your&nbsp;Customer class that returns the IList&lt;Customer&gt; and simply create a new IList&lt;SpecialCustomer&gt; and basically create instances of SpecialCustomer from the Customer objects that you
 would get from base.<br>
<br>
Hope that helps.</p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/251259-Generic-Base-class-problem/b2acc17df81b442398059dea014fe02a#b2acc17df81b442398059dea014fe02a</link>
		<pubDate>Sun, 07 Jan 2007 07:29:29 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/251259-Generic-Base-class-problem/b2acc17df81b442398059dea014fe02a#b2acc17df81b442398059dea014fe02a</guid>
		<dc:creator>ilya</dc:creator>
		<slash:comments>4</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/ilya/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - Generic Base class problem</title>
		<description><![CDATA[<p>Your talking about a contra/co- variance problem.&nbsp; The problem is that IList&lt;Bob&gt; isnt assignable to IList&lt;Person&gt; even though Bob is a type of person.&nbsp; They fixed this problem in .NET 4.</p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/251259-Generic-Base-class-problem/f5ac0d3208ec4597b0ee9dea014fe079#f5ac0d3208ec4597b0ee9dea014fe079</link>
		<pubDate>Mon, 15 Feb 2010 22:15:22 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/251259-Generic-Base-class-problem/f5ac0d3208ec4597b0ee9dea014fe079#f5ac0d3208ec4597b0ee9dea014fe079</guid>
		<dc:creator>cdwatkins</dc:creator>
		<slash:comments>4</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/cdwatkins/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - Generic Base class problem</title>
		<description><![CDATA[<p><blockquote><div class="quoteUser">cdwatkins said:</div><div class="quoteText">
<p>Your talking about a contra/co- variance problem.&nbsp; The problem is that IList&lt;Bob&gt; isnt assignable to IList&lt;Person&gt; even though Bob is a type of person.&nbsp; They fixed this problem in .NET 4.</p>
</div></blockquote>
<p>Probably not the solution you are looking for, but you could do this:</p>
<p>&nbsp;</p>
<p>Have only one Customer class and make your 'special' members internal so only you can use them. If it's in a different assembly from where you need it you can use this to gain access to the internal members:
<a href="http://msdn.microsoft.com/en-us/library/0tke9fxk.aspx">http://msdn.microsoft.com/en-us/library/0tke9fxk.aspx</a></p></p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/251259-Generic-Base-class-problem/7c7ca35a05a4447db2679dea014fe0a1#7c7ca35a05a4447db2679dea014fe0a1</link>
		<pubDate>Tue, 16 Feb 2010 01:45:22 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/251259-Generic-Base-class-problem/7c7ca35a05a4447db2679dea014fe0a1#7c7ca35a05a4447db2679dea014fe0a1</guid>
		<dc:creator>ploe</dc:creator>
		<slash:comments>4</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/ploe/Discussions/RSS</wfw:commentRss>
	</item>
</channel>
</rss>