[C#] Assembly =)

Results 1 to 5 of 5
  1. #1
    akakori akakori is offline
    MemberRank
    Apr 2008 Join Date
    613Posts

    [C#] Assembly =)

    Place this in a text file
    Code:
    1%this%that%what
    1:What do you want to achieve this or that?:this:Say you have achieved this:that:say you have achieved that:what:What is it
    Code:
    using System;
    using System.Collections;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Reflection;
    using System.IO;
    
    namespace AssemblyTest
    {
        public class Program
        {
            static Dictionary<string, string> dict = new Dictionary<string, string>();
            static string[] choices;
            static void Main(string[] args)
            {
                Load();
                Console.WriteLine(dict["1"]);
                wait();
    
            }
    
            public static void wait()
            {
                while (true)
                {
                    string choice = Console.ReadLine();
                    if(choices.Contains(choice)) 
                    {
                        invokeWrite("DynamicFunction", "writeLine", new object[1] { dict[choice] });
                    }
                }
            }
    
            public static void invokeWrite(string tarClass, string tarMethod, object[] objs)
            {
                foreach (Type t in Assembly.GetExecutingAssembly().GetTypes())
                {
                    if (t.FullName.EndsWith(tarClass))
                    {
                        Object asb = Activator.CreateInstance(t);
                        MethodInfo mi = asb.GetType().GetMethod(tarMethod);
                        mi.Invoke(asb, objs);
                    }
                }
            }
    
            static void Load()
            {
                TextReader tr = new StreamReader(@"C:\Documents and Settings\%user%\My Documents\test.txt");
                choices = tr.ReadLine().Split('%');
                string[] process2 = tr.ReadToEnd().Split(':');
    
                for (int i = 0; i < process2.Length; i += 2)
                {
                    dict.Add(process2[i], process2[i + 1]);
                }
            }
        }
    
        public class DynamicFunction
        {
            public static void writeLine(string args)
            {
                Console.WriteLine(args);
            }
        }
    }

    Edit this line
    TextReader tr = new StreamReader(@"C:\Documents and Settings\%user%\My Documents\test.txt");

    change it to your text location...


    Assembly is used for runtime execution of functions that have been compiled. =) The above shows a very simple script.


  2. #2
    WowIwasSuperCringeB4 XZeenon is offline
    MemberRank
    Jun 2008 Join Date
    CanadaLocation
    1,405Posts

    Re: [C#] Assembly =)

    What is the point of this? :D

  3. #3
    akakori akakori is offline
    MemberRank
    Apr 2008 Join Date
    613Posts

    Re: [C#] Assembly =)

    the power of assembly.. if tapped well.. you will end up with a script engine.. =)

    or it is possible to get cloud service too =)

  4. #4
    Ginger by design. jMerliN is offline
    MemberRank
    Feb 2007 Join Date
    2,497Posts

    Re: [C#] Assembly =)

    Not really what we mean in computer science when we talk about "assembly"... And this doesn't seem very useful, if you want a scripting engine in C# use something like IronPython. It's far better than anything you're going to write.

  5. #5
    akakori akakori is offline
    MemberRank
    Apr 2008 Join Date
    613Posts

    Re: [C#] Assembly =)

    it is built on similar concept.. by invoking and creating instance of the class by catching it on assembly..

    yea its not very useful unless its fully worked on.. =(



Advertisement