. Topicala Page Index Token

A Journal about the experiences I have developing little applications in C#, Perl, Html and Javascript and talking about things new things that I use. Always Geeky; Always Nerdy; Always poor Grammer!

I am a Software Analyst Developer working in Southport, England but living in Liverpool. I develop mainly in C# and ASP.Net. I have been developing comercial software for several years now. I maintain this site (hosted at SwitchMedia UK) as a way of exploring new technologies (such as AJAX) and just generally talking about techie geek issues. This site is developed through a host of Perl scripts and a liberal use of Javascript. I enjoy experimenting with new technologies and anything that I make I host here.

Quick Search

Web www.kinlan.co.uk

Monday, November 07, 2005

Google Search: c# expando

One of the queries that came to my site the other day was: c# expando. Now you could take this to mean one of several things:
  1. Creating Javascript Expando Objects in C#
  2. Creating C# Expando classes for use in C#
  3. Something Else

If it is something else, email me: paul.kinlan@gmail.com and I will see if I can shed any light.

If however it is choice 1, I know how to do this, but it can be quite a big subject. In IE it is really simple to do, you can simply use an attribute on a class and there you have an expando. Basically an expando is an arbitary object that is attached created at runtime on another. If you want you can also use setAttribute on the object and add a variable that way.

function Kinlan()
this.Test = 1;

var currKin = new Kinlan();

currKin .Test = 2;
currKin .Bleep = "bleeeep";

The Object currKin, will have two properties, one test, the other Bleep. It is that simple.

To do it in C# when creating javascript wouldn't be too different. You would just have to make sure your Javascript looked like that above. You could also attach new attributes to HTML Elements from C# which would be "expandoesk". Say you had a table t and you wanted to have a flag on it called readyToDelete you could add it to the Page via something similar to:

HTMLTable t = new HTMLTable();
t.Attributes.Add("readyToDelete", "false");

The above code would create a HTMLTable with an attribute called readyToDelete with the value false.

Going back to the begining; if it was option 2, I am not too sure how you would achieve dynamic addition of properties or variables to an object, but I assume it would involve Reflection and a lot of extra leg work. I know that there is also such a thing as an ExtenderProvider, but again I am not too sure how it works [Tooltips in Winforms extend the Class that it is attached too by providing an new Propery called "ToolTip"].

I have also heard that C# 3.0 may provide this type of functionality but that is just hearsay, I haven't actually read the spec.

I will look up the Reflection methods; the ExtenderProvider and also C# 3.0 spec.

Technorati Tags
[feed], [feed], [feed], [feed], [feed], [feed], [feed], [feed]

Related Wikipedia Documents
, , , , , , , , , ,

My Related Documents
, , ,

Related Amazon Books
, , , , , , ,

Comments: [Add New]