System.ComponentModel.TypeDescriptionProvider.CreateInstance C# (CSharp) Method

CreateInstance() public method

public CreateInstance ( IServiceProvider provider, Type objectType, Type argTypes, object args ) : object
provider IServiceProvider
objectType System.Type
argTypes System.Type
args object
return object
        public virtual object CreateInstance(IServiceProvider provider, Type objectType, Type[] argTypes, object[] args)
        {
            if (_parent != null)
            {
                return _parent.CreateInstance(provider, objectType, argTypes, args);
            }

            if (objectType == null) {
                throw new ArgumentNullException("objectType");
            }

            return SecurityUtils.SecureCreateInstance(objectType, args);
        }

Usage Example

Example #1
0
        public static object CreateInstance(IServiceProvider provider, Type objectType, Type [] argTypes, object [] args)
        {
            if (objectType == null)
            {
                throw new ArgumentNullException("objectType");
            }

            object instance = null;

            if (provider != null)
            {
                TypeDescriptionProvider typeDescrProvider = provider.GetService(typeof(TypeDescriptionProvider)) as TypeDescriptionProvider;
                if (typeDescrProvider != null)
                {
                    instance = typeDescrProvider.CreateInstance(provider, objectType, argTypes, args);
                }
            }

            // TODO: also search and use the internal providers table once Add/RemoveProvider have been implemented

            if (instance == null)
            {
                instance = Activator.CreateInstance(objectType, args);
            }

            return(instance);
        }
All Usage Examples Of System.ComponentModel.TypeDescriptionProvider::CreateInstance