System.Linq.Expressions.Error.TypeMissingDefaultConstructor C# (CSharp) Méthode

TypeMissingDefaultConstructor() static private méthode

ArgumentException with message like "Type '{0}' does not have a default constructor"
static private TypeMissingDefaultConstructor ( object p0, string paramName ) : Exception
p0 object
paramName string
Résultat Exception
        internal static Exception TypeMissingDefaultConstructor(object p0, string paramName)
        {
            return new ArgumentException(Strings.TypeMissingDefaultConstructor(p0), paramName);
        }

Usage Example

 /// <summary>
 /// Creates a <see cref="NewExpression"/> that represents calling the parameterless constructor of the specified type.
 /// </summary>
 /// <param name="type">A <see cref="Type"/> that has a constructor that takes no arguments. </param>
 /// <returns>A <see cref="NewExpression"/> that has the <see cref="NodeType"/> property equal to New and the Constructor property set to the ConstructorInfo that represents the parameterless constructor of the specified type.</returns>
 public static NewExpression New(Type type)
 {
     ContractUtils.RequiresNotNull(type, "type");
     if (type == typeof(void))
     {
         throw Error.ArgumentCannotBeOfTypeVoid();
     }
     if (!type.IsValueType)
     {
         var constructorInfo = type.GetConstructors(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic).SingleOrDefault(c => c.GetParameters().Length == 0);
         if (constructorInfo == null)
         {
             throw Error.TypeMissingDefaultConstructor(type);
         }
         return(New(constructorInfo));
     }
     return(new NewValueTypeExpression(type, EmptyCollection <Expression> .Instance, null));
 }
All Usage Examples Of System.Linq.Expressions.Error::TypeMissingDefaultConstructor
Error