|
thanks
the quieter u become more u hear
|
|
|
|
|
Is it possible to get the program's own filename on runtime?(exe file)
|
|
|
|
|
Yes, of course.
OK, here's what I use:
System.Windows.Forms.Application.ExecutablePath
and sometimes I pass that through
System.IO.Path.GetFileNameWithoutExtension()
modified on Thursday, January 22, 2009 10:40 PM
|
|
|
|
|
PIEBALDconsult wrote: Yes, of course.
Why is common sense not common?
Never argue with an idiot. They will drag you down to their level where they are an expert.
Sometimes it takes a lot of work to be lazy
Individuality is fine, as long as we do it together - F. Burns
|
|
|
|
|
Get the current process using Process.GetCurrentProcess()
Then use the ProcessName or MainModule property.
«_Superman_»
|
|
|
|
|
I don't think that'll work reliably.
|
|
|
|
|
You mean, we would not always get the filename ?
«_Superman_»
|
|
|
|
|
Is there a guarantee that the process name is the filename?
On the other hand I just tried it and it seems to be reliable.
At least it knows if I change the file name.
I may need to look into it further.
|
|
|
|
|
I guess you might as well you the GetModuleFileName API
«_Superman_»
|
|
|
|
|
That may have a problem if called from a different assembly?
I guess stick with System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName .
I suppose might System.Windows.Forms.Application.ExecutablePath call that.
|
|
|
|
|
You can use Assembly.GetExecutingAssembly().GetName() in .Net and if you want file path then you can use this one[^]
|
|
|
|
|
If main calls a library routine in another assembly and that routine does that, you'll get the name of the library assembly, not the assembly containing main.
|
|
|
|
|
Ive got a class library project set up, and its set for 3.5 framework.(Im actually following a tutorial online).
However, when I reference a IList<t>, I get no extension method in the list, such as ToArray<t>.
Im defining an object as:
IList<int> results = new List<int>();
var convertedtoArray = results.ToArray<int>();
But I can compiler error because ToArray doesnt exist. Even though Im using the System.Collections.Generic namespace.
Any ideas?
Mark
modified on Thursday, January 22, 2009 5:27 PM
|
|
|
|
|
You must have a reference to the assembly in your project, not just a using statement.
only two letters away from being an asset
|
|
|
|
|
System.Collections.Generic sits in the System.Core assembly, which is referenced by default.
|
|
|
|
|
No, only part of it.
System.Collections.Generic.List<> is in mscorlib assembly, while System.Collections.Generic.Queue<> is in System assembly.
Eslam Afifi
|
|
|
|
|
using System.Linq;
and reference System.Core
Eslam Afifi
|
|
|
|
|
using System.Linq, thats the one.
Thanks Eslam!
|
|
|
|
|
You're welcome.
Eslam Afifi
|
|
|
|
|
Therein lies a great deal of what I don't like about extension methods.
|
|
|
|
|
and what might that be?
only two letters away from being an asset
|
|
|
|
|
People not knowing where they are and not even knowing that they are extension methods.
At least as regular static methods it's clearer that the method is not part of the type.
Exension methods are a form of obfuscation.
But that's just me.
|
|
|
|
|
PIEBALDconsult wrote: even knowing that they are extension methods.
VS shows extension methods with a different icon in intellisense, right?
|
|
|
|
|
Not everyone uses VS. Snippets of code posted here don't have intellisense either. Nor do printouts
Don't rely on the behaviour of any one tool.
modified on Friday, January 23, 2009 1:26 AM
|
|
|
|
|
The semantics of an extension method are correct, and they increase code readability. They are certainly preferable than buggering up the type heirarchy with things like "MyListWithExtraStuff : List". They also allow you to extend any type which supports a particular interface, which is a powerful feature - almost like half-baked multiple inheritance.
myFoo.Baz(bar);
Is Baz an extension method? Does it matter? As long as it "bazzes" as documented, then it is no different from a normal method.
|
|
|
|