Easier access to PropertyInfo

M

Marco Spatz

Hi,

This is my first post on this mailing list as I am quite new to the c#
programming language. So please be patient ;)

I am currently developing a small framework that can connect two properties
of two objects. Therefore I create a Connection object, that gets the input
object i and the PropertyInfo of the property that should be used as input,
and an output object o and the PropertyInfo of the property that acts as
the output. A call for creating the connection currently looks like this :

graph.AddConnection(
i, i.GetType().GetProperty("Input"),
o, o.GetType().GetProperty("Output"));

This is ok, but not satisfying for me :D.
I want the user of the framework to be able to create a connection like
this:

graph.AddConnection(i.Input, o.Output);

So by calling the properties "getter method" I want to get the object the
getter method is called on and the property info the getter method has
called for.

I don't even know if this possible, but would be great ;)

Thx for your help,

Marco
 
M

Marc Gravell

I want the user of the framework to be able to create a connection like
this:
graph.AddConnection(i.Input, o.Output);

A few options leap to mind:
Te simplest is just a half-way house is to handle the lookup inside the
method:
graph.AddConnection(i, "Input", o, "Output");
But of course it still isn't compiler-verified.

You could do various things involving delegates and lambdas, including
treating a lambda as the missing "infoof" operator, which would allow
you to refer to a property directy (and safely), but simply: they are
all quite complicated.

That said, you are also duplicating a lot of what Binding does (at least
for the UI).

You haven't really indicated how it would be *used* (i.e. end-to-end,
not just creation), which probably counts for a lot in terms of giving
the best reply...

Marc
 
M

Marco Spatz

Hi Marc,

thanks for your fast answer.
A few options leap to mind:
Te simplest is just a half-way house is to handle the lookup inside the
method:
graph.AddConnection(i, "Input", o, "Output");
But of course it still isn't compiler-verified.

But it's easier than my current approach, so if everything fails, I'll do
it that way.
You could do various things involving delegates and lambdas, including
treating a lambda as the missing "infoof" operator, which would allow
you to refer to a property directy (and safely), but simply: they are
all quite complicated.

That said, you are also duplicating a lot of what Binding does (at least
for the UI).

I don't worry about complicated solutions for this problem, as long as the
usage for the user of the framework get's simpler :D.. But I'm sorry, I
forgot to mention that I'm using C# 2.0, so lambdas won't apply here I
think :(
You haven't really indicated how it would be *used* (i.e. end-to-end,
not just creation), which probably counts for a lot in terms of giving
the best reply...

Ok, so here's what the framework should be used for:

The (dev) user can creates a tree graph by adding custom nodes and creating
connections. The connections are made between properties of nodes. Those
properties are marked declarative by using an [Input] or [Output]
attribute.
The nodes transfers the data from inputs to outputs on update calls, and
the connection transports the data from one node's output tp the connected
input of another node.

In my current domain, the tree represents a query to a custom datamodel.
The creation of the query is supported by a UI.

After creating the query tree, the user sets an input collection and calls
evalute on the tree. Inside, the tree nodes and connections are sorted to
be evaluated in the correct order, and then their update methods are
called.

The result of the query is the output of the last node.

Bye,

Marco
 
M

Marc Gravell

Just to warn you that this sounds *awfully* like what System.Expression
does... even if just to rule it out, you might want to see what .NET 3.5
and C# 3 bring to this...

Marc
 

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