PDA

View Full Version : Expression problem with types


john.hui
02-02-2007, 11:20 PM
Hi,

I found a problem with types in Expressions.


obj = Spring.Expressions.ExpressionEvaluator.GetValue(No thing, "T(Object)")


returns the equivalent of


obj = GetType(Object)


However,


obj = Spring.Expressions.ExpressionEvaluator.GetValue(No thing, "T(Object).FullName")


should return


obj = GetType(Object).FullName


It does not but instead throws an exception

InvalidPropertyException was unhandled
'FullName' node cannot be resolved for the specified root context.


The second issue has to do with arrays.

I try to execute this:


obj = Spring.Expressions.ExpressionEvaluator.GetValue(No thing, "T(Object[])")
obj = Spring.Expressions.ExpressionEvaluator.GetValue(No thing, "T(Object[,])")


which should be equivalent to


obj = GetType(Object())
obj = GetType(Object(,))


However, this raises the exception

TypeLoadException was unhandled
Could not load type from string value 'Object[]'.

Could you tell if my Expression strings were correct?

Thanks in advance.

John

Erich Eichinger
02-03-2007, 11:33 PM
Hi John,

I'm afraid this is a nasty bug. I recorded a JIRA (http://opensource.atlassian.com/projects/spring/browse/SPRNET-470) entry to keep track of this.

cheers,
Erich

Bruno Baia
02-04-2007, 05:26 PM
Hi,

I've created another issue (http://opensource.atlassian.com/projects/spring/browse/SPRNET-471) to support multi dimensional array in type resolution.

There are two problems :

First, many type aliases are registered in Spring.Context.Support.TypeRegistry class.
C# alias "object[]" and VB.NET alias "Object()" are one of them.
You are using half C#, half VB.NET syntax with Object[], here are valid syntaxs :

Spring.Expressions.ExpressionEvaluator.GetValue(No thing, "T(System.Object[])")
Spring.Expressions.ExpressionEvaluator.GetValue(No thing, "T(object[])")
Spring.Expressions.ExpressionEvaluator.GetValue(No thing, "T(Object())")

The last one will not be parsed correctly, and I don't know until which point we should support VB.NET syntax.


Second, TypeResolver does not support multi dimensional arrays.


Bruno

john.hui
02-04-2007, 09:46 PM
Hi,

I am glad you guys will be looking into this.

Looking really forward to RC1!

John

Aleks Seovic
02-05-2007, 10:58 PM
Just committed a fix for SPRNET-470, which takes care of the first issue.

Basically, if the context for the property resolution is a type, we try to find the property first on the specified type (i.e Object) and if it cannot be found there we probe the Type class for it. That way expressions such as Int32.MaxValue and Int32.FullName will both work (notice that this is different from C#, where you would have to use typeof(Int32).FullName in the latter case. Also, notice that from Spring's perspective, expressions such as Int32.FullName and T(System.Int32).FullName are equivalent).

I also modified MethodNode to work in a similar fashion, in order to allow invocation of Type methods such as IsAssignableFrom, etc. within SpEL expressions.

- Aleks

john.hui
02-07-2007, 08:32 PM
Well done! I can't wait to try it out. But can probably only try it in March because I sorely need a vacation !

John

Erich Eichinger
02-07-2007, 08:33 PM
Enjoy your vacation - but don't forgot your notebook *bg*