拡張メソッドの解決方法で予期しない動作が発生することがあります。その理由を理解しようとしています。私はEric Lippert's Closer is Betterの記事を読んだが、私はまだ混乱している。正しい拡張方法の解像度を確認する方法
まず呼び出しサイト:二つの異なるアセンブリでは、私は2つの異なる名前空間にIOrganziationServiceに拡張メソッドのオーバーロードを定義している
// Assembly: Microsoft.Xrm.Sdk
void Delete(string entityName, Guid id);
:
// Assembly: DLaB.Xrm.2016.Tests
using DLaB.Xrm.Entities;
using DLaB.Xrm.Test;
using Microsoft.Xrm.Sdk;
namespace DLaB.Xrm.Tests
public class TrialClass{
{
public void Delete(){
IOrganziationService service = GetService();
Id<Contact> id = GetId();
service.Delete(id); // Call Site in Question
}
}
}
IOrganizationServiceはこの署名でdeleteメソッドを定義します:
//Assembly: DLaB.Xrm.2016
//Namespace DLaB.Xrm
public static void Delete(this IOrganizationService service, Entity entity) { ... }
public static void Delete(this IOrganizationService service, EntityReference entity) { ... }
//Assembly: DLaB.Xrm.Test.2016
//Namespace DLaB.Xrm.Test
public static void Delete(this IOrganizationService service, Id id) { ... }
public static void Delete<T>(this IOrganizationService service, Id<T> entity) where T : Entity { ... }
私は私が定義されてきた私の暗黙の事業者からの理解Entity
またはEntityReference
The Call Site
service.Delete(id)
shows a compiler error: Error CS0121 The call is ambiguous between the following methods or properties: 'Extensions.Delete(IOrganizationService, Entity)' and 'Extensions.Delete(IOrganizationService, EntityReference)'
に変換イドクラスのために定義された暗黙の演算子。私が理解していないのは、DLaB.Xrm
名前空間がDLaB.Xrm.Test
名前空間よりも近い理由です。なぜなら、私はそれにディレクティブを使用していません。