silverlight-4.0 - 从 xap 内部的所有 dll 中提取程序集

标签 silverlight-4.0 c#-4.0

我有 silverlight XAP 的字节数组。我需要从字节数组中提取 xap 内的所有 dll。获得 dll 后,我需要从中提取程序集。Silverlight XAP 存储在存储库中,存储库总是返回 XAP 字节数组。C# 中是否有可用的标准 API 来实现此功能?如果没有,我们如何实现这个?

问候,阿布舍克

最佳答案

从字节数组创建一个 MemoryStream 并调用此函数:

public List<Assembly> ExtractAssembliesFromXap(Stream stream) {
        List<Assembly> assemblies = new List<Assembly>();

        string appManifest = new StreamReader(Application.GetResourceStream(
            new StreamResourceInfo(stream, null), new Uri("AppManifest.xaml",
                                       UriKind.Relative)).Stream).ReadToEnd();

        XElement deploy = XDocument.Parse(appManifest).Root;

        List<XElement> parts = (from assemblyParts in deploy.Elements().Elements()
                                select assemblyParts).ToList();

        foreach (XElement xe in parts) {
            string source = xe.Attribute("Source").Value;
            AssemblyPart asmPart = new AssemblyPart();
            StreamResourceInfo streamInfo = Application.GetResourceStream(
                 new StreamResourceInfo(stream, "application/binary"),
                 new Uri(source, UriKind.Relative));

            assemblies.Add(asmPart.Load(streamInfo.Stream));
        }
        return assemblies;
    }

关于silverlight-4.0 - 从 xap 内部的所有 dll 中提取程序集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3801065/

相关文章:

c# - 如何在通用存储库中编写通用内部连接?

asp.net - MVC 的最佳实践.. ViewModel 绑定(bind)使用接口(interface)示例

c#-4.0 - 我可以有一个既是协变又是逆变的类型,即完全可替换/可更改的子类型和 super 类型吗?

c# - 美化 Windows 窗体应用程序

c# - 访问控制的单元测试方法

silverlight - Windows Phone 7 弹出窗口

c# - 重置使用 MEF 加载的控件

silverlight-4.0 - 自定义 WCF RIA 服务终结点

c# - 在 ResourceDictionary 中添加 .cs?

Silverlight 4 文本框不显示所有内容