C # Study Notes 02 ---- custom class libraries and decompilation,

Source: Internet
Author: User

C # Study Notes 02 ---- custom class libraries and decompilation,

2.1 custom class library

The custom class library can encapsulate the core code to ensure that the core code is not leaked when delivered to the customer, but also to prevent unauthorized changes by non-professionals. In addition, it can improve the Reuse Rate of program code, reduce the amount of code, and simplify the program structure.A custom class library is a common. dll file in a program.

Create a user-defined class library for people. In fact, it is the same as the export package in java.

The difference between a class library and a portable class library is that the class library is used on a Windows PC and can be used on other platforms, such as Windows Mobile Phones. Create a new class library Class1 with pelple as the namespace and use two attributes and one method for testing.

  

1 using System; 2 using System. collections. generic; 3 using System. linq; 4 using System. text; 5 using System. threading. tasks; 6 7 namespace people 8 {9 public class Class110 {11 // attribute 12 private string name; 13 private int age; 14 // constructor 15 public Class1 () {// No parameter construction 16} 17 public Class1 (string name, int age) {18 this. name = name; 19 this. age = age; 20} 21 22 23 // get/set Method 24 public string class1Name {25 ge T {26 return name; 27} 28 set {29 name = value; 30} 31} 32 33 public int class1Age {34 get {35 return age; 36} 37 38 set {39 age = value; 40} 41 42} 43 // custom method 44 public String sayHello () {45 string rtg; 46 Class1 c = new Class1 (); 47 c. name = "wuxinwuxin"; 48 c. age = 18; 49 rtg = "Hello everyone! I am "+ c. age +" "+ c. name; 50 return rtg; 51} 52 53 54} 55}

Right-click the project and choose generate (U. Find the debug folder where the project is located and find the generated class library.

The test code is as follows:

1 using System; 2 using System. collections. generic; 3 using System. data; 4 using System. drawing; 5 using System. linq; 6 using System. reflection; 7 using System. text; 8 using System. threading. tasks; 9 using System. windows. forms; 10 using people; // custom class library 11 12 private void button4_Click (object sender, EventArgs e) 13 {14 Class1 c = new Class1 (); 15 c. class1Name = "test"; 16 textBox1.Text = c. class1Name; 17 string rtg = c. sayHello (); 18 textBox1.Text + = "/*" + rtg; 19 20}

Shown as follows:

When other programs need to use the classes and methods under my people namespace. if you copy a dll file, it will be okay and you do not need to implement it again. Of course, such a class library must be highly reusable, such as connecting to oracle. dll class library, otherwise I don't feel much necessary, unless it ensures code security, so that when someone else calls this class library, he doesn't have to worry about how I implement it internally, this is not a good thing for those who later took over the maintenance program?

 

2.2 Decompilation

DecompilationIn the previous inverse process, sometimes when we are curious about the dll class libraries provided by others, we need to decompile them when we want to study how they are implemented .. Once a dll file is generated, common text readers including VS and computers cannot be opened. In this case, a software Reflector is required to open the file. dll files (not all files can be decompiled. The latest version may have strong decompilation capabilities! ).

The software is easy to use. Open people. dll.

 

 

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.