Last post Apr 05, 2010 04:18 PM by atconway
Mar 31, 2010 05:19 PM|chickflickssuck|LINK
For a few days now I have spent my spare time trying to learn about Reflection. Only 2 other .NET programmers exist in our company, and I rarely ever work directly with them... but I believe that understanding and using reflection could still benefit me
and my future projects.
I have scoured the web, looking for example projects or real world useful examples... I must be cursed with bad googling techniques because I have only come across one example project (which didnt even work properly) and a few code-snippet examples that
dont seem all-too-realistic.
Can anyone link me to some VB.NET *not C#* reflection example projects, or even explain how a 1-year-of-experience .NET programmer could realistically use reflection?
All direction and help is apperciated! thanks!
Mar 31, 2010 11:04 PM|CruzerB|LINK
Reflection is a big topic. How u going to implement the reflection? is to build a dynamic assembly or want to get dynamic properties at runtime?
Recently I just finish some class that able to get the dynamic properties at runtime. U may refer to below for the kick off.
Is much more easier to get the example in C# than VB.net. I'm also VB.net guy. So I'm always visit this (http://codechanger.com/) for the code convertion.
Apr 01, 2010 12:02 AM|Rohit Rao|LINK
try this ->
Apr 01, 2010 10:40 AM|atconway|LINK
One thing I would like to point out is that Reflection is a tool, not a design pattern or an entire technology that I feel you really need to tackle. It is like a small Phillips head screwdriver; it is good for some projects and useful when needed, but
it is not for everything. Reflection is something you can typically use for solving specific programming needs, but to sit down and learn the entire .NET namespace might not be the best use of your time.
In my years of .NET programming, I have used it on occasion, but never had the need to seek out and learn it from end to end. It is a 'tool' that I use on occasion.
Learning about it at a high level to know when the System.Reflection namespace can be powerful is probably a good idea, but it is not an architecture, methodology, or design pattern that is going to drastically improve multiple development projects. Just
scraping the surface would probably be good for now IMO, and if the need arises, you can dig into it deeper. For these reasons, this explains not finding a ton of material or example projects. For one being, very few projects are built entirely around Reflection.
Again it is a tool to use, but not a complete design pattern.
If you are trying to lead your team by learning about some useful technologies, then look into things like Silverlight, ASP.NET MVC, Entity Framework, OOP Design Patterns, WPF, WCF Services, Azure (if cloud computing is something you can use), etc.
Reflection is a core .NET Framework tool, and I would let that one sit by the wayside until you need to specifically use it.
Regardless, here are (2) links that might be helpful for just seeing a small use of Reflection:
.NET Framework Developer's Guide: Reflection:
Using Reflection to Map Properties on Objects by their String Name:
Hope this helps!
Apr 01, 2010 05:57 PM|chickflickssuck|LINK
Thank you all for the responses, I do have one question / explination for allen :)
The one reason why I have sought out trying to understand how to use reflection to my advantage, is because I have made many *and will make possibly dozens more* reports that have multiple levels.
such as colors for each size for each store:
Color Blue *sales data here*
Color Green *sales data here*
Color Red *sales data here*
Color Green *sales data here*
Through the use of reflection, I believe I could design a dynamic report that can more easily display data where anywhere from 1 to 5 grouping levels may exist, and each grouping level can be different *such as store -> size -> weight or size -> color
or date -> color -> sku type. I have read that you can dynamically manipulate properties at run time, so this would easily allow me to change number of columns in my table or the column name/type... as well as data displayed
With reflection being compared to a screwdriver, can i assume that it is more of a tool for piecing two unknown objects together
*attaching database results to a form's table during runtime, when the columns are unknown* by usage of the methods within the reflection namespace
*those methods being different types of screws*?
Apr 05, 2010 04:18 PM|atconway|LINK
To be honest, with describing in just a few sentences the makeup of your system and which tool to use it is difficult to make solid recommendations;
especially in regards to an inventory system. I have built an inventory system, and they can get complex quickly, especially at the database with all of the item combinations as you eluded to.
Make sure you read the MSDN link I provided about reflection, and at least go through the 1st few links within to have a better understanding of the power behind reflection. Typically reflection would be used to get information about an assembly, object,
etc at runtime. One time I had an app where I got the name of a method as a string, and was able to map that method name to an object via reflection and call that method dynamically. So you see it was a tool I used to help my app along, but not a complete
Also, since this conversation is going beyond VB.NET constructs and more about general architecture in relation to an inventory application, you may consider reposting any design questions into the Architecture forum. Here is another Reflection link that