从程序集中公开不同的类型名称(别名) [英] Expose different type names (aliasing) from assembly

查看:36
本文介绍了从程序集中公开不同的类型名称(别名)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题与我之前未回答的问题有关,因为我仍在解决同样的问题;不过,这是一种不同的方法.

This question is related to a previous, unanswered question of mine, as I'm still solving the same problem; this is about a different approach though.

我目前在 C# .NET 项目中使用第三方 SOAP Web 服务.不幸的是,生成的客户端代理类和类成员的名称与我当前的约定不一致.

I'm currently consuming a third-party SOAP web service in a C# .NET project. Unfortunately, the generated client proxy classes and class members have names that are inconsistent with my current conventions.

除非另有建议,否则我认为 Svcutil 不支持别名(不过,在那个级别似乎最容易实现)

Until advised otherwise, I'm left to presume that Svcutil doesn't support aliasing (though, it certainly seem it would be most easily accomplished at that level)

我现在正在考虑将 Web 服务消费包装到它自己的项目中,即组装,并简单地从其他项目中引用它.我正在考虑这一点,因为可以添加一些(大概是程序集级别的)声明来公开名称与程序集中定义的名称不同的公共类型.

I'm now considering wrapping the web service consumption into it's own project, thus assembly, and simply referencing that from other projects. I'm considering this given that it's possible to add some (presumably, assembly-level) declarations to expose the public types with different names than those defined within the assembly.

我的问题是;是否可以公开与程序集中定义的类型/成员名称不同的类型/成员名称,本质上是它们的别名?

例如,给定一个神奇的程序集属性:

For example, given a magical assembly attribute:

[assembly: AssemblyTypeAlias(
    Type = typeof(Foo.Bar.qux),
    Name = "Qux"
)]

因此,引用此程序集的项目将访问 Foo.Bar.qux 作为 Foo.Bar.Qux.

Thus, projects referencing this assembly would access Foo.Bar.qux as Foo.Bar.Qux.

当然,类似的类级别属性也很好,因为生成的代理是partial:

Of course, a similar class-level attribute would be great too, seeing as the generated proxies are partial:

namespace Foo.Bar
{
    [Alias("Qux")]
    public partial class qux 
    {
    }
}

产生相同的效果.

虽然我只用我的理论示例介绍了类型名称,但允许成员名称别名的解决方案将壮观.

While I've only covered type names with my theoretical examples, a solution that allows the aliasing of member names would be spectacular.

编辑:我已经说过别名",其中更适用的术语是重命名",以隐藏原始名称;最好是后者,但前者也行.

Edit: I've said "alias", where the more applicable term would be "rename", in order to hide the original name; preferably the latter, but the former will work.

推荐答案

我已将此建议在服务引用中使用 XmlType 属性的答案移至您的 另一个问题,因为这个问题实际上是在询问别名程序集,无论它们是否来自服务.

I've moved this answer suggesting use of the XmlType Attribute in the Reference to the Service to your other question, since this one is really asking about aliasing assemblies, whether they come from a service or not.

这篇关于从程序集中公开不同的类型名称(别名)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆