C # Use the reflection development plug-in,
Reflection is required when developing plug-ins. The traversal assembly is dynamically loaded on the client and the methods of each Assembly are called.
To create a console application, first design an interface:
public interface ISay
{
void SaySth();
}
Create the Plugins folder under the console application. The executable files in the console and all Assembly files are generated here. Right-click the console project -- "properties" -- "generate" and set "output path" to the Plugins folder.
Create a class library project Assembly1, add a reference to the console project, and create a class that implements the ISay interface:
namespace Assembly1
{
public class OneSay : ISay
{
public void SaySth()
{
Console. WriteLine ("I'm from Assembly 1 ");
}
}
}
Right-click the class library project Assembly1 -- "attribute" -- "generate", set "output path" to the Plugins folder, and generate the class library project Assembly1.
The client needs to find all classes that implement the ISay interface in all datasets. The basic idea is:
→ Find all dll Suffixes in the Plugins folder
→ Traverse these files and dynamically load the Assembly according to the file name
→ Implement the ISay interface type in the traversal set and save it to the ISay type set.
→ The client traverses the ISay type set and calls the ISay interface method.
class Program
{
static void Main(string[] args)
{
foreach (var say in GetSpeakers())
{
say.SaySth();
}
}
static List<ISay> GetSpeakers()
{
List<ISay> result = new List<ISay>();
// Obtain the Plugins folder under the project root directory
string dir = Directory.GetCurrentDirectory();
// Traverse objects in the target folder that contain the dll suffix
foreach (var file in Directory.GetFiles(dir + @"\", "*.dll"))
{
// Load the Assembly
var asm = Assembly.LoadFrom(file);
// Traverse the types in the Assembly
foreach (var type in asm.GetTypes())
{
// If it is an ISay Interface
if (type.GetInterfaces().Contains(typeof (ISay)))
{
// Create an interface-type instance
var isay = Activator.CreateInstance(type) as ISay;
if (isay != null)
{
result.Add(isay);
}
}
}
}
return result;
}
Create a class library project Assembly2, add a reference to the console project, and create a class that implements the ISay interface:
namespace Assembly2
{
public class TwoSay : ISay
{
public void SaySth()
{
Console. WriteLine ("I am from assembly 2 ");
}
}
}
Right-click the class library project Assembly2 -- "attribute" -- "generate", set "output path" to the Plugins folder, and generate the class library project Assembly2.
Run the console project again.
C :\
Yes
Refer to this to clean up the C drive:
1. Disable System Restoration: My computer properties/System Restoration/disable System Restoration on all disks, but I will not be able to use system restoration in the future!
2. Disable System sleep: Control Panel/Power Supply/sleep/remove the check before starting system sleep
3. move the virtual memory, my computer properties/advanced/performance/settings/advanced/change/select the C disk, that is, the system disk, select the no-score page, and then set the virtual memory to its disk, A disk with more disk space remaining, such as D, E, and F. set to 1.5 ~ of memory ~ 2.5 times. The size can be set to the same!
5. Clear temporary IE folders, internet Options, and delete temporary and offline files.
6. delete system logs and program logs, my computer/control panel/management tools/Computer Management/Event Viewer/application, right-click/clear events, and clear system logs in sequence
7. Clear system cache: 2000 all files in the system: C: \ WINNT \ system32 \ dllcache
The XP system is: C: \ windows \ system32 \ dllcache all files under the system cache (open my computer/tool/file and Folder Options/hide the protected system file hook off to hide all files on the hook) ). You can also run the sfc.exe/purgecache command to automatically delete the file.
8. Clear the recycle bin
9. delete the files under c: \ windows \ SoftwareDistribution \ Download (the files downloaded when the system is updated are useless if you have installed the updates)
10. Delete all directories under c: \ windows \ RegisteredPackages
11. Delete all Files under C: \ WINDOWS \ Downloaded Program Files
12. view the hidden files that are known to be protected by the system in my computer folder option, and check all the files.
13. Delete c: \ windows \ All files with $8882305 $ (backup files after system update)
Zhidao.baidu.com/question/11035955.html
Zhidao.baidu.com/question/12223613.html
Zhidao.baidu.com/question/14874715.html
... The remaining full text>
C :\
Yes
Refer to this to clean up the C drive:
1. Disable System Restoration: My computer properties/System Restoration/disable System Restoration on all disks, but I will not be able to use system restoration in the future!
2. Disable System sleep: Control Panel/Power Supply/sleep/remove the check before starting system sleep
3. move the virtual memory, my computer properties/advanced/performance/settings/advanced/change/select the C disk, that is, the system disk, select the no-score page, and then set the virtual memory to its disk, A disk with more disk space remaining, such as D, E, and F. set to 1.5 ~ of memory ~ 2.5 times. The size can be set to the same!
5. Clear temporary IE folders, internet Options, and delete temporary and offline files.
6. delete system logs and program logs, my computer/control panel/management tools/Computer Management/Event Viewer/application, right-click/clear events, and clear system logs in sequence
7. Clear system cache: 2000 all files in the system: C: \ WINNT \ system32 \ dllcache
The XP system is: C: \ windows \ system32 \ dllcache all files under the system cache (open my computer/tool/file and Folder Options/hide the protected system file hook off to hide all files on the hook) ). You can also run the sfc.exe/purgecache command to automatically delete the file.
8. Clear the recycle bin
9. delete the files under c: \ windows \ SoftwareDistribution \ Download (the files downloaded when the system is updated are useless if you have installed the updates)
10. Delete all directories under c: \ windows \ RegisteredPackages
11. Delete all Files under C: \ WINDOWS \ Downloaded Program Files
12. view the hidden files that are known to be protected by the system in my computer folder option, and check all the files.
13. Delete c: \ windows \ All files with $8882305 $ (backup files after system update)
Zhidao.baidu.com/question/11035955.html
Zhidao.baidu.com/question/12223613.html
Zhidao.baidu.com/question/14874715.html
... The remaining full text>