Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0VS Class question?VS Class question?
Previous
 
Next
New Post
4/14/2008 2:43 PM
 

I know this my not be the appropriate forum to post this but I need some help and I know that DNN developers are the best to ask. I am developing a module for a DNN site. I have numerous class files each containing different Procedures. These classes are based on quarters of the year. For example (Q12008.vb ,Q22008.vb, Q32008vb, etc.) The reason that I have these class files is because my procedures change each quarter.

My question is how can I call these classes in a dynamic way. PLEASE HELP!

Example:

Dim x as string

x = Q12008

call class (x)

X.DoThisProcedure

 

 

 
New Post
4/14/2008 3:41 PM
 

I'm going to give a crappy answer (no code samples) but hopefully it gets you to start looking in the right direction -- you'll need to use Reflection to load up those classes dynamically and then work with them.  If you have them all inheriting from a base class you can use reflection to load them and then cast them to the base class and call the methods (if the base class were abstract, for example).

Doing a simple Google search for .NET Reflection gave a few results that may or may not be good:

http://msdn2.microsoft.com/en-us/library/ms227224(VS.80).aspx

http://my.execpc.com/~gopalan/dotnet/reflection.html


-- Jon Seeley
DotNetNuke Modules
Custom DotNetNuke and .NET Development
http://www.seeleyware.com
 
New Post
4/14/2008 9:52 PM
 

I have been trying multiple ways to use Reflection but with no success. I am not doing it in the right way. Can somebody give me an example? I have looked at multiple sites but so far no luck in finding a good example. PLEASE HELP ME!!!

 
New Post
4/14/2008 10:48 PM
 

Reflection is not easy the first time ;)

It can work like this (this is just one of many possible ways):

Dim typeName = "Q12008"
Dim t As Type
= Type.GetTypeFromProgID(typeName)
Dim x As Object = Activator.CreateInstance(t)
Dim flags As BindingFlags = BindingFlags.IgnoreCase Or BindingFlags.Instance Or BindingFlags.InvokeMethod Or BindingFlags.Public
Dim myParam As Object = "hello world"
Dim arguments As Object() = {myParam}
Dim pm As ParameterModifier() = {New ParameterModifier(1)}
pm(0)(0) = False ' false for input param, true for output param
t.InvokeMember("DoThisProcedure", flags, Nothing, x, arguments, pm, Nothing, Nothing)

See .. its simple ;) 

JK


You know your website is cool, so why not let your users help you by spreading the word on social networking sites - get the DotNetNuke Social Bookmarks Module with 57 different ways to add social bookmarks to your site ... or download the FREE demo right now
 
New Post
4/15/2008 3:31 PM
 

JK,

Thanks for the reply. The code is not working though. It throws a Null reference execption at the Dim X as Object line. The reason why is because t is nothing. Is there something else that I can use besides Type.GetTypeFromProgID ?

 

Thanks!

 
Previous
 
Next
HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0VS Class question?VS Class question?


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out