SharpdevelopProgramThe functions of IDE are scattered into multiple projects. In this way, a project does not need to load too many files, and the compilation speed is also accelerated, in addition, during maintenance, the program can easily replace the corresponding Assembly to implement different functions and component upgrades.
Sharpdevelop also places the Dynamic Loading Function in The addin class, but the loaded assembly is placed in assemlbyhashtable in the addintree. I used a dictinary generic to replace the original hashtable.
Sharpdevelop uses a singleton mode to ensure the uniqueness of addintree,
Private Void Initlization ()
{
System. Diagnostics. Debug. Assert (file. exists (xmlfile ),"The configuration file does not exist." );
Xmldocument Doc= New Xmldocument ();
Doc. Load (xmlfile );
//Load the addin version and author information.
Foreach(ObjectOBJIn Doc. documentelement. childnodes)
{
If(!(OBJIs Xmlelement ))
Continue ;
Xmlelement Curel=OBJAs Xmlelement;
Switch (Curel. Name)
{
Case "Runtime" :
Loadassembly (Curel );
Break ;
Default :
Break ;
}
}
}
Private Void Loadassembly (xmlelement Curel)
{
Foreach(ObjectOBJIn Curel. childnodes)
{
If(!(OBJIs Xmlelement ))
Continue ;
// <Runtime>
// <Import Assembly = "cxytestdll. dll"/>
// </Runtime>
//Retrieve the cxytestdll. dll text.
Xmlelement XE=OBJAs Xmlelement;
StringAsmfilename=Xe. attributes ["Assembly" ]. Innertext;
Debug. Assert (!String. Isnullorempty (asmfilename ),"The Assembly in the runtime node in add cannot be empty, which contains the assembly path." );
//Assebmly path and Load
StringAsmpath=Path. getdirectoryname (xmlfile)+ Asmfilename;
Defaultaddintree. addintree. loadassembly (asmfilename );
}
}
Using System;
Using System. Collections. Generic;
Using System. text;
Using System. Windows. forms;
Using System. reflection;
Namespace Cslearn
{
Public Interface Iaddintree
{
VoidLoadassembly (StringAssemblyfile );
}
Public Class Defaultaddintree: iaddintree
{
Dictionary<String, Assembly> ASM;
defaultaddintree ()
{
ASM= NewDictionary<String, Assembly>();
}
PublicDictionary<String, Assembly> Loadedassembly
{
Get {ReturnASM ;}
}
Static Defaultaddintree Thetree;
//Nonstandard singlton
Public Static Defaultaddintree addintree
{
Get
{
If(Thetree= Null )
Thetree= New Defaultaddintree ();
Return Thetree;
}
}
Iaddintree Member # RegionIaddintree Member
//Check whether assebmly exists in the currently loaded assembly. If so, it is not loaded. Otherwise, it is loaded.
Public VoidLoadassembly (String Assemblyfile)
{
If (ASM. containskey (assemblyfile ))
Return ;
Assembly tpasm= Assembly. loadfrom (assemblyfile );
ASM. Add (assemblyfile, tpasm );
}
# Endregion
}
}