PDA

View Full Version : Cross Inheritance With .NET Can Anybody Help



darrenez
9th July 2003, 19:32
1. Created a Solution
2. Added a vb project
3. Added a cs project
4. In the cs project Add a reference to our vb project by using the Project | Add Reference menu option.

' Parent.vb which makes the dll called vblib1 see (2.)

Public Class Parent
Public Sub New()
MsgBox("Constructor Parent")
End Sub
End Class


// Form1.cs
using System;

namespace cslib
{
using vblib1;
using System.Windows.Forms;

public class Form1 : Parent &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp
{
&nbsp &nbsp &nbsp &nbsp public Form1()
&nbsp &nbsp &nbsp &nbsp {
&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp MessageBox.Show("Form1 constructor");
&nbsp &nbsp &nbsp &nbsp }
&nbsp &nbsp &nbsp &nbsp

&nbsp &nbsp &nbsp &nbsp public static void Main(System.String[] args)
&nbsp &nbsp &nbsp &nbsp {
&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp Form1 f = new Form1();
&nbsp &nbsp &nbsp &nbsp }


}
}

Now this works but what I really want to do is inherit JavaScript From CSharp

So I created a new solution and two cs projects ( how do you create a js project )


// ServerPush.js

import System;

package ServerPush
{&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp
public class jsServerPush
{
&nbsp &nbsp &nbsp &nbsp function lib_setdata( vKey:String,
&nbsp &nbsp &nbsp &nbsp vCode:String,
&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp vData:String ) : void
&nbsp &nbsp &nbsp &nbsp {
&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp //alert(vKey);
&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp //alert(vCode);
&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp //alert(vData);

&nbsp &nbsp &nbsp &nbsp var y:int;
var x:int;
y=0;
&nbsp &nbsp &nbsp &nbsp for ( x=0; x<10; x++)
{&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp
&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp y = y + x;
&nbsp &nbsp &nbsp &nbsp }
&nbsp &nbsp &nbsp &nbsp }
}
}

// Mediator.cs

namespace montego.webserving.******
{
using ServerPush;
using System;

public class Mediator : jsServerPush &nbsp &nbsp &nbsp &nbsp
{
&nbsp &nbsp &nbsp &nbsp public Mediator()
&nbsp &nbsp &nbsp &nbsp {
&nbsp &nbsp &nbsp &nbsp System.String[] xargs = new System.String[3];
&nbsp &nbsp &nbsp &nbsp xargs[ 0 ]= "Interface";
&nbsp &nbsp &nbsp &nbsp xargs[1]= "Being";
&nbsp &nbsp &nbsp &nbsp xargs[2]= "Called";
&nbsp &nbsp &nbsp &nbsp
lib_setdata( xargs[ 0 ], xargs[1], xargs[2] );
&nbsp &nbsp &nbsp &nbsp }
&nbsp &nbsp &nbsp &nbsp

&nbsp &nbsp &nbsp &nbsp public static void Main(System.String[] args)
&nbsp &nbsp &nbsp &nbsp {
&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp Mediator f = new Mediator();
&nbsp &nbsp &nbsp &nbsp }


}
}

But This causes a problem with ' using ServerPush '
Anybody know about this stuff ??

DimPrawn
11th July 2003, 11:45
try www.experts-exchange.com (http://www.experts-exchange.com)

I post there and get good answers within a few hours.

Don't have experience with JScript.Net

LettuceDance
15th July 2003, 11:19
Writing JS code in a cs file will not work. From your post it appears that your Visual Studio version doesn't have JS.Net installed . if it does , you will see a new JS project option when you try to create a New project.


You need to do that and compile the JS project before it can be cross referenced and inherited from . But it should work.

LettuceDance
15th July 2003, 11:23
You can compile the .js into a library via the command line thusly :

jsc /t:library yourfilename.js

this will create yourfilename.dll


add this dll into the references section of your other projects and you will be away .

The JSC compiler comes standard with the .NET framework and you dont need JS.Net if you do this.