Assembly.CodeBase // Getting it statically without object instantiation

S

sloan

Here is the msdn code for getting the .CodeBase property of an Assembly

Assembly SampleAssembly;
// Instantiate a target object.
Int32 Integer1 = new Int32();
Type Type1;
// Set the Type instance to the target class type.
Type1 = Integer1.GetType();
// Instantiate an Assembly class to the assembly housing the Integer type.
SampleAssembly = Assembly.GetAssembly(Integer1.GetType());
// Gets the location of the assembly using file: protocol.
Console.WriteLine("CodeBase=" + SampleAssembly.CodeBase);


Notice the "new Int32". (aka, an object instantiation)

Is there a way to statically get the Assembly.CodeBase ~without
instantiating an object ?

Take the simple example where you create a new/blank Console.Application.
How can I get the .CodeBase of that console app... remembering that I'm in
the
static world.. as such
static void Main(string[] args)

{



}
 
D

David Browne

sloan said:
Here is the msdn code for getting the .CodeBase property of an Assembly

Assembly SampleAssembly;
// Instantiate a target object.
Int32 Integer1 = new Int32();
Type Type1;
// Set the Type instance to the target class type.
Type1 = Integer1.GetType();
// Instantiate an Assembly class to the assembly housing the Integer type.
SampleAssembly = Assembly.GetAssembly(Integer1.GetType());
// Gets the location of the assembly using file: protocol.
Console.WriteLine("CodeBase=" + SampleAssembly.CodeBase);


Notice the "new Int32". (aka, an object instantiation)

Is there a way to statically get the Assembly.CodeBase ~without
instantiating an object ?

Take the simple example where you create a new/blank Console.Application.
How can I get the .CodeBase of that console app... remembering that I'm in
the
static world.. as such
static void Main(string[] args)

{
Console.WriteLine(System.Reflection.Assembly.GetAssembly(typeof(Int32)).CodeBase);



}

David
 
S

sloan

I couldn't see the trees for the forest.

Thanks David.



David Browne said:
sloan said:
Here is the msdn code for getting the .CodeBase property of an Assembly

Assembly SampleAssembly;
// Instantiate a target object.
Int32 Integer1 = new Int32();
Type Type1;
// Set the Type instance to the target class type.
Type1 = Integer1.GetType();
// Instantiate an Assembly class to the assembly housing the Integer type.
SampleAssembly = Assembly.GetAssembly(Integer1.GetType());
// Gets the location of the assembly using file: protocol.
Console.WriteLine("CodeBase=" + SampleAssembly.CodeBase);


Notice the "new Int32". (aka, an object instantiation)

Is there a way to statically get the Assembly.CodeBase ~without
instantiating an object ?

Take the simple example where you create a new/blank Console.Application.
How can I get the .CodeBase of that console app... remembering that I'm in
the
static world.. as such
static void Main(string[] args)

{
Console.WriteLine(System.Reflection.Assembly.GetAssembly(typeof(Int32)).Code
Base);

David
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top