Skip to content

Commit

Permalink
Added two more ToString methods, reformatted
Browse files Browse the repository at this point in the history
SVN: trunk@1637
  • Loading branch information
Sergey Koshcheyev committed Aug 22, 2005
1 parent de91085 commit 55ee676
Showing 1 changed file with 52 additions and 13 deletions.
65 changes: 52 additions & 13 deletions src/NHibernate/Impl/Printer.cs
Expand Up @@ -2,6 +2,7 @@
using System.Collections;

using log4net;

using NHibernate.Engine;
using NHibernate.Metadata;
using NHibernate.Type;
Expand All @@ -22,44 +23,82 @@ public sealed class Printer
public string ToString( object entity )
{
IClassMetadata cm = _factory.GetClassMetadata( entity.GetType() );
if( cm == null ) return entity.GetType().FullName;
if( cm == null )
{
return entity.GetType().FullName;
}

IDictionary result = new Hashtable();
if ( cm.HasIdentifierProperty )

if( cm.HasIdentifierProperty )
{
result[ cm.IdentifierPropertyName ] =
cm.IdentifierType.ToString( cm.GetIdentifier( entity ), _factory );
}
IType[] types = cm.PropertyTypes;
string[] names = cm.PropertyNames;
object[] values = cm.GetPropertyValues( entity );

IType[ ] types = cm.PropertyTypes;
string[ ] names = cm.PropertyNames;
object[ ] values = cm.GetPropertyValues( entity );

for( int i = 0; i < types.Length; i++ )
{
result[ names[i] ] = types[i].ToString( values[i], _factory );
result[ names[ i ] ] = types[ i ].ToString( values[ i ], _factory );
}

return cm.MappedClass.FullName + CollectionPrinter.ToString( result );
}

public string ToString( IType[ ] types, object[ ] values )
{
IList list = new ArrayList( types.Length );
for ( int i = 0; i < types.Length; i++ )
for( int i = 0; i < types.Length; i++ )
{
if( types[i] != null )
if( types[ i ] != null )
{
list.Add( types[ i ].ToString( values[ i ], _factory ) );
}
}
return CollectionPrinter.ToString( list );
}

public string ToString( IDictionary namedTypedValues )
{
IDictionary result = new Hashtable( namedTypedValues.Count );

foreach( DictionaryEntry me in namedTypedValues )
{
TypedValue tv = ( TypedValue ) me.Value;
result[ me.Key ] = tv.Type.ToString( tv.Value, _factory );
}

return CollectionPrinter.ToString( result );
}

public void ToString( IEnumerator enumerator )
{
if( !log.IsDebugEnabled || !enumerator.MoveNext() )
{
return;
}

log.Debug( "listing entities:" );
int i = 0;

do
{
if( i++ > 20 )
{
log.Debug( "more......" );
break;
}
log.Debug( ToString( enumerator.Current ) );
}
while( enumerator.MoveNext() );
}

public Printer( ISessionFactoryImplementor factory )
{
_factory = factory;
}
}
}
}

0 comments on commit 55ee676

Please sign in to comment.