Get system generic type defenition from Post-Sharp defenition.
9 posts • Page 1 of 1
Get system generic type defenition from Post-Sharp defenition.
I have this method
public void PassArray(T[] workersArray)
Then I watch on ParameterDeclaration.ParameterType of workersArray it shows "{!!0[]}".
Then I try to get ParameterDeclaration.ParameterType.GetSystemType(null, null) of workersArray then it returns null. But I want to get System.Type of workersArray ({Name = "T[]" FullName = null}). How I can do it?
public void PassArray(T[] workersArray)
Then I watch on ParameterDeclaration.ParameterType of workersArray it shows "{!!0[]}".
Then I try to get ParameterDeclaration.ParameterType.GetSystemType(null, null) of workersArray then it returns null. But I want to get System.Type of workersArray ({Name = "T[]" FullName = null}). How I can do it?
- Anonymous
Re: Get system generic type defenition from Post-Sharp defenition.
Sorry, the Anonymous was I am.
Denis Bredikhin
- Denis
- Posts: 20
- Joined: Sat Jan 12, 2008 4:55 pm
- Full Name: Denis Bredikhin
Re: Get system generic type defenition from Post-Sharp defenition.
I suppose it is because you do not pass generic arguments to GetSystemType (you pass null values). In System.Reflection, all generic arguments should be bound. You should pass at least one generic method argument from the proper context.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
Re: Get system generic type defenition from Post-Sharp defenition.
But from reflection I can get Type for generic argument defenition ({Name = "T[]" FullName = null}) using type.GetMethod("PassArray").GetParameters()[0].ParameterType
Denis Bredikhin
- Denis
- Posts: 20
- Joined: Sat Jan 12, 2008 4:55 pm
- Full Name: Denis Bredikhin
Re: Get system generic type defenition from Post-Sharp defenition.
This is because [i]System.Reflection[/i] implicitly binds the generic parameters of [i]ParameterType [/i]to the generic parameters of the method. In [i]System.Reflection[/i], everything is bound to a generic context. But in MSIL (and PostSharp), generic parameters are not bound to a context, you have to give the context yourself. In MSIL, the same type can be used in different contexts, so it is not possible to add a method "get system type in the parent context" at type level. This is a mater of semantics, a logical feature of MSIL, not a technical limitation of PostSharp.
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
Re: Get system generic type defenition from Post-Sharp defenition.
Please, help me. How I can bind generic parameters of ParameterType to the generic parameters of the method like System.Reflection do? Should I use MapGenericArguments?
I have MethodDefDeclaration and I want to get System.Type for each parameter.
I have MethodDefDeclaration and I want to get System.Type for each parameter.
- Anonymous
Re: Get system generic type defenition from Post-Sharp defenition.
I changed all forums to member-only posting
.As for your question, it really depends on you what to do. In which generic context would you like to use the system type?
I suppose your context is the body of the method declaring the parameter. In this case your generic context, in terms of system types, is MethodInfo.GetGenericArguments(). You will get an array of types representing unbound generic arguments.
.As for your question, it really depends on you what to do. In which generic context would you like to use the system type? I suppose your context is the body of the method declaring the parameter. In this case your generic context, in terms of system types, is MethodInfo.GetGenericArguments(). You will get an array of types representing unbound generic arguments.
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
Re: Get system generic type defenition from Post-Sharp defenition.
Thanks, it seems I'm investigated it. 

Last bumped by Anonymous on Sat Jan 19, 2008 4:20 am.
Denis Bredikhin
- Denis
- Posts: 20
- Joined: Sat Jan 12, 2008 4:55 pm
- Full Name: Denis Bredikhin
9 posts • Page 1 of 1