Dynamic generate JScript code using C#  
Author Message
Teddy79





PostPosted: Visual C# Language, Dynamic generate JScript code using C# Top

I want to generate a JScript source code file using CodeDom in C# . To be more specific, I use class JScriptCodeProvider. Everything seems fine except when generating , for example the following JScript code:

public class Evaluator implements IEvaluator {
}

My C# code for generating that is:
CodeTypeDeclaration Class1 = new CodeTypeDeclaration("Evaluator");
JscriptTest.Types.Add(Class1);
Class1.IsClass = true;
Class1.BaseTypes.Add(new CodeTypeReference("IEvaluator"));

The problem is that CodeTypeDeclaration class only has the collection BaseTypes but not something like InterfaceTypes hence instead of generating "implements", it generates "extends"

public class Evaluator extends IEvaluator {
}
Any idea how to fix that Thanks in advance


Visual C#13  
 
 
GavH





PostPosted: Visual C# Language, Dynamic generate JScript code using C# Top

To include interfaces you must add object as the first BaseType such as :

CodeTypeDeclaration Class1 = new CodeTypeDeclaration("Evaluator");
JscriptTest.Types.Add(Class1);
Class1.BaseTypes.Add(new CodeTypeReference(typeof(Object)));
Class1.BaseTypes.Add(new CodeTypeReference("IEvaluator"));


That is untested but should fix your issue.

Regards



 
 
Teddy79





PostPosted: Visual C# Language, Dynamic generate JScript code using C# Top

Thanks, it works