public static IReadOnlyList <T> NotEmpty <T>(IReadOnlyList <T> value, [InvokerParameterName][JetBrains.Annotations.NotNull] string parameterName) { NotNull(value, parameterName); if (value.Count == 0) { NotEmpty(parameterName, nameof(parameterName)); throw new ArgumentException(AbstractionsStrings.CollectionArgumentIsEmpty(parameterName)); } return(value); }
public static IReadOnlyCollection <T>?NullButNotEmpty <T>( IReadOnlyCollection <T>?value, [InvokerParameterName] string parameterName) { if (!ReferenceEquals(value, null) && (value.Count == 0)) { NotEmpty(parameterName, nameof(parameterName)); throw new ArgumentException(AbstractionsStrings.ArgumentIsEmpty(parameterName)); } return(value); }
public static IReadOnlyList <string> HasNoEmptyElements( [NotNull] IReadOnlyList <string>?value, [InvokerParameterName] string parameterName) { NotNull(value, parameterName); if (value.Any(s => string.IsNullOrWhiteSpace(s))) { NotEmpty(parameterName, nameof(parameterName)); throw new ArgumentException(AbstractionsStrings.CollectionArgumentHasEmptyElements(parameterName)); } return(value); }
/// <summary> /// Initializes a new instance of the <see cref="PrecisionAttribute" /> class. /// </summary> /// <param name="precision">The precision of the property.</param> /// <param name="scale">The scale of the property.</param> public PrecisionAttribute(int precision, int scale) { if (precision < 0) { throw new ArgumentException(AbstractionsStrings.ArgumentIsNegativeNumber(nameof(precision))); } if (scale < 0) { throw new ArgumentException(AbstractionsStrings.ArgumentIsNegativeNumber(nameof(scale))); } Precision = precision; Scale = scale; }
public static string NotEmpty([NotNull] string?value, [InvokerParameterName] string parameterName) { if (value is null) { NotEmpty(parameterName, nameof(parameterName)); throw new ArgumentNullException(parameterName); } if (value.Trim().Length == 0) { NotEmpty(parameterName, nameof(parameterName)); throw new ArgumentException(AbstractionsStrings.ArgumentIsEmpty(parameterName)); } return(value); }
public async Task InsertOneAsync(T document) { if (document is IDocument <Guid> ) { ((IDocument <Guid>)document).Id = ((IDocument <Guid>)document).Id.GetIfIsNullOrEmpty(() => Guid.NewGuid()); } if (document is IDocument <ObjectId> ) { ((IDocument <ObjectId>)document).Id = ((IDocument <ObjectId>)document).Id.GetIfIsNullOrEmpty(() => ObjectId.GenerateNewId()); } var response = await _client.IndexDocumentAsync(document); if (!response?.IsValid ?? true) { throw new ConnectorException(AbstractionsStrings.DbError(nameof(InsertOne)), response?.OriginalException); } }
public static string NotEmpty(string value, [InvokerParameterName][NotNull] string parameterName) { Exception ex = null; if (value == null) { ex = new ArgumentNullException(parameterName); } else if (value.Trim().Length == 0) { ex = new ArgumentException(AbstractionsStrings.ArgumentIsEmpty(parameterName)); } if (ex != null) { NotEmpty(parameterName, nameof(parameterName)); throw ex; } return(value); }
/// <summary> /// Constructor for the Handlebars DbContext generator. /// </summary> /// <param name="legacyProviderCodeGenerators">Legacy provider code generators</param> /// <param name="providerCodeGenerators">Generator for scaffolding provider.</param> /// <param name="annotationCodeGenerator">Annotation code generator.</param> /// <param name="dbContextTemplateService">Template service for DbContext generator.</param> /// <param name="cSharpHelper">CSharp helper.</param> public HbsCSharpDbContextGenerator( #pragma warning disable CS0618 // Type or member is obsolete IEnumerable <IScaffoldingProviderCodeGenerator> legacyProviderCodeGenerators, #pragma warning restore CS0618 // Type or member is obsolete IEnumerable <IProviderConfigurationCodeGenerator> providerCodeGenerators, IAnnotationCodeGenerator annotationCodeGenerator, IDbContextTemplateService dbContextTemplateService, ICSharpHelper cSharpHelper) { if (!legacyProviderCodeGenerators.Any() && !providerCodeGenerators.Any()) { throw new ArgumentException(AbstractionsStrings.CollectionArgumentIsEmpty(nameof(providerCodeGenerators))); } _legacyProviderCodeGenerator = legacyProviderCodeGenerators.LastOrDefault(); _providerConfigurationCodeGenerator = providerCodeGenerators.LastOrDefault(); _annotationCodeGenerator = annotationCodeGenerator ?? throw new ArgumentNullException(nameof(annotationCodeGenerator)); DbContextTemplateService = dbContextTemplateService ?? throw new ArgumentNullException(nameof(dbContextTemplateService)); _code = cSharpHelper ?? throw new ArgumentNullException(nameof(cSharpHelper)); }
public CSharpDbContextGeneratorBase( [NotNull] IEnumerable <IScaffoldingProviderCodeGenerator> legacyProviderCodeGenerators, [NotNull] IEnumerable <IProviderConfigurationCodeGenerator> providerCodeGenerators, [NotNull] IAnnotationCodeGenerator annotationCodeGenerator, [NotNull] ICSharpHelper cSharpHelper) { Check.NotNull(legacyProviderCodeGenerators, nameof(legacyProviderCodeGenerators)); Check.NotNull(providerCodeGenerators, nameof(providerCodeGenerators)); Check.NotNull(annotationCodeGenerator, nameof(annotationCodeGenerator)); Check.NotNull(cSharpHelper, nameof(cSharpHelper)); if (!legacyProviderCodeGenerators.Any() && !providerCodeGenerators.Any()) { throw new ArgumentException(AbstractionsStrings.CollectionArgumentIsEmpty(nameof(providerCodeGenerators))); } this._legacyProviderCodeGenerator = legacyProviderCodeGenerators.LastOrDefault(); this._providerConfigurationCodeGenerator = providerCodeGenerators.LastOrDefault(); this._annotationCodeGenerator = annotationCodeGenerator; this._code = cSharpHelper; }
public static string?NotNullOrEmpty(string?value, [InvokerParameterName][NotNull] string parameterName) { Exception?e = null; if (ReferenceEquals(value, null)) { e = new ArgumentNullException(parameterName); } else if (value.Trim().Length == 0) { e = new ArgumentException(AbstractionsStrings.ArgumentIsEmpty(parameterName)); } if (e != null) { NotNullOrEmpty(parameterName, nameof(parameterName)); throw e; } return(value); }
/// <summary> /// Throw an exception if value is null or empty. /// </summary> /// <param name="value">Value to check.</param> /// <param name="parameterName">Method parameter name.</param> /// <returns></returns> public static string NotEmpty(string value, string parameterName) { Exception e = null; if (value is null) { e = new ArgumentNullException(parameterName); } else if (value.Trim().Length == 0) { e = new ArgumentException(AbstractionsStrings.ArgumentIsEmpty(parameterName)); } if (e != null) { NotEmpty(parameterName, nameof(parameterName)); throw e; } return(value); }
/// <summary> /// This API supports the Entity Framework Core infrastructure and is not intended to be used /// directly from your code. This API may change or be removed in future releases. /// </summary> public CSharpDbContextGenerator( #pragma warning disable CS0618 // Type or member is obsolete [NotNull] IEnumerable <IScaffoldingProviderCodeGenerator> legacyProviderCodeGenerators, #pragma warning restore CS0618 // Type or member is obsolete [NotNull] IEnumerable <IProviderCodeGenerator> providerCodeGenerators, [NotNull] IAnnotationCodeGenerator annotationCodeGenerator, [NotNull] ICSharpUtilities cSharpUtilities) { Check.NotNull(legacyProviderCodeGenerators, nameof(legacyProviderCodeGenerators)); Check.NotNull(providerCodeGenerators, nameof(providerCodeGenerators)); Check.NotNull(annotationCodeGenerator, nameof(annotationCodeGenerator)); Check.NotNull(cSharpUtilities, nameof(cSharpUtilities)); if (!legacyProviderCodeGenerators.Any() && !providerCodeGenerators.Any()) { throw new ArgumentException(AbstractionsStrings.CollectionArgumentIsEmpty(nameof(providerCodeGenerators))); } _legacyProviderCodeGenerator = legacyProviderCodeGenerators.LastOrDefault(); _providerCodeGenerator = providerCodeGenerators.LastOrDefault(); _annotationCodeGenerator = annotationCodeGenerator; _cSharpUtilities = cSharpUtilities; }
/// <summary> /// Constructor for the Handlebars DbContext generator. /// </summary> /// <param name="handlebarsScaffoldingOptions">Handlebars Scaffolding Options.</param> /// <param name="legacyProviderCodeGenerators">Legacy provider code generators.</param> /// <param name="providerCodeGenerators">Generator for scaffolding provider.</param> /// <param name="annotationCodeGenerator">Annotation code generator.</param> /// <param name="dbContextTemplateService">Template service for DbContext generator.</param> /// <param name="entityTypeTransformationService">Service for transforming entity definitions.</param> /// <param name="cSharpHelper">CSharp helper.</param> public HbsCSharpDbContextGeneratorEnhance( #pragma warning disable CS0618 // Type or member is obsolete IEnumerable <IScaffoldingProviderCodeGenerator> legacyProviderCodeGenerators, #pragma warning restore CS0618 // Type or member is obsolete IEnumerable <IProviderConfigurationCodeGenerator> providerCodeGenerators, IAnnotationCodeGenerator annotationCodeGenerator, IDbContextTemplateService dbContextTemplateService, IEntityTypeTransformationService entityTypeTransformationService, ICSharpHelper cSharpHelper, HandlebarsScaffoldingOptions handlebarsScaffoldingOptions) { if (!legacyProviderCodeGenerators.Any() && !providerCodeGenerators.Any()) { throw new ArgumentException(AbstractionsStrings.CollectionArgumentIsEmpty(nameof(providerCodeGenerators))); } HandlebarsScaffoldingOptions = handlebarsScaffoldingOptions ?? HandlebarsScaffoldingOptions.Default; LegacyProviderCodeGenerator = legacyProviderCodeGenerators.LastOrDefault(); ProviderConfigurationCodeGenerator = providerCodeGenerators.LastOrDefault(); CodeGenerator = annotationCodeGenerator ?? throw new ArgumentNullException(nameof(annotationCodeGenerator)); DbContextTemplateService = dbContextTemplateService ?? throw new ArgumentNullException(nameof(dbContextTemplateService)); EntityTypeTransformationService = entityTypeTransformationService ?? throw new ArgumentNullException(nameof(entityTypeTransformationService)); CSharpHelper = cSharpHelper ?? throw new ArgumentNullException(nameof(cSharpHelper)); }
public void Members_check_arguments() { Assert.Equal( AbstractionsStrings.ArgumentIsEmpty("name"), Assert.Throws <ArgumentException>(() => new Annotation("", "Kake")).Message); }
public static double NotNegative([CA.NotNull] double value, [InvokerParameterName][NotNull] string parameterName) => value < 0 || string.IsNullOrEmpty(NotEmpty(parameterName, nameof(parameterName))) ? throw new ArgumentException(AbstractionsStrings.ArgumentIsEmpty(parameterName)):value;