#region License
/**
* Ingenious MVC : An MVC framework for .NET 2.0
* Copyright (C) 2006, JDP Group
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Authors: - Kent Boogaart (kentcb@internode.on.net)
*/
#endregion
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using Ingenious.Mvc.Util;
namespace Ingenious.Mvc{
/// <include file='Id.doc.xml' path='/doc/member[@name="T:Id`1"]/*'/>
[Serializable]
public struct Id<T> : IEquatable<Id<T>>
{
private readonly string _id;
private static readonly Log _log = Log.CreateForType(typeof(Id<>));
/// <include file='Id.doc.xml' path='/doc/member[@name="F:Empty"]/*'/>
public static readonly Id<T> Empty;
/// <include file='Id.doc.xml' path='/doc/member[@name="P:IsEmpty"]/*'/>
[DebuggerHidden]
public bool IsEmpty
{
get
{
return (_id == null);
}
}
/// <include file='Id.doc.xml' path='/doc/member[@name="P:IdType"]/*'/>
[DebuggerHidden]
public string IdType
{
get
{
return typeof(T).FullName;
}
}
[DebuggerHidden]
private Id(string id)
{
_id = id;
}
/// <include file='Id.doc.xml' path='/doc/member[@name="M:ToString()"]/*'/>
[DebuggerHidden]
public override string ToString()
{
return _id;
}
/// <include file='Id.doc.xml' path='/doc/member[@name="M:Equals(Ingenious.Mvc.Id`1)"]/*'/>
[DebuggerHidden]
public bool Equals(Id<T> id)
{
bool equal = (string.CompareOrdinal(_id, id._id) == 0);
_log.Debug("Comparing ID '{0}' (of type '{1}') to ID '{2}' (of type '{3}'). Result = {4}", this, this.GetType().FullName, id, typeof(Id<T>).FullName, equal);
return equal;
}
/// <include file='Id.doc.xml' path='/doc/member[@name="M:Equals(System.Object)"]/*'/>
[DebuggerHidden]
public override bool Equals(object obj)
{
if (obj is Id<T>)
{
return Equals((Id<T>) obj);
}
return false;
}
/// <include file='Id.doc.xml' path='/doc/member[@name="M:GetHashCode()"]/*'/>
[DebuggerHidden]
public override int GetHashCode()
{
if (_id == null)
{
return 0;
}
else
{
return _id.GetHashCode();
}
}
/// <include file='Id.doc.xml' path='/doc/member[@name="M:op_Equality(Ingenious.Mvc.Id`1,Ingenious.Mvc.Id`1)"]/*'/>
[DebuggerHidden]
public static bool operator ==(Id<T> id1, Id<T> id2)
{
return id1.Equals(id2);
}
/// <include file='Id.doc.xml' path='/doc/member[@name="M:op_Inequality(Ingenious.Mvc.Id`1,Ingenious.Mvc.Id`1)"]/*'/>
[DebuggerHidden]
public static bool operator !=(Id<T> id1, Id<T> id2)
{
return !id1.Equals(id2);
}
/// <include file='Id.doc.xml' path='/doc/member[@name="M:op_Implicit(System.String)"]/*'/>
[DebuggerHidden]
public static implicit operator Id<T>(string stringId)
{
ArgumentHelper.AssertNotNull(stringId, "stringId");
ExceptionHelper.ThrowIf(stringId.Trim().Length == 0, "operator.emptyStringId", new object[] { "stringId" });
_log.Debug("Converting string '{0}' to type '{1}'.", stringId, typeof(Id<T>).FullName);
return new Id<T>(stringId);
}
/// <include file='Id.doc.xml' path='/doc/member[@name="M:op_Implicit(System.Enum)"]/*'/>
[DebuggerHidden]
public static implicit operator Id<T>(Enum enumId)
{
ArgumentHelper.AssertNotNull(enumId, "enumId");
_log.Debug("Converting enumeration member '{0}' to type '{1}'.", enumId, typeof(Id<T>).FullName);
return new Id<T>(enumId.ToString());
}
}
}
|