Link to home
Start Free TrialLog in
Avatar of dotnet22
dotnet22

asked on

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?
Avatar of noulouk
noulouk

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.
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.
Avatar of dotnet22

ASKER

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...
ASKER CERTIFIED SOLUTION
Avatar of noulouk
noulouk

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.