0

我正在xsltc.exe使用A.dllA.xslt. 然后A.dll在我的项目中引用并进行转换:

XslCompiledTransform xslt = new XslCompiledTransform();
xslt.Load(typeof(A)); // A is a public static class from A.dll
xslt.Transform(RootPath + "A.xml", RootPath + "A.txt");

但是我如何A.dll在运行时参考并进行转换?

4

1 回答 1

1

如果我理解正确,您希望在运行时生成和引用 DLL。好消息是您可以在运行时使用Assembly.LoadFrom.

以下内容取自文档,该技术称为反射。

Assembly SampleAssembly;
SampleAssembly = Assembly.LoadFrom("c:\\A.dll");
// Obtain a reference to a method known to exist in assembly.
var aTypes = SampleAssembly.GetTypes();
MethodInfo Method = aTypes[0].GetMethod("Method1");
// Obtain a reference to the parameters collection of the MethodInfo instance.
ParameterInfo[] Params = Method.GetParameters();
// Display information about method parameters.
// Param = sParam1
//   Type = System.String
//   Position = 0
//   Optional=False
foreach (ParameterInfo Param in Params)
{
    Console.WriteLine("Param=" + Param.Name.ToString());
    Console.WriteLine("  Type=" + Param.ParameterType.ToString());
    Console.WriteLine("  Position=" + Param.Position.ToString());
    Console.WriteLine("  Optional=" + Param.IsOptional.ToString());
}
于 2019-02-01T09:13:46.437 回答