// Copyright (c) 2007 Omer Rauchwerger (a.k.a rauchy) (omer@rauchy.net)
// All rights reserved.
//
// This file is part of Regionerate.
//
// This program is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 3 of the License,
// or (at your option) any later version.
//
// This program 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 General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see .
using System;
using System.Collections.Generic;
using System.Text;
namespace Rauchy.Regionerate.Domain.Entities
{
public abstract class ContainerTypeCode : TypeCode, ICloneable
{
#region Data Members (5)
// Fields (2)
private string _header;
private IList _members;
// Properties (3)
public string Footer
{
get;
set;
}
public string Header
{
get
{
return _header;
}
set
{
_header = value;
}
}
public IList Members
{
get
{
return _members;
}
set
{
_members = value;
}
}
#endregion Data Members
#region Plumbing Code (5)
///
///Creates a new object that is a copy of the current instance.
///
///
///
///A new object that is a copy of this instance.
///
///2
public object Clone()
{
return MemberwiseClone();
}
protected ContainerTypeCode()
{
_members = new List();
}
public override bool Equals( object obj )
{
if ( obj == null ||
!( obj is ContainerTypeCode ) )
{
return false;
}
ContainerTypeCode comparedCode = ( ContainerTypeCode )obj;
bool sameHeader = SafeCompare( Header, comparedCode.Header );
bool sameAttributes = SafeCompare( Attributes, comparedCode.Attributes );
bool sameMembers = SafeCompare( Members, comparedCode.Members );
bool sameLength = SafeCompare( Length, comparedCode.Length );
bool sameName = SafeCompare( Name, comparedCode.Name );
bool sameTypeVisibility = SafeCompare( TypeVisibility, comparedCode.TypeVisibility );
return sameHeader && sameAttributes && sameMembers && sameLength && sameName && sameTypeVisibility;
}
///
/// Compares two objects even in case they are null.
///
/// True if objects are equal or both null; False otherwise.
private static bool SafeCompare( object objA, object objB )
{
if ( objA != null &&
objB != null )
{
return objA.Equals( objB );
}
else if ( objA == null &&
objB == null )
{
return true;
}
else
{
return false;
}
}
[ Obsolete ]
public override string ToString()
{
StringBuilder builder = new StringBuilder();
builder.Append( _header );
for ( int i = 0; i < _members.Count; i++ )
{
Code member = _members[ i ];
builder.Append( member );
}
builder.Append( "}" );
return builder.ToString();
}
#endregion Plumbing Code
}
}