Expando

  • Thread starter Thread starter Mike Caputo
  • Start date Start date
M

Mike Caputo

I'm trying to figure out how to use this class/interface to dynamically
create properties. I've looked at all the documentation, but I can't find
any real sample code, and I'm really not sure how to get started. Does
anyone have either a self-written example or a link to one? I'd appreciate
it.

Mike

--
 
Hi Mike,

|| I'm trying to figure out how to use this class/interface
|| to dynamically create properties.

Which class ?

In fact, which language? - Expando is JavaScript.

Do you mean that you want the same functionality in VB ?

Regards,
Fergus
 
Hello,

Fergus Cooney said:
Which class ?

In fact, which language? - Expando is JavaScript.

Do you mean that you want the same functionality in VB ?

I think the OP is referring to the 'IExpando' interface in the namespace
'System.Runtime.InteropServices.Expando'.
 
Hi Herfried,

LOL. Thanks. Never heard of it. But it sounds interesting. On to the list
it goes. :-)

Regards,
Fergus
 
Hello,

Fergus Cooney said:
LOL. Thanks. Never heard of it. But it sounds interesting.
On to the list it goes. :-)

Do you have a sample for using this interface?!
 
Hi Herfried,

|| > Thanks. Never heard of it.
||
|| Do you have a sample for using this interface?!

Are you asking or offering? I had never heard of Expando in .NET until you
told me about it.

A quick look on Google gives nothing!! (Usage-wise)

Regards,
Fergus
 
Hello,

Fergus Cooney said:
Are you asking or offering? I had never heard of Expando in
.NET until you told me about it.

A quick look on Google gives nothing!! (Usage-wise)

I have heard about it but I didn't find any samples too.

;-(
 
A look in msdn does and when I saw it my first thought were not my stuff
it's Fergus Cooney stuff.
 
Mike,
In addition to the others comments. Are you referring to
System.Runtime.InteropServices.Expando.IExpando?

To the best of my knowledge it is there to support 'Dynamic Scripting'
languages such as JScript.NET. It is also used with COM Interop to enable
the IDispatchEx interface (again 'dynamic scripting' languages).

If you look at the Microsoft.JScript assembly there are a number of classes
that implement IExpando.

Also JScript.NET has an expando keyword that 'declares that instances of a
class support expando properties or that a method is an expando object
constructor'.

What specifically are you trying to accomplish?

Remember that VB.NET is a compiled language, in order to use 'dynamic
properties' you will need to use late binding. I hope you realize that late
binding is not always such a good idea.

What I normally do to implement 'dynamic properties' is to have a default
indexer on my class that accepts a string as the key. This enables the !
operator, so the property looks very much dynamic.

Public Class Expando

Private readonly m_properties As New HashTable

Default Public Property Item(key As String) as Object
Get
return m_properties(key)
End Get
Set(value As Object)
m_properties(key) = value
End Set
End Property

End Class

Then when I need to use it:

dim expando as New Expando

expando!Name = "Mike "
expando("Name") = "Mike "
expando.Item("Name") = "Mike "

As you notice all three syntaxes work.

Of course you need to make the property Object to support any type, which
means you need to cast the property when you take it out, if you are using
Option Strict On, you are using Option Strict?

Hope this helps
Jay
 
Back
Top