Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/333.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在运行时从dll引用静态类_C#_Xslt_Dll_Xsltc - Fatal编程技术网

C# 如何在运行时从dll引用静态类

C# 如何在运行时从dll引用静态类,c#,xslt,dll,xsltc,C#,Xslt,Dll,Xsltc,我正在从A.xslt使用xsltc.exe创建A.dll。 然后在我的项目中引用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并进行转换

我正在从
A.xslt
使用
xsltc.exe
创建
A.dll
。 然后在我的项目中引用
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
并进行转换呢?

如果我理解正确,您希望在运行时同时生成和引用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());
}

我只想从dll中得到我的类
A
,你的代码有
Method1
,我不知道应该替换什么,因为类
A
中没有方法。谢谢,我忘了提到我想在运行时生成和引用DLL我更新了一点代码-在var-aTypes=samplessembly.GetTypes()上设置一个断点;MethodInfo方法=类型[0]。GetMethod(“方法1”);并使用VisualStudio中的watch功能检查aTypes对象。这将列出您的课程。aTypes[0]只是引用程序集中的第一个类。