Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# Windows
hello
 
please provide a sample windows application regarding how to use c# scriptor for run time event creation and implementation
 
regards
ginnas
Posted 12-Nov-12 19:46pm
ginnas457
Comments
Richard MacCutchan at 13-Nov-12 4:10am
   
What is "c# scriptor"?
ginnas at 13-Nov-12 4:15am
   
hello
 
i meant the c# script in order to code in the events of the controls at run time
 
regards
ginnas
Richard MacCutchan at 13-Nov-12 4:20am
   
Sorry, I still do not understand what you are talking about. C# is a programming language not a script. And what controls are you referring to? Please edit your question and explain in detail what problem you are trying to solve.
ginnas at 13-Nov-12 23:28pm
   
hello
 
actually what i am planning to do is a framework like application HMI development software so i have to provide both design time and run time to the end user.at design time the user can put different .net controls on to the design surface and change their properties , now i wanted to provide the option for write code in their events of the controls,that is while running based on the each event happening the code written in their events has to execute, here only i am trying to put the scripting language
 
these codes written by the end user in each event handlers can we put the scripts like c# script eg-:alvas.net/alvas.scriptor.aspx
 
regards
ginnas
 

 
Richard MacCutchan at 14-Nov-12 3:05am
   
As I said before, C# is not a scripting language. I really have no idea what you mean by all this. If you are trying to build the actual code of a program dynamically, then you need to research some of the compile-on-demand websites that exist. If I recall there is an article somewhere here on CodeProject about this subject.
Michiel du Toit at 16-Nov-12 10:17am
   
What you're looking for is the CSharpCodeProvider to compile the code and then you can use AppDomains if you want to run it plug-in style. You have to implement the events using MarshalByRefObject to cross AppDomain boundaries and then use serializable EventArgs descendants as parameters or you won't be able to unload the domains later.
 
This is rather complicated to implement - unfortunately my existing code is application-specific, but here a few snippets that can help:
 
To compile the code (has to be a complete .cs file with usings and all) into a dll:
 
var cc = new CSharpCodeProvider(new Dictionary<string,>() { { "CompilerVersion", "v3.5" } });
var outputpath = BinaryFolder + TargetAssembly + ".dll";
 
CompilerParameters cp = new CompilerParameters()
{
OutputAssembly = outputpath,
WarningLevel = 3,
GenerateExecutable = false,
GenerateInMemory = false,
CompilerOptions = "/target:library /optimize"
};
 
cp.ReferencedAssemblies.Add(
"System.dll", "System.Data.dll", "System.Xml.dll", "mscorlib.dll",
"System.Windows.Forms.dll");
 
To execute the code from the dll that you have compiled:
var _domain = AppDomain.CreateDomain("Isolated:" + Guid.NewGuid());
 
var _value = (IExecute)_domain.CreateInstanceAndUnwrap(AssemblyName, "Full name of the class in the dll here", false, BindingFlags.CreateInstance | BindingFlags.Default, null, null, null, null, null);
//_value.Properties = assign them here;
 
_value.Execute();
 
Further, you have to create a class based on an interface and then use only the interface in the calling code (main app) and implement the class in the .cs file. If you use any virtual (override) methods you will not be able to unload the appdomain (plug-in) later.
 
Hope this gives you a point to begin...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Mobile
Web03 | 2.8.1411022.1 | Last Updated 13 Nov 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100