Skip to main content

C# - How to get Property Name and Value of a dynamic object?

C# - Dynamic Object

Use the following code to get Name and Value of a dynamic object's property.

dynamic d = new { Property1= "Value1", Property2= "Value2"};

var properties = d.GetType().GetProperties();
foreach (var property in properties)
{
    var PropertyName=property.Name;
//You get "Property1" as a result
 
  var PropetyValue=d.GetType().GetProperty(property.Name).GetValue(d, null);
//You get "Value1" as a result

// you can use the PropertyName and Value here
 }

Comments

Post a Comment

Popular posts from this blog

Mapping .NET Data Types to MySQL Data Types

Mapping .NET Data Types to MySQL Data Types .NET Data Types MySQL Data Types System.Boolean boolean, bit(1) System.Byte tinyint unsigned System.Byte[] binary, varbinary, blob, longblob System.DateTime datetime System.Decimal decimal System.Double double System.Guid char(36) System.Int16 smallint System.Int32 int System.Int64 bigint System.SByte tinyint System.Single float System.String char, varchar, text, longtext System.TimeSpan time DateTimeOffset type is not supported.

WCF Service in IIS7 - The current identity (NT AUTHORITY\NETWORK SERVICE) does not have write access to ‘C:\WINDOWS\Microsoft.NET\Framework\v4.0.3019\Temporary ASP.NET Files’.

The current identity (NT AUTHORITY\NETWORK SERVICE) does not have write access to ‘C:\WINDOWS\Microsoft.NET\Framework\v4.0.3019\Temporary ASP.NET Files’. To solve this issue just run the following command  in command line C:\Windows\Microsoft.NET\Framework\v4.0.30319> aspnet_regiis -ga “NT Authority\Network Service”