Page 1 of 1

Entity Name and .ToString()

Posted: Fri Jul 01, 2011 12:30 pm
by -=Magic=-
I think that it will be usefull if we may assign a Name to an entity, and overriding the default .ToString method so that the Name sill be returned.
In this way, build a log file to debug the physic should me more easy.

I've added to the EntityBase class this code:

Code: Select all

        public string Name { get; set; }

        public override string ToString()
        {
            if (String.IsNullOrEmpty(Name))
                return base.ToString();
            return Name;
        }

Re: Entity Name and .ToString()

Posted: Fri Jul 01, 2011 4:17 pm
by Norbo
I would recommend using the Tag property for this purpose; it was designed to hold arbitrary user data.

I will modify the ToString method to return the Tag's ToString as well if it is not null.

Re: Entity Name and .ToString()

Posted: Fri Jul 01, 2011 9:43 pm
by -=Magic=-
but the Tag could be used to store other kind of infos... the Name is just for "debug" purposes. if I need to use Tag for this, and I need to use the Tag for other purposes.. then I have to complicate the whole thing, passing an object array as Tag.. so you choice still useless, beacuse ToString will return object array.

Re: Entity Name and .ToString()

Posted: Fri Jul 01, 2011 9:48 pm
by Norbo
I try to avoid 'extra' features in the API since things can get cluttered. The Tag is capable of serving the same purpose as the Name, and Name can't do much else besides act like a crippled Tag.

If the Tag needs to contain a Name as well as other gameplay data, the recommended approach is to make a class which contains all the user data and stick that object into the Tag. An array can work too, but it's usually less direct.