System.Windows.Forms.SecurityUtils.SecureCreateInstance C# (CSharp) Méthode

SecureCreateInstance() static private méthode

static private SecureCreateInstance ( Type type ) : object
type System.Type
Résultat object
        internal static object SecureCreateInstance(Type type) {
            return SecureCreateInstance(type, null);
        }

Same methods

SecurityUtils::SecureCreateInstance ( Type type, object args ) : object
SecurityUtils::SecureCreateInstance ( Type type, object args, bool allowNonPublic ) : object

Usage Example

        // Create an object of the given type. Throw an exception if this fails.
        private static object CreateInstanceOfType(Type type)
        {
            object    instancedObject   = null;
            Exception instanceException = null;

            try {
                instancedObject = SecurityUtils.SecureCreateInstance(type);
            }
            catch (TargetInvocationException ex) {
                instanceException = ex; // Default ctor threw an exception
            }
            catch (MethodAccessException ex) {
                instanceException = ex; // Default ctor was not public
            }
            catch (MissingMethodException ex) {
                instanceException = ex; // No default ctor defined
            }

            if (instanceException != null)
            {
                throw new NotSupportedException(SR.GetString(SR.BindingSourceInstanceError), instanceException);
            }

            return(instancedObject);
        }
All Usage Examples Of System.Windows.Forms.SecurityUtils::SecureCreateInstance