|
Is there a way to return the full path name of the file containing the code?
suppose I have the following class in the file c:\myproject\CA.cs
public static class A
{
public static void Show()
{
string myFile = ....
Console.WriteLine(myFile);
}
}
modified 20-Nov-12 17:08pm.
|
|
|
|
|
The only possible reason I could see for you doing so, is if you're working on some sort of dynamic plugin system and you're going to compile/interpret/load the file at runtime - in which case you need a system to register where you're going to look for the code/plugin/etc
Once your code is compiled into an exe or a dll, you can find the path to the executable module or where it was loaded from, but not to a single piece of code - What would be the point, hmm, if a compiled module couldnt be shipped to a seperate machine/location, but that compiled module still had to retain a reference to the source code ?? yuck ??
Maybe Ive mis-interpreted what you're asking
|
|
|
|
|
You can certainly get the fully qualified name.
There might be some method in the Assembly which loaded the class which might provide a path name but I doubt it would be a fully qualified one. (I don't feel like looking at the docs at the current time.)
Your version control system might have 'variables' (or macros, etc - the name is always different) that allows it to insert the path into the source code when you check it in. If so you could create string with that. Of course you would need to do it on every class.
|
|
|
|
|
The best I can think of is the stack trace, but it's probably not worth the trouble.
Remember that a class can be partial or inherit members from base classes.
If you really want to, you could add an Attribute to the class, but you'd have to weigh the costs and benefits of added maintenance.
It still comes down to why you want the information.
|
|
|
|
|
The reason it that the class has a method that should be able to copy its source file whatever it is.
An alternative solution i found:
1) create each file containing one only class so that the file is the class name
2) implementing a method (in a base class that will be overrides), which get the text class name,
and build a name of file (classname +".cs"). Then starting from root directory of project, it will search for the file name in the sub directories..
a workaround.. but it should work
|
|
|
|
|
You still haven't really explained why. Why do you want to copy the file?
And what happens if the app is installed on another system or otherwise separate from the source?
Include the file name in a config file?
Could you include the source as a resource in the app?
Or in an install package?
|
|
|
|
|
it is an utility I use only during the developing, only to copy the file containing the specific class to a specific directory. I don have to distribute it.
This is way: I don ' want to look for the class and do copy and paste of the file manually
|
|
|
|
|
Sounds like a lot of hard work for no particular benefit. You can probably do this more easily within Visual Studio during your build processing.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
If you're using the functionality of this class again and again, why not put it into a class library and reference that instead? That way you don't have to copy/paste.
|
|
|
|
|
|
we need to create a application which has a pin button on title bar.
if its clicked the application should get hide on top of the desktop as like connection bar in remote desktop application.
can some one pls tell me how to do that... mearly searched for 1 week but still could't find. connection bar example []
|
|
|
|
|
How to write dataset to mpp file
|
|
|
|
|
Hi fellows, a question from my side again! Would really need your expertise!
Is therer a way (maybe with Reflection) to get the definition of a Function?
Description:
I have a self defined Function (yeah I know dynamic, but here it's really neccessary, would take too long to explain):
dynamic func = new Func<int,int>((int i)=>{return 2*i;});
Chance to get to display the part {return 2*i;} programatically? (something like
MessageBox.Show("Function Code: {0}", functionCode);
(int i)=>{return 2*i;} would be fine as well, just if it makes any difference
Thank's in advance!
|
|
|
|
|
|
Thank you for the link, although it seems what I need to achieve cannot be done - at least not with C#. Looks like I have to save the function definition in an attribute.
D'oh
|
|
|
|
|
I want to get an exception when I am running a program on virtual machine. I use VIX API and RunProgramInGuest...
try
{
vmx.RunProgramInGuest(@"C:\Windows\system32\My
Program.exe", "", true, false, false);
}
catch {....?}
Thank you
|
|
|
|
|
I'm not sure you can just catch exception from another process just like that if MyProgram.exe isn't aware of what you want to do.
To be honest, this scenario isn't much different on catching exception from another process on other physical machine or even on the same machine.
If you have control over MyProgram.exe you can write its default error handler to notify your main application on any exception. For hints look there http://lmgtfy.com/?q=inter+process+communication[^] and especially on http://msdn.microsoft.com/en-us/library/windows/desktop/aa365574(v=vs.85).aspx[^]
Hope this helps.
--
"My software never has bugs. It just develops random features."
|
|
|
|
|
You may want to read this[^] article. Pay particular attention to the section "Transforming Error Codes into Exceptions".
|
|
|
|
|
Hi Newbie here,
I've starting using C# a while ago and started a nice project to help my company maintiance PC profiles.
This application i'm writing connects to AD and retrieves a users email and with the push of a button changes a users profile to <username>.old so he can login agian with a fresh windows profile.
I want to protect the communication with AD and the application by puttin the password in a secure string.
And i was looking for some feedback if i have done this correctly.
The follwing code bit shows the secure string and Authenticate a bit of the Authenticate process.
Any suggestions or critisism is welcome.
Thanks in advance.
private void btnLogIn_Click(object sender, EventArgs e)
{
string PwProtect = txtPassword.Text;
char[] PasswordChars = PwProtect.ToCharArray();
SecureString Password = new SecureString();
foreach (char c in PasswordChars)
Password.AppendChar(c);
if (Authenticate(txtLogIn.Text, txtPassword.Text))
{
gbxProfiel.Show();
txtPassword.Clear();
return;
}
|
|
|
|
|
From your code snippet you are putting the password into the SecureString .
But then you are not using it any further is there any code that is missing from your example?
But according to this msdn article: SecureString[^]. You are assigning the characters to the string correctly.
Edit: Good article that I have just read on converting the secure string back to a string
http://blogs.msdn.com/b/fpintos/archive/2009/06/12/how-to-properly-convert-securestring-to-string.aspx[^]
Lobster Thermidor aux crevettes with a Mornay sauce, served in a Provençale manner with shallots and aubergines, garnished with truffle pate, brandy and a fried egg on top and Spam - Monty Python Spam Sketch
|
|
|
|
|
Thank you for the response ,
Looked at the article you put in your reply and figured it out it works and the passwords protected.
|
|
|
|
|
Hi Experts,
I am searching for a way to edit app.config connection strings using .msi file. Since it needs to be installed by other people. I dont want others to explicitly go into file and edit the server address and db username and password.
I want to have a nice interface or an .msi file would be a very good option. Can someone guide me with a starting point on this issue.
Your help is highly appreciated.
|
|
|
|
|
Is not app.config part of application assembly? Modifying it would be modifying assembly. Would be easier to just add separate configuration file?
No more Mister Nice Guy... >: |
|
|
|
|
|
I don't think the installer is the right place for this. Instead, on startup, if you haven't got the settings you need, direct the user to the 'database settings' dialogue.
|
|
|
|
|
sathish17 wrote: Can someone guide me with a starting point on this issue
Google using the following phrase
microsoft installer custom action
|
|
|
|