views:

248

answers:

4

I'm implementing some objects which will have about an equal amount of richness on both the client-side and server side.

In this particular case, I'll be building a (hopefully) little class library to deal with search tokens. So as a pseudo-code example, I'll want to be able to do the equivalent of the following in both Javascript and on the server (C# in my case).

s = new SearchTokenList();
s.Add(new SearchToken(field, value, negation));

What design strategies will help avoid creating a big ball of mud for a library which must span C# and Javascript?

Update: Looking for more of strategies than mechanics. But I'll take any guidance I can get from those who have previously done similar things.

+3  A: 

Take a look at Script# by Nikhil Kothari, might help you out. It is a C# to JavaScript compiler.

epitka
A: 

You should be able to run some Javascript code on your .NET server using Microsoft's JScript.NET -- compile it with /target:library and make sure it's CLS-compliant and that you declare that fact with

[assembly:System.CLSCompliant(true)]

or other variants of CLS compliance declarations. Once you've gotten this to work, you could run (a bit of) JS code on both the server (calling it from C#) and the client (calling it from other JS) and more easily ensure equal functionality on both sides.

Alex Martelli
+3  A: 
zproxy
+1  A: 

If performance is not critical, you could load the data in JSON or XML and pass it back to server-side and do the processing. I think WCF can generate JavaScript interface out of the box. See .NET by Example: Calling a WCF service from Javascript.

eed3si9n