Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamic class definitions

Status
Not open for further replies.

groston

IS-IT--Management
Dec 31, 2001
141
US
I have an ASP.NET application to which I want to limit access depending on the user's level of authorization. Currently, I do this by maintaining a database table with the requisitie information.

However, this is a poor method. What I would rather do is have each page (class) define a method (myAuths) that returns the appropriate information to the calling routine. Knowing that the class name is the same as the file name, a routine could find all of the .ASPX files in application's directory, thereby providing sufficient information for doing this.

So basically, in very pseudo-code:

for each ASPX file in myAppDir
dim myClassName as String = FileName - ".ASPX"
dim myClass as myClassName <<<===
authInfo = myClass.myAuths()
myClass = Nothing
next

I have yet to figure out how to implement the marked line. Obviously, what is written here is nonsense.

I thought that this might work:

Dim testObj As Object
authInfo = CType(testObj, myClassName).myAuths()

But I get a compile error of: Type 'Type.GetType' is not defined.

From my reading, this is related to &quot;late binding&quot;, but that bit of info has not been terribly useful.

Your help/suggestions are gratefully welcomed.

----

Gerry Roston
gerry@pairofdocs.net
 
Found the magic!

This is what you need to do:

for each ASPX file in myAppDir
dim myClassName as string = &quot;ClassName.&quot; + FileName - &quot;.ASPX&quot;
Dim t As Type = Type.GetType(myClassName)
Dim o As Object = Activator.CreateInstance(t)
Dim retval As myReturnType
retval = CType(t.GetMethod(&quot;myAuths&quot;).Invoke(o, Nothing), myReturnType)
next

Hopefully, someone else will find this helpful...



----

Gerry Roston
gerry@pairofdocs.net
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top