3

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.

2
  • Hmmmmm. Hypothetically? Interface to hell. Do your utmost to separate them, you want complimentary not bound ideally. If you're inevitably doing client-server communication, get that right first. I'm thinking mediator and/or observer based. Commented May 28, 2009 at 21:11
  • What I'm looking for is something along the lines of what Annakata was getting at. I'm happy to help clarify the question if needed. Commented Jun 3, 2009 at 18:19

4 Answers 4

3
+75

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

Sign up to request clarification or add additional context in comments.

Comments

3

I think you should check out my C# to JavaScript compiler out at http://jsc.sourceforge.net/

Unlike Script# my jsc compiler works on MSIL level.

WPF Example: AvalonExampleGallery alt text

Contact me if you have any specific questions.

Comments

1

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.

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.