Click here to Skip to main content
15,884,099 members
Articles / Programming Languages / C#

A Resource Hacker in C# .NET

Rate me:
Please Sign up or sign in to vote.
4.46/5 (14 votes)
6 Mar 2012CPOL6 min read 47.1K   2.1K   37  
How to get into a .NET DLL file and extract its types, show their information, extract the members of each type, and even invoke them.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SampleDll
{
    public class Calc
    {
        public int Add(int x, int y)
        {
            return x + y;
        }
        public int Subtract(int x, int y)
        {
            return x - y;
        }
        public int Multiply(int x, int y)
        {
            return x * y;
        }
        public int DivideBy(int x, int y)
        {
            return x / y;
        }
        public double ShowPI()
        {
            return 3.14;
        }
        public override string ToString()
        {
            return "A Calc";
        }
    }
    public class Person
    {
        private string sampleField = string.Empty;
        public string LastName { get; set; }
        public string FirstName { get; set; }
        public int ID { get; set; }
        public Person()
        {
            FirstName = string.Empty;
            LastName = string.Empty;
            ID = 0;
        }
        public Person(int id,string firstName,string lastName):this(firstName,lastName)
        {
          
            ID = id;
           
        }
        public Person(string firstName, string lastName)
        {
            FirstName = firstName;
            LastName = lastName;
        }
        public override string ToString()
        {
            return "A Person";
        }
        public string ShowData()
        {
            StringBuilder sb=new StringBuilder();
            sb.AppendFormat("ID: {0}, FirstName: {1}, LastName: {2}", ID, FirstName, LastName);
            return sb.ToString();
        }
       
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

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


Written By
Software Developer (Senior)
Iran (Islamic Republic of) Iran (Islamic Republic of)
I'm a software engineer specialized in .NET framework. I've developed applications in such technologies as Console Applications, Windows Forms, WPF, Web Forms, MVC, Silverlight and Xamarin Forms. I also create and publish my multimedia courses at provid.ir and softdevwithmorteza.wordpress.com.
Some of my courses inclue Design Patterns in C#, OOP Principles, SOLID Principles, High Quality Coding Principles, Anti-patterns, Refactoring, TDD, DDD, .NET Core and so on.

Comments and Discussions