Created
December 3, 2020 21:33
-
-
Save svick/5ea4b6ab26f2405f95b0ee27ebaedb98 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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