SqlScripter.Core/src/Smo/SmoUtils.cs
/// <summary>
/// Chcecks if an obejct is a system object.
/// </summary>
/// <param name="o"></param>
/// <param name="ignoreNoIsSystemObjectProperty">If an a given object will not have a property "IsSystemObject" 
/// then an exception will be thrown if this is false. If property is missing and this is true, an abject will be assumed 
/// as not a system object.</param>
/// <returns></returns>
Chcecks if an obejct is a system object.
Chcecks if an obejct is a system object .
public static bool IsSystemObject(Object o, bool ignoreNoIsSystemObjectProperty) {
            Guard.NotNull(o, "o");
            Type type = o.GetType();
            PropertyInfo isSystemObjectProperty = type.GetProperty("IsSystemObject");
            PropertyInfo schemaProperty = type.GetProperty("Schema");
            if (schemaProperty != null) {
                object schema = schemaProperty.GetValue(o, null);
                if ("sys".Equals(schema)) {
                    return true;
                }
            }
            if (isSystemObjectProperty != null) {
                if ((bool)isSystemObjectProperty.GetValue(o, null)) {
                    return true;
                }
            } else {
                if (!ignoreNoIsSystemObjectProperty) {
                    string s = string.Format("Cannot check if \"{0}\" is system object, there is no IsSystemObject property on type.", o);
                    throw new InvalidOperationException(s);
                }
            }
            if (o is NamedSmoObject && "sysdiagrams".Equals(((NamedSmoObject)o).Name)) {
                return true;
            }
            if (o is Index && "sysdiagrams".Equals(((NamedSmoObject)((Index)o).Parent).Name)) {
                return true;
            }
            if (o is Schema) {
                string schemaName = ((Schema) o).Name;
                switch(schemaName) {
                    case "sys":
                    case "INFORMATION_SCHEMA":
                    case "guest":
                    case "dbo":
                    case "db_securityadmin":
                    case "db_owner":
                    case "db_denydatawriter":
                    case "db_denydatareader":
                    case "db_ddladmin":
                    case "db_datawriter":
                    case "db_datareader":
                    case "db_backupoperator":
                    case "db_accessadmin":
                        return true;
                }
            }
            return false;
        }
public static bool IsSystemObject ( Object o , bool ignoreNoIsSystemObjectProperty ) { Guard . NotNull ( o , " " ) ; Type type = o . GetType ( ) ; PropertyInfo isSystemObjectProperty = type . GetProperty ( " " ) ; PropertyInfo schemaProperty = type . GetProperty ( " " ) ; if ( schemaProperty != null ) { object schema = schemaProperty . GetValue ( o , null ) ; if ( " " . Equals ( schema ) ) { return true ; } } if ( isSystemObjectProperty != null ) { if ( ( bool ) isSystemObjectProperty . GetValue ( o , null ) ) { return true ; } } else { if ( ! ignoreNoIsSystemObjectProperty ) { string s = string . Format ( " \" \" " , o ) ; throw new InvalidOperationException ( s ) ; } } if ( o is NamedSmoObject && " " . Equals ( ( ( NamedSmoObject ) o ) . Name ) ) { return true ; } if ( o is Index && " " . Equals ( ( ( NamedSmoObject ) ( ( Index ) o ) . Parent ) . Name ) ) { return true ; } if ( o is Schema ) { string schemaName = ( ( Schema ) o ) . Name ; switch ( schemaName ) { case " " : case " " : case " " : case " " : case " " : case " " : case " " : case " " : case " " : case " " : case " " : case " " : case " " : return true ; } } return false ; }
Chcecks if an obejct is a system object.
Chcecks if an obejct is a system object .
None
o
Object
None
ignoreNoIsSystemObjectProperty
bool
If an a given object will not have a property "IsSystemObject"
then an exception will be thrown if this is false. If property is missing and this is true, an abject will be assumed
as not a system object.
If an a given object will not have a property " IsSystemObject " then an exception will be thrown if this is false . If property is missing and this is true an abject will be assumed as not a system object .