Design question

  • Thread starter Thread starter Tem
  • Start date Start date
T

Tem

I have 2 projects a classlibrary project and a windows forms project.

the winform app calls the library to perform certain functions and returns
the results.

however i run into a problem where the method in the library class requires
the windows forms app to do something then complete its tasks then returns
the results to the win form app.

Example:

class WinFormApp
{
public static void Main()
{

//***inject some code to the Library file assembly***

LibraryFile.MethodA("some text");

}
}
--------------in a different assembly
Class LibraryFile
{

public static int MethodA(string content)
{
//process content

//*** Where the injected code needs to be placed in the process ***

//Write content to file (file's format and attributes are defined in the
WinFormApp) to hard drive

return content;
}
}

There will be more than 1 winformapp that calls this library. each will have
a slightly different use. the *** will be different for each.
I use .net 3.5. im thinking a delegate would be suitable for this use. but
not sure how to write it.
can someone guide me to the right track?

Thx
Tem
 
It sounds like a weird design which I would normally advise is split into two
methods that can be called in turn by the winform with its custom code
inbetween. If this is not possible or you definately want this design then
you certainly could add a delegate type to the library and pass in a delegate
to the function call.

e.g


class WinFormApp
{


publci static void DoCustomLogic(string requiredInfo)
{
//do custom logic
}

public static void Main()
{

//***inject some code to the Library file assembly***

LibraryFile.MethodA("some text", DoCustomLogic);

}
}
--------------in a different assembly
Class LibraryFile
{


public delegate void DoCustomLogicDelegate(string requiredInformation);
public static int MethodA(string content, DoCustomLogicDelegate customLogic)
{
//process content

//*** Where the injected code needs to be placed in the process ***

//Write content to file (file's format and attributes are defined in the
WinFormApp) to hard drive

return content;
}
}
 
Ciaran

how do I execute customLogic in MethodA?
customLogic(); doesn't work

Thx

public static int MethodA(string content, DoCustomLogicDelegate customLogic)
{
// do something before

customLogic();

// do something after

return content;
}
 
Back
Top