CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Nov 2006
    Posts
    357

    DLR Winforms/Console?

    Hey,

    Im just wondering if you can use the DLR for dynamic scripting logic within winforms based applications, or at least console based applications.

    I tried to find any examples online but couldnt find much, so was wondering if anyone had anything on it...

    All i need for the basics to test is being able to make a class, have a c# console app that lets you put in a value, then call the script to change the value on the object then display the value... that there should give me the building blocks for everything else i need to do... would like to use JScript ideally but any DLR language to show the principle is fine

  2. #2
    Join Date
    May 2009
    Location
    Bengaluru, India
    Posts
    460

    Re: DLR Winforms/Console?

    what is the full form of DLR ?

  3. #3
    Join Date
    Nov 2006
    Posts
    357

    Re: DLR Winforms/Console?

    Im sorry i dont have a clue what you are on about... on the plus side ive managed to scrounge together some info to get me started...

    If anyone else like me is a bit baffled as to how to start... go to codeplex and download ironpython/ruby (NOT THE SILVERLIGHT ONLY VERSIONS ). Then make a console app and add the following:

    Code:
    using System;
    using IronPython.Hosting;
    using Microsoft.Scripting;
    using Microsoft.Scripting.Hosting;
    
    namespace DLRTest
    {
        class Program
        {
            private static ScriptEngine m_ScriptEngine;
            private static ScriptRuntime m_ScriptRuntime;
            private static ScriptScope m_ScriptScope;
    
            static void Main(string[] args)
            {
                m_ScriptEngine = Python.CreateEngine();
                m_ScriptRuntime = m_ScriptEngine.Runtime;
                m_ScriptScope = m_ScriptRuntime.CreateScope();
                
                StartApp();
            
                Console.WriteLine("Press Enter To Exit");
                Console.ReadKey();
            }
    
            static void StartApp()
            {
                int var = 5;
                string Code = "var + 10";
                m_ScriptScope.SetVariable("var", var);
                ScriptSource CodeSource = m_ScriptEngine.CreateScriptSourceFromString(Code, SourceCodeKind.Expression);
                var = (int)CodeSource.Execute(m_ScriptScope);
                Console.WriteLine(var);
            }
        }
    }
    Now i want to be able to bind to objects, so lets say i have an object like below:

    Code:
    public class User
    {
       public int ID;
       public string Name;
       public byte Status;
    }
    i would want to be able to change the values of this object in the DLR and attach to events in the DLR... im sure ive seen various blurbs about people binding events from objects created in c# to objects in the DLR so they will react to mouseover events etc... anyone who can share this knowledge would be a hero in my book!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured