2. Dynamic addition and use type
Reflection provides an infrastructure used by a language compiler (such as Microsoft Visual Basic .NET and JScript) to implement implicit late binding. The binding is a process of finding a declaration (ie implementing) corresponding to the uniquely specified type. Since this process occurs during runtime instead of compile, it is called a late binding. Visual Basic .NET allows you to use implicit late bindings in your code; the Visual Basic compiler will call a helper method that uses reflection to get an object type. Parameters passing to the help method helps to call the correct way at runtime. These parameters include: instances (objects) of their calling method, the name of the modified method (string), and the parameters pass to the called method (an array).
The following example is a GetDataSet method in the dynamically called dynamic link library, which requires parameters String UserID
AskEMBLY Assembly;
TYPE TYPE;
String DLLPATH = @ "d: /test/powerspace.vcp.utility.dll";
Try
{
askEMBLY = askFILE (DLLPATH);
TYPE = ask ("PowerSpace.vcp.utility.cmystring", true, true); // CMYRESULT
}
Catch (filenotfoundexception)
{
Response.write ("Could Not Load Assembly: /" DLLPATH "/");
Return NULL;
}
Catch (TypeLoadException)
{
Response.write ("COULD NOT LOAD TYPE: /" String / "/ N from assembly: /" "" DLLPATH "/" "); Return NULL
}
MethodInfo method = type.getMethod ("Testinvoke");
Object obj = assembly.getassembly (Type) .createInstance ("PowerSpace.vcp.utility.getDataSet");
Object s = method.invoke (Obj, new object [] {"jiangli"});
DataSet SS = (Dataset) S;
askEMBLY = NULL;
TYPE = NULL;
Method = NULL;
Return ss;
3. Access custom properties
Access custom properties and dynamically add and use types.
How? Is it difficult to reflex? Oh, or go to research research. Have something to contact me: mailto: jljkyh@163.com