Congratulations to all the winners of April 2013, they have won INR 3400 cash and INR 20147 worth prizes !
DotNetFunda.Com Logo
Twitter TwitterLinkedIn
YouTubeGoogle
 Online : 3640 |  Welcome, Guest!   Register  Login
 Home > Blogs > C# > ExpandoObject in C# 4.0, it's really dynamic ...
Amitkpatel

ExpandoObject in C# 4.0, it's really dynamic

 Blog author: Amitkpatel | Posted on: 6/25/2012 | Category: C# Blogs | Views: 864 | Status: [Member] | Points: 75 | Alert Moderator   


Introduction:- ExpandoObject  it like a expand property in HTML. Microsoft introduces new class ExpandoObject. It's really dynamic object.  It is part of DLR (dynamic language runtime).

The ExpandoObject class enables you to add and delete members of its instances at run time and also to set and get values of these members. This class supports dynamic binding, which enables you to use standard syntax like sampleObject.sampleMember instead of more complex syntax like sampleObject.GetAttribute("sampleMember").


Purpose:- To create a runtime instance of any type. You can add properties, methods, and events to instances of the ExpandoObject class.

Code:-

Here we are creating dynamic instance.
dynamic Employee = new ExpandoObject();
       Employee.ID = 1;
       Employee.Name = "Amit";
       Employee.Salary = 10000;

Nested dynamic instance

       Employee.Addess = new ExpandoObject();
       Employee.Addess.City = "Pune";
       Employee.Addess.Country = "India";
       Employee.Addess.PinCode = 456123;

Bind dynamic Event

Employee.Click += new EventHandler(SampleHandler);

private void SampleHandler(object sender, EventArgs e)
{
//throw new NotImplementedException();
}

Pass parameter as dynamic.

public void Write(dynamic employee)
{
//you can write your logic
}

Happy coding..





Amit Kumar Patel
http://blog.iquestionanswer.co.in
http://www.iquestionanswer.co.in
Found interesting? Add this to:


About Amit Patel

Experience:8 year(s)
Home page:http://www.dotnetchuks.com
Member since:Friday, June 22, 2012
Level:Starter
Status: [Member]
Biography:I am Amit Patel, I have 8yrs of experiences in Microsoft technologies. I am very much passionate about Web technology. My core skill is ASP.NET, WCF, C#, JQuery and CSS
>> Write Response - Respond to this post and get points

More Blogs

About Us | Contact Us | The Team | Advertise | Software Development | Write for us | Testimonials | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
General Notice: If you find plagiarised (copied) contents on this page, please let us know the original source along with your correct email id (to communicate) for further action.
Copyright © DotNetFunda.Com. All Rights Reserved. Copying or mimicking the site design and layout is prohibited. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks. | 5/18/2013 11:57:34 AM