简体   繁体   English

如何重命名并公开第3方dll中的类型

[英]How to rename and exposes a type from the 3rd party dll

Is there a way for a custom assembly to rename and exposes a type from the 3rd party dll? 有没有一种方法可以使自定义程序集重命名并公开来自第三方dll的类型?

// Assembly Foo (cannot change code)
namespace Foo
{
    enum XValues
    {
        Val1, Val2;
    }
}

// Assembly Bar
// References Foo
namespace Bar
{
    using Foo;
    // Code that exposes Foo.XValues as Bar.YValues
}

// Assembly Client
// References Bar
namespace Client
{
    void Main() {
        Console.WriteLine(Bar.YValues.Val1);
    }
}

Is there a way for a custom assembly to rename and exposes a type from the 3rd party dll? 有没有一种方法可以使自定义程序集重命名并公开来自第三方dll的类型?

No, is the short answer. 不,是简短的答案。 A type is a type is a type. 一个类型就是一个类型。 You could create your own enum in Bar which has the same values, and convert between them where you need to. 您可以在Bar创建具有相同值的自己的枚举,并在需要时在它们之间进行转换。

What are you trying to achieve - what's the bigger picture? 您想达到什么目标?更大的前景是什么? There may well be a better solution than the one you're thinking of. 可能有比您正在考虑的解决方案更好的解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM