私は彼らのURIに基づいてオブジェクトのコレクションを維持しようとしている:EqualsメソッドでUriのフラグメントが無視されるのはなぜですか?
public class ConceptCollection : KeyedCollection<Uri, Concept> {
protected override Uri GetKeyForItem(Concept item) {
return item.Uri;
}
}
しかし、URIをウリのフラグメントに基づいて定期的にのみ異なります。
ConceptCollection wines = new ConceptCollection();
Concept red = new Concept("http://www.w3.org/2002/07/owl#RedWine");
Concept white = new Concept("http://www.w3.org/2002/07/owl#WhiteWine");
wines.Add(red);
wines.Add(white); // Error: An item with the same key has already been added.
http://msdn.microsoft.com/en-us/library/f83xtf15.aspxパー:
The Equals method compares the two instances without regard to user information (UserInfo) and fragment ( Fragment) parts that they might contain. For example, given the URIs http://www.contoso.com/index.htm#search and http://user:[email protected]/index.htm , the Equals method would return true.
私はこの周りをハックすることに辞任していますので、以下のエラーが発生します。しかし、それはなぜこのように振舞うのでしょうか?私は、ユーザー情報のロジックを見ることができますが、フラグメントは見えません。
私が扱ってきたRDFフレームワークは、.NET System.Uriの実装で独自のUriクラスを実装しなければならず、元のUriの純度は維持されません。あなたはSystem.Uri.OriginalStringを使用してこれを小さなプロジェクトで回避することができます。同様の問題は何度も何度も繰り返されます。 –