Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Type type = typeof(Car);
- // Type type = Type.GetType("Namespace.ClassName");
- // string fullName = typeOf(SomeClass).FullName;
- // string name = typeOf(SomeClass).Name;
- // Type baseType = typeof(SomeClass).BaseType;
- // var field = type.GetField("fieldName"); // without binding flags given only public or return null
- var fields = type.GetFields(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static);
- foreach (var field in fields)
- {
- Console.WriteLine(field); // field.Name or field.FieldType
- var fieldValue = field.GetValue(instance);
- }
- // var field = type.GetField($"{fieldAsString}", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static);
- // var fieldValue = field.GetValue(instance);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement