3 回答

TA貢獻1775條經驗 獲得超8個贊
System.Reflection.Assembly dll = System.Reflection.Assembly.LoadFile("文件路徑");
Stream xmls = dll.GetManifestResourceStream("a.dll的命名空間.項目中的文件路徑.文件名");
后面就可以把這個xml作為正常的xml文件的流來使用了。
不好意思,只是按照自己的想法寫的。沒有去實踐。
這個問題是我寫錯函數了。用load函數的話。參數是dll的命名空間。我已經改了上面的source。
你試一下。
試了一下,這樣就好用了。
LoadFile,中的參數是你的dll的路徑。不是xml的路徑。

TA貢獻2021條經驗 獲得超8個贊
System.Reflection.Assembly dll = System.Reflection.Assembly.LoadFile("文件路徑");
Stream xmls = dll.GetManifestResourceStream("a.dll的命名空間.項目中的文件路徑.文件名");

TA貢獻1811條經驗 獲得超6個贊
以下是我的代碼
將我的自定義類的內容去掉以后就是獲取DLL的嵌入資源的代碼了
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
namespace Madison.Server.MethodFactory
{
public class MethodFactory
{
private static Assembly dllAssembly = null;
private MethodFactory() { }
private static List<MadisonMethodInfo> allMethodInfo = new List<MadisonMethodInfo>();
public static MethodFactory LoadDll(string dllFilePath)
{
dllAssembly = Assembly.LoadFile(dllFilePath);
var allTypes = dllAssembly.GetTypes();
LoadAllMethod(allTypes.ToList());
return new MethodFactory();
}
private static void LoadAllMethod(List<Type> allTypes)
{
if (allTypes.Count > 1)
{
var typeMethods = allTypes[0].GetMethods();
for (int i = 0; i < typeMethods.Count(); i++)
{
if (
typeMethods[i].GetCustomAttribute(typeof(MadisonMethodAttribute)) != null
&&
(typeMethods[i].GetCustomAttribute(typeof(MadisonMethodAttribute)) as MadisonMethodAttribute).UsingMethod
)
{
allMethodInfo.Add(MadisonMethodInfo.Create(typeMethods[i]));
}
}
}
}
}
}
- 3 回答
- 0 關注
- 161 瀏覽
添加回答
舉報