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

The Archive Base Latest Questions

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

With the DLR, i would like to do something like this: class MyClass {

  • 0

With the DLR, i would like to do something like this:

class MyClass {
   int MyProperty { get; set; }
}

In razor, I would do something like this. (InstanceOfMyClass is some dynamic object that looks at an instance of MyClass)

@InstanceOfMyClass.MyProperty

This would output the string representation of MyProperty.

Now if I do this.

@InstanceOfMyClass.MyMissingProperty

I would like it to output “Missing: MyMissingProperty”. I would love to capture the whole expression, like so.

@InstanceOfMyClass.MyMissingProperty.MoreMissing

Could potentially output “Missing: MyMissingProperty.MoreMissing”, but that might be asking a lot of the DLR.

Will the ExpandoObject allow me to do this? If not, what do I have to do to implement this?

  • 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-27T19:02:02+00:00Added an answer on May 27, 2026 at 7:02 pm

    Extend DynamicObject.TryGetMember in this way:

    If the member exists, return the value. If the member doesn’t exist, return a new instance of a class that will handle both the string representation of the missing property and also the chain. Something like this

    public class MissingPropertyChain : DynamicObject
    {
        private string property;
    
        public MissingPropertyChain(string property)
        {
            this.property = property;
        }
    
        public override bool TryGetMember(GetMemberBinder binder, out object result) 
        {
            if(binder.Name == "ToString")
                result = "Missing property: " + property;
            else
                result = new MissingPropertyChain( property + "." + binder.Name;
    
            return true;
        }
    }
    

    I didn’t try it, but I think it will give you the idea of how to solve the problem.

    Hope it helps.

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

Sidebar

Related Questions

I have a dynamic object built inside IronPython and I would like to build
I'm playing with DLR to get a better understanding of it. I'm not completely
Although I'm not a .NET developer I always get excited about the work DLR
I have this scenario... 1.- I'm providing a Dynamic Table for wich users can
I'm planning to make an implementation of Lua for the DLR, and i would
One example of using the DLR in C# is as follows: dynamic dyn =
I'd like to run some arbitrary user code in a Silverlight application. Of course
With the inception of the dynamic type and the DLR in .NET 4, I
In the DLR's LINQ Expressions, what is the difference between this: Expression.Convert(SomeVariableExpression, typeof(T)); and
From wikipedia's entry on DLR , it look like the purpose of DLR is

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.