Hi,
I'm re-organize my code and have problem.
I have 2 VS solutions, ProjA and ProjB. I extract common function to 3rd DLL, common.dll. There are some const string in common.dll are different for ProjA and ProjB, like project name.
I tried make 2 copies of common.dll with different project name.
after I start AutoCAD,
NETLOAD ProjA, print out project name = ProjA, then NETLOAD ProjB, project name = ProjA (which is wrong)
if NETLOAD ProjB alone, then project name = ProjB
What's best way to implement this?
Thank you so much
Wes
It seems to me that project name is not common to both dlls, therefore the project name should exist in the individual projects instead of in the common code. If you need it in the common code then just pass it in as an argument.
If you share how you are using the constants we might be able to give you a better answer.
Thank you, Keith.
Here is one example:
in common.dll,
public static void MessageBoxError(string str) { MessageBox.Show(str, Class1.Project_Name, MessageBoxButtons.OK, MessageBoxIcon.Error); }
here is how Project_Name defined:
public class Class1
{
public static string Project_Name = "ProjA"; // for ProjA; it will be ProjB for ProjB
}
I already tried to assign in ProjA/ProjB's IExtensionApplication Initialize, does not work.
I use this function a lot, everywhere.
Any idea? Thank you so much.
Wes
The easiest way is to just add the title to your MessageBoxError method. Something like this.
public static void MessageBoxError(string str, string title) { MessageBox.Show(str, title, MessageBoxButtons.OK, MessageBoxIcon.Error); }
But if you really have your heart set on automating then you can use Assembly.GetCallingAssembly to get the assembly that called the MessageBoxError method. You can then use a Custom Attribute of the assembly to get your title. See this article. Or, if your assembly titles are the actual name that you want to use then you could just use Assembly.GetCallingAssembly().FullName. So your messagebox method would like something like this.
public static void MessageBoxError(string str) { MessageBox.Show(str, Assembly.GetCallingAssembly().FullName, MessageBoxButtons.OK, MessageBoxIcon.Error); }
The obvious advantage to using this method is that you do not need to modify any existing code other than your MessageBoxError method.
You will need to add a reference to System.Reflection I believe to use Assembly.GetCallingAssembly()
Also, none of this was tested, it was just an idea off the top of my head. Please note the difference from GetCallingAssembly and GetExecutingAssembly. I will leave it up to you to google them both.
Can't find what you're looking for? Ask the community or share your knowledge.