NServiceBus.Guard.TypeHasDefaultConstructor C# (CSharp) Method

TypeHasDefaultConstructor() public static method

public static TypeHasDefaultConstructor ( Type type, [ argumentName ) : void
type System.Type
argumentName [
return void
        public static void TypeHasDefaultConstructor(Type type, [InvokerParameterName] string argumentName)
        {
            if (type.GetConstructors(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)
                .All(ctor => ctor.GetParameters().Length != 0))
            {
                var error = $"Type '{type.FullName}' must have a default constructor.";
                throw new ArgumentException(error, argumentName);
            }
        }

Usage Example

Example #1
0
        /// <summary>
        /// Defines a custom builder to use.
        /// </summary>
        /// <param name="definitionType">The type of the <see cref="ContainerDefinition" />.</param>
        public void UseContainer(Type definitionType)
        {
            Guard.AgainstNull(nameof(definitionType), definitionType);
            Guard.TypeHasDefaultConstructor(definitionType, nameof(definitionType));

            Settings.Get <HostingComponent.Settings>().CustomObjectBuilder = definitionType.Construct <ContainerDefinition>().CreateContainer(Settings);
        }
All Usage Examples Of NServiceBus.Guard::TypeHasDefaultConstructor