You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
57 lines
1.3 KiB
57 lines
1.3 KiB
using System;
|
|
|
|
/// <summary>装箱类。</summary>
|
|
public class Class<T>
|
|
{
|
|
|
|
private bool _hashcode = false;
|
|
private bool _equals = false;
|
|
|
|
/// <summary>装箱对象。</summary>
|
|
public T Value;
|
|
|
|
/// <summary></summary>
|
|
public bool IsNull
|
|
{
|
|
get { return Value == null; }
|
|
}
|
|
|
|
/// <summary>创建默认值。</summary>
|
|
public Class(T value = default, bool tryValueEquals = true, bool tryValueHashCode = true)
|
|
{
|
|
Value = value;
|
|
_hashcode = tryValueHashCode;
|
|
_equals = tryValueEquals;
|
|
}
|
|
|
|
/// <summary></summary>
|
|
public override int GetHashCode()
|
|
{
|
|
if (_hashcode && Value != null)
|
|
{
|
|
return Value.GetHashCode();
|
|
}
|
|
return base.GetHashCode();
|
|
}
|
|
|
|
/// <summary></summary>
|
|
public override bool Equals(object obj)
|
|
{
|
|
if (_equals)
|
|
{
|
|
if (Value == null && obj == null) return true;
|
|
if (Value == null && obj != null) return false;
|
|
if (Value != null && obj == null) return false;
|
|
return Value.Equals(obj);
|
|
}
|
|
return base.Equals(obj);
|
|
}
|
|
|
|
/// <summary></summary>
|
|
public override string ToString()
|
|
{
|
|
if (Value == null) return null;
|
|
return Value.ToString();
|
|
}
|
|
|
|
}
|
|
|