dynamic obj = new ExpandoObject(); obj.Name = "John"; obj.Age = 30; GetMemberBinder binder = Binder.GetMember(CSharpBinderFlags.None, "Name", typeof(Program), new[] { CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null) }); var result = binder.FallbackGetMember(obj, null); Console.WriteLine(result);
dynamic obj = new MyDynamicObject(); obj.Name = "John"; obj.Age = 30; GetMemberBinder binder = Binder.GetMember(CSharpBinderFlags.None, "Age", typeof(Program), new[] { CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null) }); var result = binder.FallbackGetMember(obj, null); Console.WriteLine(result);In this example, we have created a custom dynamic object by inheriting from the DynamicObject class. We have set two properties of the object, Name and Age. We then created a GetMemberBinder object and called its FallbackGetMember method to retrieve the value of the "Age" property. Package library: System.Core.dll