Okay so I've got a delegate called "InstructionRun " (just a simple void with no parameters), and a class called "Instructio n" which contains a delegate InstructionRun object as a member variable, as well as a method called "Run" which just calls the InstructionRun object's current functionality. There is also a byte in this class called "code".
Another class ("Instructions" ) has a static array of Instruction objects. It also has a static method whose purpose is to initialize all the Instruction objects.
And then somewhere else are a bunch of static void() methods that will be stored into the "InstructionRun " object for each Instruction object in the array.
My predicament is that I would like something like a simple text file or database to provide me with the data for this Instruction array. I want it to have a bunch of pairs, my "code" byte and then my static void() method. However, I would not want to resort to any of the following:
1) Not using a data file and just putting hundreds of "new Instruction()" lines to fill the array. I hate mass blocks like that when the design could change and then I have to change hundreds of those lines. I want something like a simple text file to just match up "code"s with functionality.
2) Putting the method's actual name in the data file, and then using reflection to read it during runtime and match it up with a method. Just seems sluggish and icky.
Please help out! If I wasn't clear on something, I can explain more.
8 1628 tlhintoq 3,525
Recognized Expert Specialist
I'm guessing the end goal is to change the order of start-up events by changing the config.txt file. But ...
[not] Putting the method's actual name in the data file
yet
Not using a data file and just putting hundreds of "new Instruction()" lines to fill the array. I hate mass blocks like that when the design could change and then I have to change hundreds of those lines.
Implies that you do have hundreds of methods, that all match the same delegate.
So, what... You're trying to create a text like
27, add
19, remove
89, load
Something like that?
That will eventually become a sequence that effectively does
Add(LoadedByte) ; // LoadedByte being 27
Remove(LoadedBy te); // LoadedByte being 19
Load(LoadedByte ); // 89 LoadedByte being 89
Do I interpret the goal correctly?
You are pretty much correct. I will have hundreds of methods, which is why I chose a delegate system as I don't want this: - switch (code)
-
{
-
case 0x28:
-
RunADD();
-
break;
-
case 0x2A:
-
RunJMP();
-
break;
-
//so on...
-
}
However, they are parameterless methods...they don't take a byte (actually I haven't decided that yet, they MIGHT have parameters down the line, but that's not important right now, right now I just need some way to match up the bytes with methods), but rather the byte determines which method to call.
So yes, my text would be something like:
28 RunADD
2A RunJMP
...
etc.
and then there would just be:
static void RunADD()
static void RunJMP()
...
etc.
tlhintoq 3,525
Recognized Expert Specialist
Got it. Looks like you are making an assembly language simulator/translator.
Why not just make the methods match the bytes then? If you have a byte of 2A then run static void 2A(), which is the JMP instruction? Why do the lookup table at all?
That would be fine, I don't care what the methods are named....but even then, how would I go about matching up that byte coming in to that function named "2A"? Do I have to resort to reflection?
tlhintoq 3,525
Recognized Expert Specialist
Do I have to resort to reflection?
You say that like it's a bad thing. What are you trying to avoid about reflection, or what is it that makes your project hard to deal with reflection?
Nothing in particular, wouldn't it just slow it down? It seems a little excessive...get ting a method name from a file, passing the string to look up a symbol name of the very program you're running in currently...whe n all you really need to do (though it might be uglier) is just call the damn method in the program. I was merely trying to look for a non-ugly way, maybe, avoiding reflection.
Thanks for being patient with me.
tlhintoq 3,525
Recognized Expert Specialist - using System;
-
using System.Reflection;
-
-
class CallMethodByName
-
{
-
string name;
-
-
CallMethodByName (string name)
-
{
-
this.name = name;
-
}
-
-
public void DisplayName() // method to call by name
-
{
-
Console.WriteLine (name); // prove we called it
-
}
-
-
static void Main()
-
{
-
// Instantiate this class
-
CallMethodByName cmbn = new CallMethodByName ("CSO");
-
-
// Get the desired method by name: DisplayName
-
MethodInfo methodInfo =
-
typeof (CallMethodByName).GetMethod ("DisplayName");
-
-
// Use the instance to call the method without arguments
-
methodInfo.Invoke (cmbn, null);
-
}
-
}
Okay, thanks for your help.
I just have seen that most people, including even in this community, frown upon retrieving a variable via a string (its name). I figured the same would apply here. But I guess in some cases it is acceptable for such behavior, especially when it would simplify the code so greatly.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Don Vaillancourt |
last post by:
Hello all,
Over the years as I design more database schemas the more I come up with
patterns in database design. The more patterns I recognize the more I
want to try to design some kind of generic design patterns that can be
used and shared amongst many sub-schemas.
For example, the grouping of entities. I may have the following tables:
employee, product and client. These tables have no direct relationship
with each other. But...
|
by: sk |
last post by:
I have an applicaton in which I collect data for different parameters
for a set of devices. The data are entered into a single table, each
set of name, value pairs time-stamped and associated with a device.
The definition of the table is as follows:
CREATE TABLE devicedata
(
device_id int NOT NULL REFERENCES devices(id), -- id in the device
|
by: Test User |
last post by:
Hi all, (please excuse the crosspost as I'm trying to reach as many people
as possible)
I am somewhat familiar with Access 2000, but my latest project has me
stumped. So, I defer to you experts.
I've been asked to create a Daily Log sheet to be distributed to some of our
clerks.
For each day, the clerk is to log tasks worked on for the day, (i.e worked
on the johnson account).
|
by: rodchar |
last post by:
Hey all,
I'm trying to understand Master/Detail concepts in VB.NET. If I do a data
adapter fill for both customer and orders from Northwind where should that
dataset live?
What client is responsible for instantiating the orders class? Would it be
the ui layer or the master class in the business layer?
thanks,
|
by: tshad |
last post by:
Many (if not most) have said that code-behind is best if working in teams -
which does seem logical.
How do you deal with the flow of the work?
I have someone who is good at designing, but know nothing about ASP. He can
build the design of the pages in HTML with tables, labels, textboxes etc.
But then I would need to change them to ASP.net objects and write the code
to make the page work (normally I do this as I go - can't do this...
| |
by: roN |
last post by:
Hi,
I'm creating a Website with divs and i do have some troubles, to make it
looking the same way in Firefox and IE (tested with IE7). I checked it with
the e3c validator and it says: "
This Page Is Valid XHTML 1.0 Transitional!" but it still wouldn't look the
same.
It is on http://www.dvdnowkiosks.com/new/theproduct.php scroll down and
recognize the black bottom bar when you go ewith firefox(2.0) which isn't
there with IE7. Why does...
|
by: JoeC |
last post by:
I have a question about designing objects and programming. What is the
best way to design objects? Create objects debug them and later if you
need some new features just use inhereitance. Often times when I
program, I will create objects for a specific purpose for a program and
if I need to add to it I just add the code.
|
by: |
last post by:
I have a question about spawning and displaying subordinate list controls
within a list control. I'm also interested in feedback about the design of
my search application. Lots of code is at the end of this message, but I
will start with an overview of the problem.
I've made a content management solution for my work with a decently
structured relational database system. The CMS stores articles. The CMS also
stores related items --...
|
by: neelsmail |
last post by:
Hi,
I have been working on C++ for some time now, and I think I have a
flair for design (which just might be only my imagination over-
stretched.. :) ). So, I tried to find a design certification, possibly
that involves C++, but, if not, C++ and UML. All I could find was Java
+ UML design certifications (one such is detailed on
http://www.objectsbydesign.com/tools/certification.html). Although UML
is expected to be language independent,...
|
by: indrawati.yahya |
last post by:
In a recent job interview, the interviewer asked me how I'd design
classes for the following problem: let's consider a hypothetical
firewall, which filters network packets by either IP address, port
number, or both. How should we design the classes to represent these
filters?
My answer was:
class FilterRule
{
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |