|
// file : ExtensionRepository.RepositoryItemTargetKey.cs
// project : UniversalTypeExtender
// author : Thorsten Bruning
// date : 18.10.2011
using System;
namespace TB.ComponentModel.Infrastructure {
partial class ExtensionRepository {
/// <summary>
/// Represents the key of an ExtensionRepositoryItem.
/// Only for infrastructure.
/// </summary>
public class RepositoryItemTargetKey {
private readonly WeakReference mTarget;
private readonly int mHashCode;
/// <summary>
/// Gets the target.
/// </summary>
public object Target {
get { return mTarget.Target; }
}
/// <summary>
/// Initializes a new instance of the RepositoryItemTargetKey class.
/// </summary>
/// <param name="target">RepositoryItem.</param>
public RepositoryItemTargetKey(object target) {
mTarget = new WeakReference(target);
if(target != null) {
mHashCode = target.GetHashCode();
}
}
/// <summary>
/// Serves as a hash function for this type.
/// </summary>
/// <returns>A hash code for this instance.</returns>
public override int GetHashCode() {
return mHashCode;
}
/// <summary>
/// Determines whether the specified object is equal to this instance.
/// </summary>
/// <param name="obj">The object to compare with this instance.</param>
/// <returns>true if the specified object is equal to this instance otherwise, false.</returns>
public override bool Equals(object obj) {
if (obj == null) {
return false;
}
if (obj.GetType() != GetType()) {
return false;
}
object target = Target;
object objectsTarget = ((RepositoryItemTargetKey)obj).Target;
if (target == null && objectsTarget == null) {
return true;
}
if (target == null) {
return false;
}
if(objectsTarget == null) {
return false;
}
return target.Equals(objectsTarget);
}
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.