我正在使用xsltc.exe
从A.dll
创建A.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
并进行转换?
答案 0 :(得分:1)
如果我理解正确,那么您希望在运行时全部生成并引用DLL。好消息是您可以在运行时使用Assembly.LoadFrom
加载程序集。
以下摘录自documentation,该技术称为反射。
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());
}