Modifying indexer and add function of existing class && Use functionsstored in C# dll without specif


M

michelQA

I'm having a funny problems and questions with classes. It's little
hard to explain so I'm focusing on the expected result needed to find
possible solution.

In a C# dll I want to create a kind of "Scripting language" to
manipulate UI elements class of the System.Windows.Forms.* classes.
The final goal is to being able to use Classes and or functions to
fits to the following needs.

Afer referencing the dll in a c# form project I want to interact with
the .dll like this :
Example 1 : Showing button7 button text
MessageBox.Show(Button("button7").Text);
//Note "Button" function must come from the .dll without any
initialisation

Example 2 : Click button1 button
Button("button1").Click(); //Not the event, a special click function
with particular param

Example 3 : Showing if ListView item "Item2" is selected
MessageBox.Show(ListView("listView1").Items("item2").Selected.ToString
());

=======================

Question 1 :
In ex1 button can be simply a function like this... (we dont care
about how I fill class/object/properties)

public static Button xButton(string RecString)
{
Button Btn = new Button();
//...
//We already get the properties and fill Btn properties by
communicating with our tcp test client here somehow...blablabla
//...
return (Button)Btn;
}
This works directly in the c# project but may be sounds like a stupid
question but how can I put this function in a C# dll without having to
previously create the instance with the class name... I want to avoid
MyDllClass.XButton in the C# project.

Question 2 : Having a Button() instead of a XButton() function is
totally impossible if I want to keep reference to System.Windows.Forms
in my dll ?

Question 3 : Is there a way to inherits from the ...Forms.ListView
class and change the way the Items[] indexers is working to
support .Items[TextItem].Selected (string index) instead of .Items
[0].Selected?? (int index) ...create an extra function Items() to
return the correct ListViewItem?

is Adding extra functions to existing Forms.* classes with inheritance
make sense?
For now, my only option is to remove System.Windows.Forms references
in my DLL and use "Custom made" classes almost identical to
System.Windows.Froms classes. Since the goal of my "scripting
language" is mostly to interact with existing object and get object
properties it can live with major limitations (Ex: the end users do
not create any UI element, the script have no UI too and will be used
by a tool to automate Software testing)

I really need to be pointed to interresting things a get some advises
to figure out the best way to do this. I only care about the way to
define this in a .dll and get some ideas to "fits" to an homebrew kind
of scripting language without previous initialisations hosted in a
full C# script done with CS-Script.
 
Ad

Advertisements

M

michelQA

Why?  Why is it a requirement that you "avoid MyDllClass.XButton in theC#  
project"?  It seems like a needless, arbitrary requirement to me.

You are right but the classname of XButton in the dll is totally
useless for the end user since 99% of lines of the script will starts
with that classname. The goal was to identify the object and the
action to execute at the same time in one simple line. Still thinking
about this.

For my question with indexers I realize that there are indexers with
string parameter in latest net framework...for some reasons I was
using a 1.1 net version when trying to figure out this... But there
stills indexer to modify like the Items of a ComboBox since I want
ComboBox("Combo1").Items("Item3").Select() and not ComboBox
("Combo1").Items[2].Select()

I need to think more about this and try different things...Since there
is no way to create a function Button(string button name) or ListView
(string ListViewName) and being able to call this without the
classname i'm considering moving theses function from the dll to the
user script by adding the code needed at the end of the script just
before the compiling process. But this is defenitively not a clean
solution but this can be improved or modified in a futur version.
 
M

michelQA

Why?  Why is it a requirement that you "avoid MyDllClass.XButton in theC#  
project"?  It seems like a needless, arbitrary requirement to me.

You are right but the classname of XButton in the dll is totally
useless for the end user since 99% of lines of the script will starts
with that classname. The goal was to identify the object and the
action to execute at the same time in one simple line. Still thinking
about this.

For my question with indexers I realize that there are indexers with
string parameter in latest net framework...for some reasons I was
using a 1.1 net version when trying to figure out this... But there
stills indexer to modify like the Items of a ComboBox since I want
ComboBox("Combo1").Items("Item3").Select() and not ComboBox
("Combo1").Items[2].Select()

I need to think more about this and try different things...Since there
is no way to create a function Button(string button name) or ListView
(string ListViewName) and being able to call this without the
classname i'm considering moving theses function from the dll to the
user script by adding the code needed at the end of the script just
before the compiling process. But this is defenitively not a clean
solution but this can be improved or modified in a futur version.
 
J

Jesse Houwing

Hello michelqa,
Why? Why is it a requirement that you "avoid MyDllClass.XButton in
the C# project"? It seems like a needless, arbitrary requirement
to me.
You are right but the classname of XButton in the dll is totally
useless for the end user since 99% of lines of the script will starts
with that classname. The goal was to identify the object and the
action to execute at the same time in one simple line. Still thinking
about this.

For my question with indexers I realize that there are indexers with
string parameter in latest net framework...for some reasons I was
using a 1.1 net version when trying to figure out this... But there
stills indexer to modify like the Items of a ComboBox since I want
ComboBox("Combo1").Items("Item3").Select() and not ComboBox
("Combo1").Items[2].Select()

I need to think more about this and try different things...Since there
is no way to create a function Button(string button name) or ListView
(string ListViewName) and being able to call this without the
classname i'm considering moving theses function from the dll to the
user script by adding the code needed at the end of the script just
before the compiling process. But this is defenitively not a clean
solution but this can be improved or modified in a futur version.

It also sounds like looking at Expression Tree's (a more functional approach)
and/or the DLR (Dynamic Language Runtime) migth be things worth investigating.

Expression trees to allow your own syntax for looking up and manipulating
things from within C# and the DLR for hosting a script context in your application
and to allow you to specify methods and context objects to work with.

Sounds more like the direction I'd be going in after reading your requirements.

Also. Dont' try to change the language. It's easier for people to have a
standard langauge for which there is thourough documentation, than to have
a script like language that comes without it. You'll be surprised to see
how many people can master at least the basics of Visual Basic .NET or C#
in a few days. Especially if you provide them with some easy to alter examples.
 
J

Jesse Houwing

Hello michelqa,
Why? Why is it a requirement that you "avoid MyDllClass.XButton in
the C# project"? It seems like a needless, arbitrary requirement
to me.
You are right but the classname of XButton in the dll is totally
useless for the end user since 99% of lines of the script will starts
with that classname. The goal was to identify the object and the
action to execute at the same time in one simple line. Still thinking
about this.

For my question with indexers I realize that there are indexers with
string parameter in latest net framework...for some reasons I was
using a 1.1 net version when trying to figure out this... But there
stills indexer to modify like the Items of a ComboBox since I want
ComboBox("Combo1").Items("Item3").Select() and not ComboBox
("Combo1").Items[2].Select()

I need to think more about this and try different things...Since there
is no way to create a function Button(string button name) or ListView
(string ListViewName) and being able to call this without the
classname i'm considering moving theses function from the dll to the
user script by adding the code needed at the end of the script just
before the compiling process. But this is defenitively not a clean
solution but this can be improved or modified in a futur version.

It also sounds like looking at Expression Tree's (a more functional approach)
and/or the DLR (Dynamic Language Runtime) migth be things worth investigating.

Expression trees to allow your own syntax for looking up and manipulating
things from within C# and the DLR for hosting a script context in your application
and to allow you to specify methods and context objects to work with.

Sounds more like the direction I'd be going in after reading your requirements.

Also. Dont' try to change the language. It's easier for people to have a
standard langauge for which there is thourough documentation, than to have
a script like language that comes without it. You'll be surprised to see
how many people can master at least the basics of Visual Basic .NET or C#
in a few days. Especially if you provide them with some easy to alter examples.
 
M

michelQA

Looks really interresting :) I'm trying to find something to start
with DLR and Expression tree...

For now i'm using CSScript for compiling and running C# file...The
code writing is done in our application. My goal was simply to add
some functions available directly in the script in one line. I want
to have the same control object like button, form, listview but with
ability to get the control with the control name directly in the
"expression"

Ex: Button("Btn").Text=something

instead of

Button Btn=new Button();
btn.Text = something

The properties are filled by our application..

I have to learn more about DLR and I will be back with more info or
maybe a possible solution... Since we are out of schedule on the
project we will maybe have to choose the ugly dirty cheap solution and
alter the code before compiling but I dont want to go that way for
obvious reasons. I hope DLR is not too complicate and can be an easy
alternative...Will see..

Thanks again for pointing to this direction :)
 
Ad

Advertisements

M

michelQA

Looks really interresting :) I'm trying to find something to start
with DLR and Expression tree...

For now i'm using CSScript for compiling and running C# file...The
code writing is done in our application. My goal was simply to add
some functions available directly in the script in one line. I want
to have the same control object like button, form, listview but with
ability to get the control with the control name directly in the
"expression"

Ex: Button("Btn").Text=something

instead of

Button Btn=new Button();
btn.Text = something

The properties are filled by our application..

I have to learn more about DLR and I will be back with more info or
maybe a possible solution... Since we are out of schedule on the
project we will maybe have to choose the ugly dirty cheap solution and
alter the code before compiling but I dont want to go that way for
obvious reasons. I hope DLR is not too complicate and can be an easy
alternative...Will see..

Thanks again for pointing to this direction :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top