|
-
Nov 27th, 2002, 10:01 PM
#1
Thread Starter
New Member
Finding a class in an assembly?
My program compiles script files written in VB.NET at run-time into an assembly in memory using the built-in compiler stuff. Now, let's say my script has this in it:
VB Code:
Namespace Testing
Public Class Abc
Public Sub TryMe()
System.Windows.Forms.MessageBox.Show("Hello World")
End Sub
End Class
End Namespace
Well, my program will take this script and compile it at run-time into an assembly in memory.
Is there a way to get a list of the namespaces/classes/etc. contained within the assembly, or search through it for a class with a certain name and return its information?
I'm pretty new to assembly stuff and compiling dynamic code at run-time, so I'm not really sure how to do much yet. Any help would be greatly appreciated.
Thanks in advance,
Satch
-
Nov 28th, 2002, 02:50 AM
#2
Registered User
Maybe you can do something like this.....
Code:
Dim asm As System.Reflection.Assembly
asm = System.Reflection.Assembly.LoadFrom("c:\asm.dll")
Dim ty As Type
For Each ty In asm.GetTypes
MsgBox(ty.FullName)
Next
I'm not sure how to get a proper reference to the class in your case, if LoadFrom does not work, try Load or any of the other commands.
-
Nov 28th, 2002, 04:29 PM
#3
yay gay
of course u can..do a search by the forum and u'll c that i made the same question a while ago..
and by what u say i see that u used the system.reflection.emit ... i am very interested in that but where can i find info about how to use it? tks
\m/  \m/
-
Nov 28th, 2002, 06:05 PM
#4
Thread Starter
New Member
Thanks for the responses 
PT, I found the post and can't wait to get home to try it out. As for the System.Reflection.Emit stuff, I'm not sure if its the same as what I'm doing. I use the Microsoft.VisualBasic.VBCodeProvider and the compiler in System.CodeDOM (can't remember the full name at the moment.) Either way, it'll compile VB.NET code. I'll post a link to it when I get home where I have access to my project's code.
-
Nov 29th, 2002, 09:59 PM
#5
Thread Starter
New Member
This compiles the compile.vb file in the application's directory and outputs it into assembly.dll and loads it into the memory.
VB Code:
Dim myVBCodeProvider As Microsoft.VisualBasic.VBCodeProvider
Dim myCodeCompiler As CodeDom.Compiler.ICodeCompiler
Dim myCompilerParameters As CodeDom.Compiler.CompilerParameters
Dim myCompilerResults As CodeDom.Compiler.CompilerResults
Dim i As Long
myCompilerParameters = New CodeDom.Compiler.CompilerParameters()
myCompilerParameters.GenerateInMemory = False
myCompilerParameters.GenerateExecutable = False
myCompilerParameters.OutputAssembly = Application.StartupPath + "\assembly.dll"
myVBCodeProvider = New Microsoft.VisualBasic.VBCodeProvider()
Dim asm As [Assembly]
For Each asm In AppDomain.CurrentDomain.GetAssemblies
myCompilerParameters.ReferencedAssemblies.Add(asm.Location)
Next
myCodeCompiler = myVBCodeProvider.CreateCompiler()
myCompilerResults = myCodeCompiler.CompileAssemblyFromFile(myCompilerParameters, Application.StartupPath + "\compile.vb")
If myCompilerResults.Errors.HasErrors Then
For i = 1 To myCompilerResults.Errors.Count
frmMain.DefInstance.lstStatus.Items.Add("Error: " + myCompilerResults.Errors.Item(i - 1).ToString())
Application.DoEvents()
Next
Exit Sub
End If
Compiler_Assembly = myCompilerResults.CompiledAssembly
-
Dec 1st, 2002, 05:42 PM
#6
yay gay
ahh tks...but im in C#...and looks like no one has examples about using system.reflection.emit
\m/  \m/
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|