Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 627177
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T19:30:00+00:00 2026-05-13T19:30:00+00:00

I have been struggling to get a simple DynamicObject example working in .NET 3.5.

  • 0

I have been struggling to get a simple DynamicObject example working in .NET 3.5.

Using the latest build of the DLR off codeplex I haven’t been able to figure out what the .NET 3.5 equivalent to the following is:

public class DynamicObjectBag : DynamicObject
{
    private Dictionary<string, object> _properties = new Dictionary<string, object>();
    public override bool TryGetMember(GetMemberBinder binder, out object result)
    {
        return _properties.TryGetValue(binder.Name, out result);
    }

    public override bool TrySetMember(SetMemberBinder binder, object value)
    {
        _properties[binder.Name] = value;
        return true;
    }
}

dynamic foo = new DynamicObjectBag();
foo.Val1 = 3;
foo.Val2 = “Value 2”;

This is of course a simplified example. I plan to derive classes from DynamicObject so I am able to use both direct object properties and properties stored in the dictionary using the same semantic dot style notation or access methods. The goal is to have DLR compatible objects for use in DLR supported languages and provide for future compatibility with .NET 4.0 DLR capabilities when the application can be upgraded to .NET 4.0.

My problem is that pre-.NET 4.0 I have no equivalent concept to the dynamic keyword. The methods such as TryGetMember have a binder parameter like GetMemberBinder. Now .NET 4.0 has a C# default binder available which will allow binding to happen when using the dynamic keyword, however I have been unable to find or determine how to perform the equivalent in .NET 3.5.

At the moment it is my understanding that I would need to write a custom binder which would basically duplicate the type of logic available in the .NET 4.0 default C# binder.

Please someone point me in the right direction on how I can use a DynamicObject in .NET 3.5 and add properties etc. at runtime without access to the dynamic keyword.

References:
Dynamically adding members to a dynamic object
http://tomlev2.wordpress.com/2009/10/08/c-4-0-implementing-a-custom-dynamic-object/

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T19:30:01+00:00Added an answer on May 13, 2026 at 7:30 pm

    You will need to create a custom binder and you will probably then want to consume the binder using a CallSite so that the actions are cached.

    You can use the DefaultBinder in the outer layer to do most of this – you just need to create one and then it has methods like GetMember on it to do the binding. The implementation of your binder then is just using the DefaultBinder and applying any rules for boxing value types that come back (the DLR requires all return types to be object).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.