Ejemplo n.º 1
0
    public void Snippet11()
    {
        Console.WriteLine("SNIPPET11:");
        // <Snippet11>
        Assembly SampleAssembly;

        SampleAssembly = Assembly.LoadFrom("c:\\Sample.Assembly.dll");
        // Obtain a reference to a method known to exist in assembly.
        MethodInfo Method = SampleAssembly.GetTypes()[0].GetMethod("Method1");

        // Obtain a reference to the parameters collection of the MethodInfo instance.
        ParameterInfo[] Params = Method.GetParameters();
        // Display information about method parameters.
        // Param = sParam1
        //   Type = System.String
        //   Position = 0
        //   Optional=False
        foreach (ParameterInfo Param in Params)
        {
            Console.WriteLine("Param=" + Param.Name.ToString());
            Console.WriteLine("  Type=" + Param.ParameterType.ToString());
            Console.WriteLine("  Position=" + Param.Position.ToString());
            Console.WriteLine("  Optional=" + Param.IsOptional.ToString());
        }
        // </Snippet11>
        Console.ReadLine();
    }
Ejemplo n.º 2
0
    public void Snippet9()
    {
        Console.WriteLine("SNIPPET9:");
        // <Snippet9>
        Assembly SampleAssembly;

        SampleAssembly = Assembly.LoadFrom("c:\\Sample.Assembly.dll");

        // Obtain a reference to the first class contained in the assembly.
        Type oType = SampleAssembly.GetTypes()[0];

        // Obtain a reference to the public properties of the type.
        PropertyInfo[] Props = oType.GetProperties();
        // Display information about public properties of assembly type.
        // Prop = Prop1
        //    DeclaringType = Sample.Assembly.Class1
        //    Type = System.String
        //    Readable = True
        //    Writable = False
        foreach (PropertyInfo Prop in Props)
        {
            Console.WriteLine("Prop=" + Prop.Name.ToString());
            Console.WriteLine("  DeclaringType=" + Prop.DeclaringType.ToString());
            Console.WriteLine("  Type=" + Prop.PropertyType.ToString());
            Console.WriteLine("  Readable=" + Prop.CanRead.ToString());
            Console.WriteLine("  Writable=" + Prop.CanWrite.ToString());
        }
        // </Snippet9>
        Console.WriteLine();
    }
Ejemplo n.º 3
0
 public static void Main(string[] args)
 {
     try
     {
         Assembly SampleAssembly;
         SampleAssembly = Assembly.LoadFrom("c:\\Sample.Assembly.dll");
         // Obtain a reference to a method known to exist in assembly.
         MethodInfo Method = SampleAssembly.GetTypes()[0].GetMethod("Method1");
         // Obtain a reference to the parameters collection of the MethodInfo instance.
         ParameterInfo[] Params = Method.GetParameters();
         // Display information about method parameters.
         // Param = sParam1
         //   Type = System.String
         //   Position = 0
         //   Optional=False
         foreach (ParameterInfo Param in Params)
         {
             Console.WriteLine("Param=" + Param.Name.ToString());
             Console.WriteLine("  Type=" + Param.ParameterType.ToString());
             Console.WriteLine("  Position=" + Param.Position.ToString());
             Console.WriteLine("  Optional=" + Param.IsOptional.ToString());
         }
     }
     catch (Exception exc)
     {
         Console.WriteLine(exc);
     }
     finally
     {
         Console.ReadKey(true);
     }
 }
Ejemplo n.º 4
0
    public void Snippet8()
    {
        Console.WriteLine("SNIPPET8:");
        // <Snippet8>
        Assembly SampleAssembly;

        SampleAssembly = Assembly.Load("System.Data");
        Type[] Types = SampleAssembly.GetTypes();
        foreach (Type oType in Types)
        {
            Console.WriteLine(oType.Name.ToString());
        }
        // </Snippet8>
        Console.WriteLine();
    }
Ejemplo n.º 5
0
    public void Snippet7()
    {
        Console.WriteLine("SNIPPET7:");
        // <Snippet7>
        Assembly SampleAssembly;

        // Load the assembly by providing the type name.
        SampleAssembly = Assembly.Load("MyAssembly");
        foreach (String Resource in SampleAssembly.GetManifestResourceNames())
        {
            Console.WriteLine(Resource);
        }
        // </Snippet7>
        Console.WriteLine();
    }
Ejemplo n.º 6
0
    public void Snippet6()
    {
        Console.WriteLine("SNIPPET6:");
        // <Snippet6>
        Assembly SampleAssembly;

        // Load the assembly by providing the location of the assembly file.
        SampleAssembly = Assembly.LoadFrom("c:\\Sample.Assembly.dll");
        foreach (Type ExportedType in SampleAssembly.GetExportedTypes())
        {
            Console.WriteLine(ExportedType.ToString());
        }
        // </Snippet6>
        Console.WriteLine();
    }
Ejemplo n.º 7
0
    public void Snippet10()
    {
        Console.WriteLine("SNIPPET10:");
        // <Snippet10>
        Assembly SampleAssembly;

        SampleAssembly = Assembly.LoadFrom("c:\\Sample.Assembly.dll");
        MethodInfo[] Methods = SampleAssembly.GetTypes()[0].GetMethods();
        // Obtain a reference to the method members
        foreach (MethodInfo Method in Methods)
        {
            Console.WriteLine("Method Name=" + Method.Name.ToString());
        }
        // </Snippet10>
        Console.WriteLine();
    }
Ejemplo n.º 8
0
 private void Button_Click_1(object sender, RoutedEventArgs e)
 {
     if (lab1.Content != "")
     {
         items = new ObservableCollection <Item>();
         string   filename;
         string   directory = lab1.Content.ToString();
         string[] files     = Directory.GetFiles(directory, "*.dll", SearchOption.AllDirectories);
         Assembly SampleAssembly;
         foreach (string file in files)
         {
             filename = System.IO.Path.GetFileName(file);
             Item item = new Item {
                 Name = filename, Items = new ObservableCollection <Item>()
             };
             SampleAssembly = Assembly.LoadFrom(file);
             foreach (Type oType in SampleAssembly.GetTypes())
             {
                 Item item2 = new Item {
                     Name = oType.Name, Items = new ObservableCollection <Item>()
                 };
                 foreach (MethodInfo members in oType.GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly | BindingFlags.NonPublic))
                 {
                     if (members.IsFamily || members.IsPublic)
                     {
                         item2.Items.Add(new Item {
                             Name = members.Name
                         });
                     }
                 }
                 item.Items.Add(item2);
             }
             items.Add(item);
         }
         viewTree.ItemsSource = items;
     }
 }
        public static void ExtractFunctionsFromDll()
        {
            Assembly SampleAssembly;
            //SampleAssembly = Assembly.LoadFrom("BlingResource.dll");
            //SampleAssembly = Assembly.LoadFrom("SatoriFunctoids.dll");

            var dllBytes = File.ReadAllBytes("SatoriFunctoids.dll");

            SampleAssembly = Assembly.Load(dllBytes);

            var types = SampleAssembly.GetTypes().ToList();

            using (var wr = new StreamWriter("methodInfo1.txt"))
            {
                foreach (var type in types)
                {
                    var methods = type.GetMethods().ToList();
                    methods.ForEach(t =>
                    {
                        string output = string.Empty;
                        //Console.WriteLine(t.Name);
                        var customizedAttributes = t.CustomAttributes.ToList();
                        if (customizedAttributes.Count != 0)
                        {
                            var attributeNames = customizedAttributes.Select(a => a.AttributeType.Name);
                            if (attributeNames.Contains("FunctoidAttribute"))
                            {
                                output         += t.ReturnType + " ";
                                output         += t.Name + " (";
                                var parammeters = t.GetParameters().ToList();
                                parammeters.ForEach(k =>
                                {
                                    output += k.ParameterType + " " + k.Name + ", ";
                                    //Console.WriteLine("type: {0}, value: {1}", k.ParameterType, k.Name);
                                });
                                if (parammeters.Count != 0)
                                {
                                    output = output.Substring(0, output.Length - 2);
                                }
                                output += ")";

                                output = output.Replace("System.Collections.Generic.", "");
                                output = output.Replace("System.", "");
                                output = output.Replace("`1[", "<");
                                output = output.Replace("`2[", "<");
                                output = output.Replace("]", ">");
                                output = output.Replace("[>", "[]");

                                Regex regex = new Regex("Nullable<(.*?)>");
                                var v       = regex.Match(output);
                                string s    = v.Groups[1].ToString();
                                Console.WriteLine(s);
                                output = output.Replace($"Nullable<{s}>", $"{s}?");
                                output = output.Replace("Nullable<", "");
                                Console.WriteLine(output);
                                wr.WriteLine(output);
                            }
                        }
                    });
                }
            }


            //// Obtain a reference to a method known to exist in assembly.
            //MethodInfo Method = SampleAssembly.GetTypes()[0].GetMethod("Method1");
            //// Obtain a reference to the parameters collection of the MethodInfo instance.
            //ParameterInfo[] Params = Method.GetParameters();
            //// Display information about method parameters.
            //// Param = sParam1
            ////   Type = System.String
            ////   Position = 0
            ////   Optional=False
            //foreach (ParameterInfo Param in Params)
            //{
            //    Console.WriteLine("Param=" + Param.Name.ToString());
            //    Console.WriteLine("  Type=" + Param.ParameterType.ToString());
            //    Console.WriteLine("  Position=" + Param.Position.ToString());
            //    Console.WriteLine("  Optional=" + Param.IsOptional.ToString());
            //}
        }