C# Extension Method: DataRow - ToExpandoObject

CSharp · Console

/Program.cs

// C# Extension Method
// Doc: https://csharp-extension.com/en/method/1002764/datarow-toexpandoobject

// @nuget: Z.ExtensionMethods

using System;
using System.Data;
					
public class Program
{
	public static void Main()
	{
		var table = new DataTable();

        table.Columns.Add("IntColumn", typeof (int));
        table.Columns.Add("StringColumn", typeof (string));
        table.Rows.Add(1, "Fizz");

		//C# Extension Method: DataRow - ToExpandoObject
        var entity = table.Rows[0].ToExpandoObject();

        Console.WriteLine(entity.IntColumn);
		Console.WriteLine(entity.StringColumn);
	}
}
;