Right-click the node Dependencies of your project> Nuget Package Management> Overview and type “dynamic” in the search box. Select System.Dynamic.Runtimeat the top of the list, now you can use dynamicin your source code.
If you are like me, you are interested in the reason why you can use the keyword dynamicwithout reference to the DLR libraries in the method code, but you cannot continue reading in property declarations.
# , NETStandard.Library System.Dynamic.Runtime. 1 3 # dynamic vs var .
Line 1: dynamic a = new {a = 1, b = 2};
Line 2: a = new Class1();
Line 3: var b = new { a = 1, b = 2 };
.
Line 1: newobj instance void class '<>f__AnonymousType0`2'<int32,int32>::.ctor(!0,!1)
Line 2: newobj instance void ClassLibrary2.Class1::.ctor()
Line 3: newobj instance void class '<>f__AnonymousType0`2'<int32,int32>::.ctor(!0,!1)
1 3 IL, . , . DLR.
, , auto dynamic.
public class Class1 { public dynamic Test { get; set; } }
IL auto-property dynamic, object, , getter setter, System.Runtime.CompilerServices.DynamicAttribute System.Dynamic.Runtime, DLR.