Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4030108
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T11:25:48+00:00 2026-05-20T11:25:48+00:00

I have a Visual Studio 2008 C# .NET 3.5 project where I accept a

  • 0

I have a Visual Studio 2008 C# .NET 3.5 project where I accept a non-reference DLL as a plugin. The plugin implements an arbitrary number of classes derived from a known interface. Each class implements a set of known functions from that interface, but may also implement unknown functions that have a known attribute.

[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
public class SomeAttribute : Attribute
{
    public SomeAttribute(string description) { /*...*/ }
}

public class PluginClassA : IPluginInterface
{
    public PluginClassA(int some_val) : base(some_val)
    {
    }

    public override void Begin() { /*do interesting things...*/ }
    public override void End() { /*do interesting things...*/ }

    [SomeAttribute("Attribute Title")]
    public void SomeUnknownFunction() { /*do interesting things...*/ }

    [SomeAttribute("Attribute Title")]
    public void SomeOtherFunction() { /*do interesting things...*/ }
}

I’d like to be able to Load that plugin DLL and execute its functions in this order:

  1. Begin()
  2. Each function with the attribute SomeAttribute
  3. End()

I have something like this:

static void Main(string[] args)
{
    Assembly u = Assembly.LoadFile("Plugin.dll");
    foreach (Type t in u.GetTypes())
    {
        if (t.GetInterface("IPluginInterface") != null)
        {
            IPluginInterface plugin = (IPluginInterface)Activator.CreateInstance(t, new int());
            plugin.Begin();

            foreach (MemberInfo mi in t.GetMembers())
            {
                if (mi.IsDefined(typeof(SomeAttribute), true))
                {
                    // we found a member with the `SomeAttribute` attribute.
                    // how can I execute that method?
                    // I'd need something like a C++ function pointer to the function.
                }
            }

            plugin.End();
        }
    }
}

Thanks,
PaulH

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T11:25:48+00:00Added an answer on May 20, 2026 at 11:25 am

    Once you have a MethodInfo, you can use Invoke on that. If the MemberInfo returned from GetMembers actually points to a method, you can cast it to MethodInfo. So you can use this code once you have the member info:

    var method = mi as MethodInfo;
    if (method != null) 
        method.Invoke(plugin, null);
    

    You can also create a delegate that represents the method. This is more suitable if you need to call it more than once.

    Action action = (Action) Delegate.CreateDelegate(typeof(Action), plugin, method);
    // Calls the method pointed to by the MethodInfo 
    action();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a visual studio 2008 solution that includes an asp.net-hosted remoting project in
I have in my Visual Studio 2008 .NET C# project one property observed and
I have a Visual Studio 2008 .NET 3.5 Web forms project that constantly shows
I have in Visual Studio 2008 a .NET 3.5 C# project that uses a
I have a Visual Studio 2008 C# .NET 2.0 CF project with an abstract
I have C# .net project with SQL Server 2008 written in Visual Studio 2008.
I have a problem with a C# ASP .NET project in Visual Studio 2008
Vista SP1 Visual Studio 2008 SP1 .NET 3.5 SP1 C# I have a winforms
I am writing a website with Visual Studio 2008 and ASP.NET 3.5. I have
I have Visual Studio 2008 SP1 and ASP.NET MVC RC installed on a XP

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.