Implemented StringUtil.fieldsToString() using flash's introspection.
Use it in SimpleStreamableObject's toString(), with some new formatting. Unfortunately, the order of public variables seems random. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@4746 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -23,6 +23,8 @@ package com.threerings.util {
|
||||
|
||||
import flash.utils.ByteArray;
|
||||
|
||||
import flash.utils.describeType; // function import
|
||||
|
||||
import mx.utils.*;
|
||||
|
||||
public class StringUtil
|
||||
@@ -202,6 +204,34 @@ public class StringUtil
|
||||
return String(obj);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a string containing all the public fields of the object
|
||||
*/
|
||||
public static function fieldsToString (buf :StringBuilder, obj :Object) :void
|
||||
{
|
||||
var desc :XML = describeType(obj);
|
||||
var appended :Boolean = false;
|
||||
for each (var varName :String in desc..variable.@name) {
|
||||
if (appended) {
|
||||
buf.append(", ");
|
||||
}
|
||||
buf.append(varName, "=", obj[varName]);
|
||||
appended = true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a pretty basic toString of the supplied Object.
|
||||
*/
|
||||
public static function simpleToString (obj :Object) :String
|
||||
{
|
||||
var buf :StringBuilder = new StringBuilder("[");
|
||||
buf.append(ClassUtil.tinyClassName(obj));
|
||||
buf.append("(");
|
||||
fieldsToString(buf, obj);
|
||||
return buf.append(")]").toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Truncate the specified String if it is longer than maxLength.
|
||||
* The string will be truncated at a position such that it is
|
||||
|
||||
Reference in New Issue
Block a user