| | | 
StrataFrame User
       
Group: StrataFrame Users Last Login: 09/05/2008 9:57:46 AM Posts: 354, Visits: 2,247 |
| | I remember seeing how to do this using reflection but cannot remember how it was done. Below is psuedo code of what I want to do. public sub whatever(classname as string) dim something as new classname end sub Thanks Paul |
| | | | 
StrataFrame Developer

Group: StrataFrame Developers Last Login: Yesterday @ 10:38:53 PM Posts: 2,683, Visits: 1,883 |
| | Here ya go... If you end up doing a lot of reflection, you'll probably want to import System.Reflection... Private Sub DoSomething(ByVal ClassName As String, ByVal MethodName As String) '-- Establish locals Dim loObject As Object Dim loType As Type Dim loMethod As Reflection.MethodInfo '-- Get the type loType = Type.GetType(ClassName) '-- Create the object loObject = Activator.CreateInstance(loType) '-- Get the method loMethod = loType.GetMethod(MethodName) '-- Execute the method loMethod.Invoke(loObject, Nothing) End Sub You can also use the Object Browser in visual studio and look at everything in the System.Reflection namespace. You'll get lots of ideas of what you might want to do 
www.bungie.net |
| | | | 
StrataFrame User
       
Group: StrataFrame Users Last Login: 09/05/2008 9:57:46 AM Posts: 354, Visits: 2,247 |
| | Thanks Ben, That was what I was looking for! Once I seen it the light came on. Thanks man Paul |
| | | | 
StrataFrame Developer

Group: StrataFrame Developers Last Login: Yesterday @ 10:38:53 PM Posts: 2,683, Visits: 1,883 |
| No problem  Reflection is fun because you can do literally ANYTHING with it... access private members, create instances of private types, etc.; you can even use the stuff within the Emit namespace to create dynamic types, methods, and assemblies. However, you'll want to try to use it as sparingly as possible because it is slow... in fact, it's even slower than late binding, but there are times when it is unavoidable. We go to great lengths within the framework to avoid the use of reflection where ever possible (hence the creation of the property descriptors within the business object... if you don't use them, then .NET uses reflection to accomplish all of the binding tasks).
www.bungie.net |
| | | | 
Advanced StrataFrame User
       
Group: StrataFrame Users Last Login: 2 days ago @ 2:02:58 PM Posts: 644, Visits: 10,954 |
| Right ... after understanding Serialization, this is my next challenge. |
| | | | 
StrataFrame User
       
Group: StrataFrame Users Last Login: 09/05/2008 9:57:46 AM Posts: 354, Visits: 2,247 |
| Don't worry Ivan i have full faith that as soon as we get comfortable using .net MS will throw something new at us to learn. Reflection seems like macro substitution "&" in foxpro but on steriods. Now I am struggling with type converters. |
| | | | 
StrataFrame Developer

Group: StrataFrame Developers Last Login: Yesterday @ 4:58:13 AM Posts: 4,379, Visits: 4,421 |
| Reflection seems like macro substitution "&" in foxpro but on steriods. You are exactly right here...just a much better strong-typed version that is not as likely to blow your fingers off when you use it |
| | | | 
StrataFrame User
       
Group: StrataFrame Users Last Login: 09/05/2008 9:57:46 AM Posts: 354, Visits: 2,247 |
| You have that right!! |
| | | | 
Advanced StrataFrame User
       
Group: StrataFrame Users Last Login: 2 days ago @ 2:02:58 PM Posts: 644, Visits: 10,954 |
| Paul Chase (10/26/2006)
Don't worry Ivan i have full faith that as soon as we get comfortable using .net MS will throw something new at us to learn.  Should I seet and wait then? Reflection seems like macro substitution "&" in foxpro but on steriods. Oh, good to know. I will certainly bump into it soon. Now I am struggling with type converters. Don't think you're allowed to swear in the forum! |
| | | |
|