C# Class library call automatic function or class in other project

hossein tavakoli 471 Reputation points
2021-11-25T13:13:19.95+00:00

I Have a class library ,that referenced to some WPF Projects.

I have a function or class in my class library, also I have function or class in WPF applications with same name.

I want when I call function in my class library , it automatic call (or use) function in WPF application.

152634-untitled.jpg

Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,710 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,649 questions
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. Bruce Barker 801 Reputation points
    2021-11-25T16:35:30.53+00:00

    Hopefully the shared class library uses a different namespace. Then just use the fully qualified method name.

    If for some reason they have the same namespace, then you can not include the library in the build. You will need to load at runtime and use reflection.

    1 person found this answer helpful.
    0 comments No comments

  2. Viorel 114.7K Reputation points
    2021-11-25T17:19:34.87+00:00

    For example, you can define an abstract class that does not have a specific definition of GetName function:

    // In Class Library:
    
    public abstract class ClassA
    {
        // . . .
    
        public void SomeFunction()
        {
            GetName( );
        }
    
        protected abstract void GetName( );
    }
    

    Then you can override it, providing the implementation that is suitable for the first WPF application:

    // In First WPF application:
    
    public class FirstWPFClassA : ClassA
    {
        protected override void GetName( )
        {
            // . . .
        }
    }
    

    The second application will give another implementation.

    It is also possible to use delegates and interfaces.

    0 comments No comments

  3. Karen Payne MVP 35,386 Reputation points
    2021-11-25T20:06:53.067+00:00

    Check out the following repository, using statement to alias classes followed by usage. which works with WPF and other project types.

    0 comments No comments