C#接口断裂,ABI [英] C# interface breakage, ABI

查看:209
本文介绍了C#接口断裂,ABI的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我们有类X 在装配 A.DLL 的版本1:

Suppose we have the class X in version 1 of the assembly A.dll:

class X {
    SomeType Property { set; get; }
}

然后在装配 A.DLL 第2版:

class X {
    SomeType Property { set; get; }
    SomeType OtherProperty { set; get; }
}

现在假设我们有一个第二组件 B.DLL ,加载 A.DLL 和使用十请问此外,财产 OtherProperty 打破ABI的?将 B.DLL 无法使用 A.DLL / X ?如果没有,就声明的顺序有什么区别?如果财产是虚拟的,有它做什么区别?

Now suppose we have a second assembly B.dll that loads A.dll and uses X. Will the addition of the property OtherProperty break the ABI? Will B.dll fail to use A.dll/X? If not, would the order of the declarations make any difference? If the properties had been virtual, had it made any difference?

我想我真的问:什么是一般ABI规则?我知道改变接口后,他们已出版是一件坏事,但我真的想能的添加的一些实例的属性,而无需添加子类。

I guess I'm really asking: what are the general ABI rules? I know changing interfaces after they have been published is a bad thing, but I really would like to be able to add properties in some instances, without adding subclasses.

推荐答案

添加属性应该是不错。

一个案例,这将打破,如果是你,例如添加的东西到自动编号枚举的中间。例如,如果你有这样的code库中的:

One case that will break is if you for example add something to the middle of an automatically numbered enum. For example if you have this code in your library:

enum Foo
{
   Bar,
   Qux
}

和你改成这样:

enum Foo
{
   Bar,
   Baz,
   Qux
}

然后,你还需要重新编译code是这样的:

Then you will also need to recompile any code like this:

if (foo == Foo.Qux)
{
    //  ...
}

这篇关于C#接口断裂,ABI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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