/// <summary> /// Validates the identifier (see <see cref="Id"/>) <see cref="Type"/>. /// </summary> /// <param name="idTypeCode">The expected <see cref="ReferenceDataIdTypeCode"/>.</param> /// <param name="id">The identifier to validate.</param> public static void ValidateId(ReferenceDataIdTypeCode idTypeCode, object id) { if (id == null) { throw new ArgumentNullException(nameof(id)); } ReferenceDataIdTypeCode typeCode = ReferenceDataIdTypeCode.Unknown; if (id is int) { typeCode = ReferenceDataIdTypeCode.Int32; } else if (id is Guid) { typeCode = ReferenceDataIdTypeCode.Guid; } else { throw new ArgumentException("Id can only be of Type Int32 or Guid.", nameof(id)); } if (typeCode != idTypeCode) { throw new ArgumentException($"Reference Data identifier value has an invalid TypeCode '{typeCode}'; expected TypeCode '{idTypeCode}'."); } }
/// <summary> /// Initializes a new instance of the <see cref="MultiSetCollReferenceDataSidArgs{TItem, TSid}"/> class. /// </summary> /// <param name="columnName">The column name for the reference data identifier.</param> /// <param name="result">The action that will be invoked with the result of the set.</param> /// <param name="minRows">The minimum number of rows allowed.</param> /// <param name="maxRows">The maximum number of rows allowed.</param> /// <param name="stopOnNull">Indicates whether to stop further query result set processing where the current set has resulted in a null (i.e. no records).</param> public MultiSetCollReferenceDataSidArgs(string columnName, Action <IEnumerable <TItem> > result, int minRows = 0, int?maxRows = null, bool stopOnNull = false) : base(minRows, maxRows, stopOnNull) { _columnName = Check.NotEmpty(columnName, nameof(columnName)); _result = Check.NotNull(result, nameof(result)); _idTypeCode = ReferenceDataBase.GetIdTypeCode(typeof(TItem)); }
/// <summary> /// Initializes a new instance of the <see cref="MultiSetCollReferenceDataSidArgs{TItem, TSid}"/> class. /// </summary> /// <param name="columnName">The column name for the reference data identifier.</param> /// <param name="result">The action that will be invoked with the result of the set.</param> /// <param name="minRows">The minimum number of rows allowed.</param> /// <param name="maxRows">The maximum number of rows allowed.</param> /// <param name="stopOnNull">Indicates whether to stop further query result set processing where the current set has resulted in a null (i.e. no records).</param> public MultiSetCollReferenceDataSidArgs(string columnName, Action <IEnumerable <TItem> > result, int minRows = 0, int?maxRows = null, bool stopOnNull = false) { _columnName = Check.NotEmpty(columnName, nameof(columnName)); _result = Check.NotNull(result, nameof(result)); Check.IsTrue(!maxRows.HasValue || minRows <= maxRows.Value, nameof(maxRows), "Max Rows is less than Min Rows."); MinRows = minRows; MaxRows = maxRows; StopOnNull = stopOnNull; _idTypeCode = ReferenceDataBase.GetIdTypeCode(typeof(TItem)); }
/// <summary> /// Initializes a new instance of the <see cref="ReferenceDataBase"/> class. /// </summary> /// <param name="idTypeCode">The <see cref="ReferenceDataIdTypeCode"/>.</param> /// <param name="defaultId">The default identifier.</param> protected ReferenceDataBase(ReferenceDataIdTypeCode idTypeCode, object defaultId) { IdTypeCode = idTypeCode; ValidateId(IdTypeCode, defaultId); _key.Id = defaultId; }