reflection

GetFields method to get enum values

拈花ヽ惹草 提交于 2020-08-27 10:57:27
问题 I have noticed that when calling GetFields() on enum type, I'm getting an extra fields with type int32. where did it come from?? When I call the other overload (GetFields(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static) ) , it returns the desired fields. is that means that the enum's fields are not Public ? thanks 回答1: Reflector IL Spy can explain this. Take a look at a decompiled enum and you will see something that looks like this: .class public auto ansi

Get private property of a private property using reflection

你离开我真会死。 提交于 2020-08-26 21:09:01
问题 public class Foo { private Bar FooBar {get;set;} private class Bar { private string Str {get;set;} public Bar() {Str = "some value";} } } If I've got something like the above and I have a reference to Foo, how can I use reflection to get the value Str out Foo's FooBar? I know there's no actual reason to ever do something like this (or very very few ways), but I figure there has to be a way to do it and I can't figure out how to accomplish it. edited because I asked the wrong question in the

Get private property of a private property using reflection

别来无恙 提交于 2020-08-26 21:03:02
问题 public class Foo { private Bar FooBar {get;set;} private class Bar { private string Str {get;set;} public Bar() {Str = "some value";} } } If I've got something like the above and I have a reference to Foo, how can I use reflection to get the value Str out Foo's FooBar? I know there's no actual reason to ever do something like this (or very very few ways), but I figure there has to be a way to do it and I can't figure out how to accomplish it. edited because I asked the wrong question in the

Modify a method definition's annotation String parameter at runtime on Android

随声附和 提交于 2020-08-26 04:54:25
问题 As the title says I'm trying to modify a method's annotation String parameter at runtime in Java on Android. I've found an answer to another question asked some time ago which should solve the problem. However, it didn't on Android. In the linked answer there is the following code line Object handler = Proxy.getInvocationHandler(annotation); It assigns a libcore.reflect.AnnotationFactory Object to the handler variable. Three lines later in the code it is tried to get the class's field

Modify a method definition's annotation String parameter at runtime on Android

*爱你&永不变心* 提交于 2020-08-26 04:54:00
问题 As the title says I'm trying to modify a method's annotation String parameter at runtime in Java on Android. I've found an answer to another question asked some time ago which should solve the problem. However, it didn't on Android. In the linked answer there is the following code line Object handler = Proxy.getInvocationHandler(annotation); It assigns a libcore.reflect.AnnotationFactory Object to the handler variable. Three lines later in the code it is tried to get the class's field

How could std::experimental::source_location be implemented?

删除回忆录丶 提交于 2020-08-24 06:03:06
问题 C++ Extensions for Library Fundamentals, Version 2 (N4564) introduces the type std::experimental::source_location. § 14.1.2 [reflection.src_loc.creation] says: static constexpr source_location current() noexcept; Returns: When invoked by a function call (C++14 § 5.2.2) whose postfix-expression is a (possibly parenthesized) id-expression naming current , returns a source_location with an implementation-defined value. The value should be affected by #line (C++14 § 16.4) in the same manner as

How to create an instance of an annotation

本秂侑毒 提交于 2020-08-20 18:15:07
问题 I am trying to do some Java annotation magic. I must say I am still catching up on annotation tricks and that certain things are still not quite clear to me. So... I have some annotated classes, methods and fields. I have a method, which uses reflection to run some checks on the classes and inject some values into a class. This all works fine. However, I am now facing a case where I need an instance (so to say) of an annotation. So... annotations aren't like regular interfaces and you can't