Dynamic resolution rules joy
Join the DZone community and get the full member experience.
Join For FreeIn the following code, what do you believe the output should be?
class Program { static void Main(string[] args) { dynamic stupid = new Stupid{Age = 3}; Console.WriteLine(stupid.Age); } } public class Stupid : DynamicObject { public int Age { get; set; } public override bool TryGetMember(GetMemberBinder binder, out object result) { result = 1; return true; } }
Argh!
The default is to use the actual type members, and then fall back to the dynamic behavior. Whereas I would expect it to first check the dynamic behavior and then fall back to the actual members if it can’t find dynamic stuff.
Quite annoying.
Published at DZone with permission of Oren Eini, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.
Trending
-
8 Data Anonymization Techniques to Safeguard User PII Data
-
AI Technology Is Drastically Disrupting the Background Screening Industry
-
HashMap Performance Improvements in Java 8
-
How to Load Cypress Chrome Extension
Comments