カスタム オブジェクトをディクショナリ、リストなどで正しく機能させる必要があります。これにより、オブジェクトのプロパティを変更し、再ソートして孤立させないようにすることができます。
前回 GetHashCode() のオーバーライドを試みたとき、オブジェクトをディクショナリに追加したときにオブジェクトを孤立させ、オブジェクトに変更を加えた (GetHashCode が変更された) ため、ディクショナリがメモリからオブジェクトを適切に破棄できませんでした。
質問
誰かが説明できますか:
int
ソートされたディクショナリで連結してTrustedEntity
正しく機能させるために、TrustedEntityReference でオーバーライドする必要があるインターフェイスとインターフェイスは何ですか?.NET ディクショナリ オブジェクトで使用されているものに関して変更してはならない値、またはオブジェクトを孤立させるリスクがある値はどれですか? (たとえば、オブジェクトの発行されたハッシュコードを変更すると、辞書で GC の問題が発生する可能性があります)
これは、私が取り組んでいる現在のサンプル オブジェクトです。
namespace Model
{
public class TrustedEntity
{
public TrustedEntity()
{
this.BackTrustLink = new List<TrustedEntityReference>();
this.ForwardTrustLink = new List<TrustedEntityReference>();
}
public List<TrustedEntityReference> BackTrustLink { get; set; }
public string EntryName { get; set; }
public List<TrustedEntityReference> ForwardTrustLink { get; set; }
}
// This is the object I want to be treated as a "key" in the above List<T>
// I want a duplicate object exception to occur if a duplicate TrustedEntityReference is inserted into trustedEntity.BackTrustLink or trustedEntity.ForwardTrustLink
public class TrustedEntityReference
{
public int HierarchyDepth { get; set; }
public TrustedEntity TrustedEntity {get; set; }
}
}