views:

81

answers:

0

How can I construct an ExpressionBuilder which takes an ExpressionBuilderContext as parameter, without the use of a virtualpath in the context?

I would like to parse expressions which retrieve data which is stored based on business-id rather then a virtualpath belonging to some view.

Extra info:

I have this to retrieve localized resource strings from my custom Sql implemented IResourceProvider. However I would like to create a custom ExpressionBuilder so I can retrieve localized business content (products, newsmessages). However I'm stuck...

<System.Runtime.CompilerServices.Extension()> _
Public Function Resource(ByVal htmlhelper As HtmlHelper, ByVal expression As String, ByVal ParamArray args As Object()) As String
    Dim virtualPath As String = GetVirtualPath(htmlhelper)
    Return GetResourceString(htmlhelper.ViewContext.HttpContext, expression, virtualPath, args)
End Function

Private Function GetResourceString(ByVal httpContext As HttpContextBase, ByVal expression As String, ByVal virtualPath As String, ByVal args As Object()) As String
    Dim context As New ExpressionBuilderContext(virtualPath)
    Dim builder As New ResourceExpressionBuilder()

    Dim fields As ResourceExpressionFields = DirectCast(builder.ParseExpression(expression, GetType(String), context), ResourceExpressionFields)

    If Not String.IsNullOrEmpty(fields.ClassKey) Then
        Return String.Format(DirectCast(httpContext.GetGlobalResourceObject(fields.ClassKey, fields.ResourceKey, CultureInfo.CurrentUICulture), String), args)
    End If

    Return String.Format(DirectCast(httpContext.GetLocalResourceObject(virtualPath, fields.ResourceKey, CultureInfo.CurrentUICulture), String), args)
End Function