Design question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Tem

    Design question

    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.Met hodA("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

  • =?Utf-8?B?Q2lhcmFuIE8nJ0Rvbm5lbGw=?=

    #2
    RE: Design question

    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(s tring requiredInfo)
    {
    //do custom logic
    }

    public static void Main()
    {

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

    LibraryFile.Met hodA("some text", DoCustomLogic);

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


    public delegate void DoCustomLogicDe legate(string requiredInforma tion);
    public static int MethodA(string content, DoCustomLogicDe legate 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 O''Donnell
    try{ Life(); } catch (TooDifficultException) { throw Toys(); }



    "Tem" wrote:
    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.Met hodA("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
    >
    >

    Comment

    • Tem

      #3
      Re: Design question

      Ciaran

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

      Thx

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

      customLogic();

      // do something after

      return content;
      }


      "Ciaran O''Donnell" <CiaranODonnell @discussions.mi crosoft.comwrot e in
      message news:BA52DF6A-89BA-4C0F-93D7-E6072777C0A3@mi crosoft.com...
      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(s tring requiredInfo)
      {
      //do custom logic
      }
      >
      public static void Main()
      {
      >
      //***inject some code to the Library file assembly***
      >
      LibraryFile.Met hodA("some text", DoCustomLogic);
      >
      }
      }
      --------------in a different assembly
      Class LibraryFile
      {
      >
      >
      public delegate void DoCustomLogicDe legate(string requiredInforma tion);
      public static int MethodA(string content, DoCustomLogicDe legate
      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 O''Donnell
      try{ Life(); } catch (TooDifficultException) { throw Toys(); }

      >
      >
      "Tem" wrote:
      >
      >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.Me thodA("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
      >>
      >>

      Comment

      Working...