reflection

Generic constructors and reflection

笑着哭i 提交于 2021-02-07 01:41:44
问题 Is it possible to see which constructor was the generic one? internal class Foo<T> { public Foo( T value ) {} public Foo( string value ) {} } var constructors = typeof( Foo<string> ).GetConstructors(); The property 'ContainsGenericParameters' returns me for both constructors false. Is there any way to find out that constructors[0] is the generic one? They both have the same signature, but I would like to call the "real" string one. EDIT: I want to invoke the given type using ilGen.Emit(

Generic constructors and reflection

一曲冷凌霜 提交于 2021-02-07 01:39:28
问题 Is it possible to see which constructor was the generic one? internal class Foo<T> { public Foo( T value ) {} public Foo( string value ) {} } var constructors = typeof( Foo<string> ).GetConstructors(); The property 'ContainsGenericParameters' returns me for both constructors false. Is there any way to find out that constructors[0] is the generic one? They both have the same signature, but I would like to call the "real" string one. EDIT: I want to invoke the given type using ilGen.Emit(

How to use Reflection in FluentValidation?

无人久伴 提交于 2021-02-06 13:55:15
问题 I have a scneario in which I want to use reflection to do validation using FluentValidation. Someting like this: public class FooValidator : AbstractValidator<Foo> { public FooValidator(Foo obj) { // Iterate properties using reflection var properties = ReflectionHelper.GetShallowPropertiesInfo(obj); foreach (var prop in properties) { // Create rule for each property, based on some data coming from other service... //RuleFor(o => o.Description).NotEmpty().When(o => // this works fine when foo

Create generic Func from reflection

ε祈祈猫儿з 提交于 2021-02-06 12:49:15
问题 I've specified type in a variable: Type hiddenType . I need to create a Func<T> delegate where T is of type specified in mentioned variable and assign an method: var funcType = typeof(Func<>).MakeGenericType(hiddenType); Func<object> funcImplementation = () => GetInstance(hiddenType); var myFunc= Delegate.CreateDelegate(funcType , valueGenerator.Method); It doesn't works - because funcImplementation is returns object instead of desired. At runtime, it will surely be an instance of type

Create generic Func from reflection

Deadly 提交于 2021-02-06 12:46:56
问题 I've specified type in a variable: Type hiddenType . I need to create a Func<T> delegate where T is of type specified in mentioned variable and assign an method: var funcType = typeof(Func<>).MakeGenericType(hiddenType); Func<object> funcImplementation = () => GetInstance(hiddenType); var myFunc= Delegate.CreateDelegate(funcType , valueGenerator.Method); It doesn't works - because funcImplementation is returns object instead of desired. At runtime, it will surely be an instance of type

How to efficiently test if action is decorated with an attribute (AuthorizeAttribute)?

…衆ロ難τιáo~ 提交于 2021-02-05 20:28:37
问题 I'm using MVC and have a situation where in my OnActionExecuting() I need to determine if the Action method that is about to execute is decorated with an attribute, the AuthorizeAttribute in particular. I'm not asking if authorization succeeded/failed, instead I'm asking does the method require authorization. For non-mvc people filterContext.ActionDescriptor.ActionName is the method name I'm looking for. It is not, however, the currently executing method; rather, it is a method that will be

How to efficiently test if action is decorated with an attribute (AuthorizeAttribute)?

生来就可爱ヽ(ⅴ<●) 提交于 2021-02-05 20:27:40
问题 I'm using MVC and have a situation where in my OnActionExecuting() I need to determine if the Action method that is about to execute is decorated with an attribute, the AuthorizeAttribute in particular. I'm not asking if authorization succeeded/failed, instead I'm asking does the method require authorization. For non-mvc people filterContext.ActionDescriptor.ActionName is the method name I'm looking for. It is not, however, the currently executing method; rather, it is a method that will be

How to efficiently test if action is decorated with an attribute (AuthorizeAttribute)?

那年仲夏 提交于 2021-02-05 20:27:38
问题 I'm using MVC and have a situation where in my OnActionExecuting() I need to determine if the Action method that is about to execute is decorated with an attribute, the AuthorizeAttribute in particular. I'm not asking if authorization succeeded/failed, instead I'm asking does the method require authorization. For non-mvc people filterContext.ActionDescriptor.ActionName is the method name I'm looking for. It is not, however, the currently executing method; rather, it is a method that will be

I can't use API reflection on androidx.appcompat:appcompat:1.1.0

安稳与你 提交于 2021-02-05 12:04:00
问题 I have a problem with androidx.appcompat:appcompat:1.1.0. It's a new problem because on androidx.appcompat:appcompat:1.0.2 it does not exist. I have a code that uses reflection to get mPopup Field from the spinner and set its height. It works very well on appcompat:1.0.2 but not on androidx.appcomppat:appcompat:1.1.0. The code is private void setPopUp() { try { Field popup = getPopupField(); // Get private mPopup member variable and try cast to ListPopupWindow final android.widget

I can't use API reflection on androidx.appcompat:appcompat:1.1.0

拥有回忆 提交于 2021-02-05 12:03:04
问题 I have a problem with androidx.appcompat:appcompat:1.1.0. It's a new problem because on androidx.appcompat:appcompat:1.0.2 it does not exist. I have a code that uses reflection to get mPopup Field from the spinner and set its height. It works very well on appcompat:1.0.2 but not on androidx.appcomppat:appcompat:1.1.0. The code is private void setPopUp() { try { Field popup = getPopupField(); // Get private mPopup member variable and try cast to ListPopupWindow final android.widget