Expose different type names (aliasing) from assembly

旧时模样 提交于 2019-12-05 01:05:14

问题


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.

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.

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)

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.

My question is; is it possible to expose different type/member names than those defined in the assembly, essentially aliasing them?

For example, given a magical assembly attribute:

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

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

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 
    {
    }
}

Yielding the same effect.

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.


回答1:


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.



来源:https://stackoverflow.com/questions/22408104/expose-different-type-names-aliasing-from-assembly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!