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 6963621
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:49:02+00:00 2026-05-27T15:49:02+00:00

In the documentation for DynamicObject , there is an example of a DynamicDictionary that

  • 0

In the documentation for DynamicObject, there is an example of a DynamicDictionary that allows you to work with a dictionary as if it’s a class with properties.

Here is the class (modified slightly for brevity):

public class DynamicDictionary : DynamicObject
{
    Dictionary<string, object> _dictionary = new Dictionary<string, object>();

    public int Count
    {
        get { return _dictionary.Count; }
    }

    public override bool TryGetMember(GetMemberBinder binder, out object result)
    {
        string name = binder.Name.ToLower();
        return _dictionary.TryGetValue(name, out result);
    }

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

What I’d like to do is modify the class, so that I can do the following:

public class Test
{
    public Test()
    {
        var result = Enumerable.Range(1, 5).Select(i => new DynamicDictionary
        {
            Id = i,
            Foo = "Foo",
            Bar = 2
        });
    }
}

Questions

  1. Is this possible?
  2. If yes, how?
  • 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-27T15:49:02+00:00Added an answer on May 27, 2026 at 3:49 pm

    It turns out, I was able to solve my problem by using Linq’s built-in ToDictionary() method.

    Example:

    public Test()
    {
        var data = Enumerable.Range(1, 5).Select(i => new
        {
            Id = i,
            Foo = "Foo",
            Bar = 2
        });
        var result = data
            .Select(d => d.GetType().GetProperties()
                .Select(p => new { Name = p.Name, Value = p.GetValue(pd, null) })
                .ToDictionary(
                    pair => pair.Name,
                    pair => pair.Value == null ? string.Empty : pair.Value.ToString()));
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Documentation can be found here It says in the example: onDrop: Called whenever a
The documentation says there's a limit to the number of regions that can be
The documentation for the Date() class lists several string formats that it can convert
The documentation for properties in Obj-C 2.0 say that atomic properties use a lock
The Documentation of the java.util.Properties-class states: A property list can contain another property list
Documentation simply states that setting setAutosavingDelay to anything > 0 on the shared doc
The documentation for the round() function states that you pass it a number, and
The documentation indicates that the error: option function will make available: XHR instance, a
Documentation states that interface delegation is available for Win32 only. Currently I can't test
The documentation for NSDictionary says that the method objectForKey returns nil if the NSDictionary

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.