© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•2y ago•
5 replies
The Fog from Human Resources

How to set Object from Inherited class with Reflections

Im working on a framework for one of my libraries and my goal is to create a similar structure as Discord.NET
as stated in #How to create a structure like Discord.NET i have an issue with my
Context
Context
object
Setting it using
module.ModuleInteractionBase = (InteractionBase)Activator.CreateInstance(moduleType);
module.ModuleInteractionBase = (InteractionBase)Activator.CreateInstance(moduleType);
seems to work but the instance its setting seems to be different from what my command handler class inherits
        public class Commands : InteractionBase
        {

            [Command("ping", "Simple Ping Command")]
            [EnabledInDms(false)]
            [PermissionGroup(PermissionGroup.PermissionGroups.Agent)]
            public async Task HandleCommand(string arg1, string[] arg2 = null)
            {
                await Console.Out.WriteLineAsync(Context.InteractionName);
            }
        }
        public class Commands : InteractionBase
        {

            [Command("ping", "Simple Ping Command")]
            [EnabledInDms(false)]
            [PermissionGroup(PermissionGroup.PermissionGroups.Agent)]
            public async Task HandleCommand(string arg1, string[] arg2 = null)
            {
                await Console.Out.WriteLineAsync(Context.InteractionName);
            }
        }
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

How to share instance of an object in base class to its inherited classes?
C#CC# / help
3y ago
How are people dealing with mapping from a class object to generated object from protobuf?
C#CC# / help
2y ago
❔ accessing object from a class inside of another class
C#CC# / help
3y ago
Json string to a class object but not {get; set; } !
C#CC# / help
15mo ago