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

  • Home
  • SEARCH
  • 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 1010977
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T09:09:55+00:00 2026-05-16T09:09:55+00:00

I am trying to create a generic simulation runner. Each simulation implements a variety

  • 0

I am trying to create a generic simulation runner. Each simulation implements a variety of interfaces. Eventually, it will pick up simulation types via DLLs at run time, so I will have no way of knowing the types beforehand.

My Currrent Code:

public class SimulationRunner<TSpace, TCell>
    where TSpace : I2DState<TCell>
    where TCell : Cell
{
    public TSpace InitialState { get; set; }
    public IStepAlgorithm<TSpace,TCell> StepAlgorithm { get; set; }
    public IDisplayStateAlgorithm<TSpace,TCell> DisplayStateAlgorithm { get; set; }
    public int MaxStepCount { get; set; }
    ...
    public void Run() {...}
    public void Step() {...}
    public void Stop() {...}
}

I want my UI class to store a generic instance of the simulation runner (Eg

public partial class UI : Window
    {
        SimulationRunner<TSpace,TCell> simulation;
        ...
    }

so that i can assign different types of simulations to it.
Eg

simulation = new SimulationRunner<2DSpace, SimpleCell>(); 
// do stuff
// start new simulation of different type 
simulation = new SimulationRunner<3DSpace, ComplexCell>();

I want to have my UI controls wired to the simulation variable so i can do things like

private void mnuiSimulate_Click(object sender, RoutedEventArgs e)
{
    if (simulation != null) simulation.RunSimulation();
}

and have it work regardless of what types are currently bound to TSpace and TCell.

Currently I am getting errors saying “Error 10 The type or namespace name ‘U’ could not be found (are you missing a using directive or an assembly reference?)”, and the same again for T.

I have tried creating a controller class that wraps the SimulationRunner, but I still have the same problem in that I have to pass in the types of TSpace and TCell when I create it, so the problem just gets moved to a different class.

How can I store any type of simulation in a variable?
How can I bind the controls to work on any type of simulation?

  • 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-16T09:09:56+00:00Added an answer on May 16, 2026 at 9:09 am

    The solution is to take the non-generic methods and properties into a non-generic interface, so that the caller of the interface doesn’t have to know which type parameters the class accepts:

    public interface ISimulationRunner {
        public int MaxStepCount { get; set; }
        ...
        public void Run() {...}
        public void Step() {...}
        public void Stop() {...}
    }
    
    public class SimulationRunner<TSpace, TCell> : ISimulationRunner 
        where TSpace : I2DState<TCell>
        where TCell : Cell
    {
        public TSpace InitialState { get; set; }
        public IStepAlgorithm<TSpace,TCell> StepAlgorithm { get; set; }
        public IDisplayStateAlgorithm<TSpace,TCell> DisplayStateAlgorithm { get; set; }
    }
    
    public partial class UI : Window
    {
      ISimulationRunner simulation = new SimulationRunner<2DSpace, SimpleCell>();
      private void mnuiSimulate_Click(object sender, RoutedEventArgs e)
      {
        if (simulation != null) simulation.RunSimulation();
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create a generic class in PHP that will provide a way
I was trying to create a generic Dictionary that implements IXmlSerializable (credit to Charles
I am trying to create a generic method that will read an attribute on
I'm trying to create a generic class which will have some static functions based
I'm trying to create a generic data model that will allow for a particular
I am trying to create generic class in python which will do all the
I'm trying to create a generic template which will render out JSON objects. The
I'm trying to create a generic web service that will always respond with OK,
I am trying to create a generic interface for my classes that will satisfy
I'm trying to create a generic function in grails that will allow me to

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.