<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
<title>Snipplr</title>
<link>http://snipplr.com/language/c-sharp/tags/Generic</link>
<description>Recent snippets posted on Snipplr.com</description>
<language>en-us</language>
<pubDate>Wed, 19 Jun 2013 17:21:51 GMT</pubDate>
<item>
<title>(C#) System Object extensions for easier conditionals (Extending Base Object Types) - bryanlyman</title>
<link>http://snipplr.com/view/53894/system-object-extensions-for-easier-conditionals-extending-base-object-types/</link>
<description><![CDATA[ <p>.net 3.0+, To create stability in your code, you must check all inputs into a method to make sure they are valid . Often people overlook this step because of laziness, or because they aren't convinced that exceptions and assertions are actually in place to help you instead of cause you a headache. Here are some extensions which can be used to enhance the System.Object class so that their methods are global to all classes; this makes input checking effortless. This is also somewhat generic in nature because the extensions take no class type in to account before they are called, but we can use type checking to perform different boxing (casting) operations.  Sadly this cannot be done in VB.net because late binding restrictions do not allow the Object class to be extended (See my VB.Net example for further information).</p> ]]></description>
<pubDate>Sat, 21 May 2011 02:48:17 GMT</pubDate>
<guid>http://snipplr.com/view/53894/system-object-extensions-for-easier-conditionals-extending-base-object-types/</guid>
</item>
<item>
<title>(C#) Anonymous generic List - wallybh</title>
<link>http://snipplr.com/view/43405/anonymous-generic-list/</link>
<description><![CDATA[ <p>Enables to create a generic list with anonymous types. Very useful for me :).</p> ]]></description>
<pubDate>Tue, 02 Nov 2010 04:10:24 GMT</pubDate>
<guid>http://snipplr.com/view/43405/anonymous-generic-list/</guid>
</item>
<item>
<title>(C#) Generic List bind to a drop down - jermeyz</title>
<link>http://snipplr.com/view/40489/generic-list-bind-to-a-drop-down/</link>
<description><![CDATA[ <p></p> ]]></description>
<pubDate>Wed, 15 Sep 2010 02:32:04 GMT</pubDate>
<guid>http://snipplr.com/view/40489/generic-list-bind-to-a-drop-down/</guid>
</item>
<item>
<title>(C#) Constructing Generics Through Reflection (List of Mixed Types Example) - bryanlyman</title>
<link>http://snipplr.com/view/33857/constructing-generics-through-reflection-list-of-mixed-types-example/</link>
<description><![CDATA[ <p>.net 2.0+ Generic classes make code size much smaller and casting objects (boxing) a cinch. However, currently there are some unsupported IDE options when trying to cast objects to and from generic objects that use mixed object types (inherited from a generic type specifier). Fear not, using reflection we can bypass the IDE and supply the users with strongly typed objects.</p> ]]></description>
<pubDate>Tue, 04 May 2010 16:58:15 GMT</pubDate>
<guid>http://snipplr.com/view/33857/constructing-generics-through-reflection-list-of-mixed-types-example/</guid>
</item>
<item>
<title>(C#) Generic list wrapper returns a smaller strongly typed sub-list  which modifies the parent-list when changed (without events) - bryanlyman</title>
<link>http://snipplr.com/view/26884/generic-list-wrapper-returns-a-smaller-strongly-typed-sublist--which-modifies-the-parentlist-when-changed-without-events/</link>
<description><![CDATA[ <p>A class which wraps a parent list containing mixed object types, to provide smaller strongly typed sub-lists of objects. These sub-lists can be modified, which then modifies the parent list concurrently (without events being triggered). Supports the merging of other lists of the same type. Supports serialization. Supports parent list auto-instantiation.</p> ]]></description>
<pubDate>Fri, 22 Jan 2010 19:24:16 GMT</pubDate>
<guid>http://snipplr.com/view/26884/generic-list-wrapper-returns-a-smaller-strongly-typed-sublist--which-modifies-the-parentlist-when-changed-without-events/</guid>
</item>
<item>
<title>(C#) Enum Limitation Fix Using a Generic Class and Implicit Casting - bryanlyman</title>
<link>http://snipplr.com/view/24778/enum-limitation-fix-using-a-generic-class-and-implicit-casting/</link>
<description><![CDATA[ <p>For .net 2.0+   The one limitation to enumerations is revealed when you try to reverse lookup an enumeration value using Enum.Parse(). The parse function will return an inconsistent enum object if ever there are two or more enumerations with the same numeric value. This class fixes that problem. Written as a system extension and using implicit casting, the process has been made extremely easy and made the syntax for the parse function even simpler. The process even allows enumeration names starting with a number or the name of a C# keyword as long as the name is preceded by an underscore. The implicit cast from an Enum object to a Enum.Cast object has been deliberately left out to account for single directional assignment, which forces the class to be used properly. An Enum to Cast object lookup would defeat the whole purpose of the class if the implicit operator is used during runtime; for this purpose a user assignment operator of type String is supplied. This simply forces the user to use Cast = Enum.ToString() to parse to a correct object. The ToString() overload for a Cast object returns a Friendly name which replaces all underscores with spaces and even allows double underscores for commas and triple underscores for periods; for this reason, the implicit \"from string\" caster also converts from a friendly name to the proper Enum object. This makes it very handy for enumerating through a list of items for a combo or list box and converting back to the proper object by simply supplying the name of the list item.</p> ]]></description>
<pubDate>Mon, 14 Dec 2009 18:03:38 GMT</pubDate>
<guid>http://snipplr.com/view/24778/enum-limitation-fix-using-a-generic-class-and-implicit-casting/</guid>
</item>
<item>
<title>(C#) Raise and handle events generically - pckujawa</title>
<link>http://snipplr.com/view/15033/raise-and-handle-events-generically/</link>
<description><![CDATA[ <p>For a discussion of .NET events best-practices, see [Roy Osherove's blog post](http://weblogs.asp.net/rosherove/articles/DefensiveEventPublishing.aspx) and [this post](http://blogs.msdn.com/ericlippert/archive/2009/04/29/events-and-races.aspx). Be sure to read the comments sections for some good arguments for and against the presented methods. Also, there is a good [MSDN Magazine article on Event Accessors](http://msdn.microsoft.com/en-us/magazine/cc163533.aspx), which may be useful.

Used in "Empire." The example shows an EventArgs with a DateTime object, but it could be a string or enumeration or whatever.</p> ]]></description>
<pubDate>Thu, 14 May 2009 16:30:42 GMT</pubDate>
<guid>http://snipplr.com/view/15033/raise-and-handle-events-generically/</guid>
</item>
<item>
<title>(C#) Serialize Object To String - mtelligent</title>
<link>http://snipplr.com/view/14704/serialize-object-to-string/</link>
<description><![CDATA[ <p></p> ]]></description>
<pubDate>Mon, 04 May 2009 09:39:11 GMT</pubDate>
<guid>http://snipplr.com/view/14704/serialize-object-to-string/</guid>
</item>
<item>
<title>(C#) Generic Convert - rengber</title>
<link>http://snipplr.com/view/9615/generic-convert/</link>
<description><![CDATA[ <p>This technique can convert a list of one type into a list of another in a single line given and instance to instance conversion method to be passed to the delegate constructor.</p> ]]></description>
<pubDate>Mon, 10 Nov 2008 19:42:38 GMT</pubDate>
<guid>http://snipplr.com/view/9615/generic-convert/</guid>
</item>
<item>
<title>(C#) Generic Based Event Handling Demo for VS.Net 2005 - rengber</title>
<link>http://snipplr.com/view/1565/generic-based-event-handling-demo-for-vsnet-2005/</link>
<description><![CDATA[ <p>Annotated version of the Microsoft/GotDotNet demo from the MSDN Wiki.</p> ]]></description>
<pubDate>Thu, 09 Nov 2006 13:05:19 GMT</pubDate>
<guid>http://snipplr.com/view/1565/generic-based-event-handling-demo-for-vsnet-2005/</guid>
</item>
</channel>
</rss>