Use of reflection not (always) needed

Jul 4, 2008 at 9:15 PM

Hi,

I have been using your fantastic tool.

Currently I'm looking at how to speed it up a bit. So I dug into the code and ran a profiler over it (the standard VS 2005 performance session stuff). And apart from the scripting, which does take all the time, I did notice the use of reflection.
So, for example:

object[] invokeMemberArgs = { scriptingOptions }; objectStatements = sqlSmoObject.GetType().InvokeMember(     "Script"
    
BindingFlags.Public | BindingFlags.Instance | BindingFlags.InvokeMethod, 
    null
    sqlSmoObject,
    invokeMemberArgs) 
    
as StringCollection;

Can be rewritten to use the Interface IScriptable:

if (sqlSmoObject is IScriptable)
{
    objectStatements = (sqlSmoObject
as IScriptable).Script(scriptingOptions);
}

Same thing for calling ExtendedProperties:

if (sqlSmoObject is IExtendedProperties)
{
   
ExtendedPropertyCollection epc = (sqlSmoObject as IExtendedProperties).ExtendedProperties;
}
//ExtendedPropertyCollection epc =
// (ExtendedPropertyCollection)
// sqlSmoObject.GetType().InvokeMember("ExtendedProperties",
// BindingFlags.Public | BindingFlags.Instance | // BindingFlags.GetProperty, null, sqlSmoObject, null);
if (epc.Contains("microsoft_database_tools_support")) return true;

Only the 'IsSystemObject' is not supported by an Interface, so that one needs to stay.