.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

best way to org my code

4 REPLIES 4
Reply
Message 1 of 5
wesbird
427 Views, 4 Replies

best way to org my code

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

 

Windows 10 64 bit, AutoCAD (ACA, Map) 2023
4 REPLIES 4
Message 2 of 5
Keith.Brown
in reply to: wesbird

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.

Message 3 of 5
wesbird
in reply to: Keith.Brown

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

 

Windows 10 64 bit, AutoCAD (ACA, Map) 2023
Message 4 of 5
Keith.Brown
in reply to: wesbird

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.

Message 5 of 5
augusto.goncalves
in reply to: wesbird

If you create a DLL project, the Assembly.cs will have the assembly name. If you make a copy but maintain the assembly name, the .NET engine will not load twice. If you need 2 DLLs returning different value for constants (defined on compile time), you need 2 different assembly names. Hope I understood you correctly.
Regards,



Augusto Goncalves
Twitter @augustomaia
Autodesk Developer Network

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Forma Design Contest


Autodesk Design & Make Report