accesing a forms property from a different namespace

I have a windows application that falls under the namespace MyApplication for instance. I've created a class library, which falls under the namespace MyClassLibrary that needs to access a public property of a form in MyApplication when it is passed into a class in MyClassLibrary. But MyClassLibrary doesn't recognize MyApplication namespace because I can't import it's namespace because it is an application therefore it's output is an .exe file and not a .dll... How can I access the property in MyApplication from MyClassLibrary?
dotnet22Asked:
Who is Participating?
 
nouloukCommented:
in your app:
string message=MyClassLibrary.myfunction("Hello");
Console.WriteLine(message);

The string is setting depending on what the function returns. This is a typical language object oriented.
0
 
nouloukCommented:
A library is made to work alone.
The best way to do what you want is to define a public property in your library, set or modify the property with your app and when the property changes, do the job with your library.
You can do the same with a function if you need a result:
in MyClassLibrary:
public string myfunction(string test)
{
return test;
}
in your app:
string message=MyClassLibrary.myfunction("Hello");
Console.WriteLine(message);

Hope this helps.
0
 
chintan_vaishyaCommented:
HI,

You can access the property of MyApplication from MyClassLibrary by either passing it to one of the methods in the myClassLibrary or u can make local variables in MyClassLibrary by passing the properties in MyApplication in to the MyClassLibrary Constructor.

Like,
In MyApplication,

public string YourLocalProperty;
MyClassLibrary newObject = new MyClassLibrary(YourLocalProperty);

In MyClassLibrary,
public MyClassLibrary(string propertyFromMyApp)
{
string myProperty = propertyFromMYApp;
// now use it anywhere
}

Or you can also create objects which will contain the values and pass it to the myclasslibrary (but the myclasslibrary should also include that class)

Hope this will be useful.
Good Luck.
Chintan.
0
 
dotnet22Author Commented:
One thing I forgot to mention is that not only do I need to access it, I need to change the value in the calling application...
0
 
dunglaCommented:
dotnet22,

I think access property of winform from class library project is not the proper way. Bring your property to another DLL, just like object-oriented.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.