Archive for August 2011
Get object types in C#/Tridion 2009
In C#, the general usage to identify the object type is using “is” keyword. This is okay to some extent but you have to write “switch” of “if”, for multiple types. If there are more object types, code will be lengthy. Recently I came across a easy way of checking the object’s type. This is helpful when the object is of COM type.
Just add the below reference in your project and call its TypeName method.
using Microsoft.VisualBasic;
.
.
.
.
.
public string GetTypeOf(object obj)
{
return Microsoft.VisualBasic.Information.TypeName(obj);
}
Output:
This was very handy for me in my migration project where I needed to write all the object details in log file.
