Click here to Skip to main content
15,885,872 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
I want to know how to create a dynamically named instance of a dynamic object.
I am using Dynamic Objects already and so I do not want to add in reflection on top of that .. I am trying to keep it simple and bare bones as fast as a dynamic object will go.

So for example the code:
C#
dynamic Bee = new DynamicObject();


I would like to do :
C#
string instanceName = "SomeWeirdName";
dynamic 'instanceName' = new DynamicObject();


Is there a way to do this ?
If so with out a huge hit on performance ?
I do not want to go the moon just to get next door.

I read this Instance Name as A Variable which is for Java but I am looking for C# or VB.NET - I can convert the VB.
Posted

1 solution

Store your objects in a Dictionary<string,> so you can do

dict["SomeWeirdName"] = new DynamicObject();
 
Share this answer
 
Comments
stixoffire 23-Jul-15 16:51pm    
That sounds interesting , but if I do that - each time I set a property on that dynamic object it is a dictionary lookup -, one of the steps I was looking to avoid. because if it is dynamic, my valueItem has an identifier and I can use valueItem.Identifer so my object would be instantiated with the valueUniqueIdentifier as its name and then setting the values is easy , and when I am done I just update my other class
myOtherClassInstance = (MyOtherClass)MyDynamicObject();
I might save a little time this way but I am not sure..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900