Edentity Web Systems
You solve creative. We crack code.
/Header/WhoWeAre.jpg
 

09/15/2009 ASP.NET Expression Builder
Posted by Andre Small

After working on a few multi-lingual sites, the common problem that I face was the swapping the text and images. Now, you can use <%$  %> expression builder to get the text and image path from resources files. Personally, I only use resx files for text, I don't like referencing images/files using a single Camel-case string. I want to see the path the image/resource as I scan through code. I think that adds additional clicks and memory work when looking through asp.net files.  

So I decided to write my own ASP.NET Expression Builder which was a lot easier than I thought it would be. There are a few caveats to using an expression builder:

1.  You should consider them static, meaning they don't below to an HttpContext, or page or object instance/context, but act more like a static methods.

2.  You will need to standardize your resource naming so that you can modify the supplied value to output the correct value for the control in a given language.

Here is the code block.

namespace Project
{
    [ExpressionPrefix("ProjectResources")]
    public class ProjectResourcesExpressionBuilder : ExpressionBuilder  
    {
        public override System.CodeDom.CodeExpression GetCodeBLOCKED EXPRESSION;
        }       
    }
}

You will have to update the web.config with a couple of additional lines to enable the expression builder:

<compilation debug="true">
 <assemblies>
  <add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
  <add assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
  <add assembly="System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
  <add assembly="System.Data.DataSetExtensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
 </assemblies>
 <expressionBuilders>
  <add expressionPrefix="ProjectResources" type="Project.ProjectResourcesExpressionBuilder "/>
 </expressionBuilders>
</compilation>

« Back to Blog Main Page |

0 Comment(s)

Leave Comment

Name:
Comment:  
 
Security Check: 
 
 
Edentity Web Systems Inc.
Suite 201
40 Spadina Ave.
Toronto ON
M5V 2H8
Tel:
416.591.2500
Fax:
416.352.5270
Home | Who We Are | What We Do | Clients & Brands | Careers | Contact

Copyright © 2010 Edentity Web Systems Inc. Privacy Policy