Method argument of generic type
2 posts • Page 1 of 1
Method argument of generic type
Hi Gael
I have the next code
public abstract class Presenter<TView> where TView : class
{
[ValidateArguments]
public void AttachView( [NotNull]TView view )
{}
}
[ValidateArguments] inherits MulticastAttribute, [NotNull] is just custom attribute used by advice to determine what code to emit.
When I handle the "view" method argument in my advice the ParameterType property of the instance of the ParameterInfo class returned by the parameter.GetReflectionWrapper(null, null) method is null.
How to distinguish arguments of a generic type from arguments of a concrete type in the right way?
How to get a type which I can use to emit code? C# compiler use "box" IL command with such types (box[/url] !TView[/url]) even when I specify "class" constraint on generic argument it is the reason why I need the type further to argument name.
best regards and Happy New Year
Ed.ward
Edward Pavlov
- Ed_ward
- Posts: 11
- Joined: Sat Jan 12, 2008 4:55 pm
- Full Name: Edward Pavlov
Re: Method argument of generic type
Edward,
You should pass the array of generic arguments to GetReflectionWrapper, so you have to map all generic type and method arguments of the current method to reflection types, and pass them as a parameter.
As for the second question, look at the interface ITypeSignature. There is a property IsGenericDefinition and IsGenericInstance.
To construct a "box", you shoud use BoxedTypeSignature.
Yup, generics are difficult...
Gael
You should pass the array of generic arguments to GetReflectionWrapper, so you have to map all generic type and method arguments of the current method to reflection types, and pass them as a parameter.
As for the second question, look at the interface ITypeSignature. There is a property IsGenericDefinition and IsGenericInstance.
To construct a "box", you shoud use BoxedTypeSignature.
Yup, generics are difficult...
Gael
Gael Fraiteur, project leader
got good support? consider donating to the project.
got good support? consider donating to the project.
- gfraiteur
- Site Admin
- Posts: 674
- Joined: Tue Dec 18, 2007 3:09 pm
- Full Name: Gael Fraiteur
- Company: postsharp.org
2 posts • Page 1 of 1