Skip to content

Instantly share code, notes, and snippets.

@svick
Created December 3, 2020 21:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save svick/5ea4b6ab26f2405f95b0ee27ebaedb98 to your computer and use it in GitHub Desktop.
Save svick/5ea4b6ab26f2405f95b0ee27ebaedb98 to your computer and use it in GitHub Desktop.
#nullable enable
public static class JavaScriptExtensions
{
public static IEnumerator<(string name, object? value)> GetEnumerator(this object js)
{
var properties = js.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public);
foreach (var property in properties)
{
yield return (property.Name, property.GetValue(js));
}
}
}
public class Program
{
public static void Main()
{
foreach (var (property, value) in DateTime.Now)
{
Console.WriteLine($"{property}: {value}");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment