Hi,

I have some trouble passing parameters to a function in one of my
CommonScripts file.

Here's what I do:

As part of a specific view I want to output a subview and pass it a
parameter that might or might not be set. That's why I pass it using
the ? prefix:

<% OutputSubView("/shared/result", {...@result: ?Result}) %>

In /shared/result.brail I use the provider "Result" parameter (which
can be the real object or an IgnoreNull) and need to pass a property
of it to a function in my CommonScripts library. For example:

<% choice(result.IsSuccess,"another arg", "yet another")%>

The method looks like this:

def choice(isSuccess as bool, anotherArg as string, moreArgs as
string):
  // stuff
end

The problem is that even if the "result" parameter is correctly
assigned to an object (I check that), it and all it's properties are
IgnoreNull values, so whenever I invoke the "choice" method like above
I get an error:

Unable to cast object of type 'Castle.MonoRail.Views.Brail.IgnoreNull'
to type 'System.IConvertible'.

[InvalidCastException: Unable to cast object of type
'Castle.MonoRail.Views.Brail.IgnoreNull' to type
'System.IConvertible'.]
   Boo.Lang.Runtime.RuntimeServices.CheckNumericPromotion(Object
value) +46
   Boo.Lang.Runtime.RuntimeServices.UnboxBoolean(Object value) +130
   BrailView_result.Run() +141

The offending line in the compiled code is:
 this.OutputEscaped(CommonModule.choice(RuntimeServices.UnboxBoolean
(ExpandDuckTypedExpressions_WorkaroundForDuplicateVirtualMethods.GetProperty
(this.GetParameter("result"), "IsSuccess")), "success", "error"));

While can comprehend why the error occurs (a IgnoreNull isn't a
boolean) I'd like to know whether I can do anything to prevent it. Can
IgnoreNull somehow transparently be converted to it's target?

I've found two work arounds:

1) don't pass result.IsSuccess but Convert.ToBoolean
(result.IsSuccess.ToString())  - pretty ugly

2) "unwrap" the IgnoreNull before use:
result = IgnoreNull.ExtractTarget(result)

Is there any easier way to handle this?

Regards,
Andre
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Castle Project Users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/castle-project-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to