/// <summary> /// Covert PrimitiveType to valid c# code /// </summary> /// <param name="pt">PrimitiveType to conver</param> /// <returns>PrimitiveType in c# code</returns> private string ConvertToString(PrimitiveDataType pt, bool safe) { switch (pt) { case PrimitiveDataType.Integer: return(safe ? "Skill.Framework.SafeInt" : "int"); case PrimitiveDataType.Boolean: return(safe ? "Skill.Framework.SafeBool" : "bool"); case PrimitiveDataType.Float: return(safe ? "Skill.Framework.SafeFloat" : "float"); case PrimitiveDataType.String: return(pt.ToString().ToLower()); default: return(pt.ToString()); } }
/// <summary> /// Creates a data generator for the given data type from the repository. /// </summary> /// <param name="dataType">The data type from the repository to get data generator for.</param> /// <param name="random">The random number generator.</param> /// <param name="isUnique">The value indicating whether the generator should produce unique data.</param> /// <returns>The data generator for the given data type.</returns> public virtual IDataGenerator CreateDataGenerator(PrimitiveDataType dataType, IRandomNumberGenerator random, bool isUnique) { ExceptionUtilities.CheckArgumentNotNull(dataType, "dataType"); ExceptionUtilities.CheckArgumentNotNull(random, "random"); if (this.primitiveDataTypes == null) { this.primitiveDataTypes = new List<PrimitiveDataType>(); this.primitiveDataTypes.AddRange(this.GetPrimitiveDataTypesOverride()); } if (!this.primitiveDataTypes.Contains(dataType)) { throw new TaupoInvalidOperationException( string.Format(CultureInfo.InvariantCulture, "Given type does not belong to this repository. Type: '{0}'.", dataType.ToString())); } var enumDataType = dataType as EnumDataType; var clrType = enumDataType != null ? enumDataType.Definition.UnderlyingType : dataType.GetFacetValue<PrimitiveClrTypeFacet, Type>(null); ExceptionUtilities.CheckObjectNotNull(clrType, "{0} has to be defined on the type: '{1}'.", enumDataType != null ? "UnderlyingType" : "PrimitiveClrTypeFacet", dataType); if (dataType.IsNullable && clrType.IsValueType() && !(clrType.IsGenericType() && clrType.GetGenericTypeDefinition() == typeof(Nullable<>))) { clrType = typeof(Nullable<>).MakeGenericType(clrType); } var hints = this.DataGenerationHintsResolver.ResolveDataGenerationHints(dataType); return this.ResolveDataGenerator(clrType, random, isUnique, hints.ToArray()); }
/// <summary> /// Creates a data generator for the given data type from the repository. /// </summary> /// <param name="dataType">The data type from the repository to get data generator for.</param> /// <param name="random">The random number generator.</param> /// <param name="isUnique">The value indicating whether the generator should produce unique data.</param> /// <returns>The data generator for the given data type.</returns> public virtual IDataGenerator CreateDataGenerator(PrimitiveDataType dataType, IRandomNumberGenerator random, bool isUnique) { ExceptionUtilities.CheckArgumentNotNull(dataType, "dataType"); ExceptionUtilities.CheckArgumentNotNull(random, "random"); if (this.primitiveDataTypes == null) { this.primitiveDataTypes = new List <PrimitiveDataType>(); this.primitiveDataTypes.AddRange(this.GetPrimitiveDataTypesOverride()); } if (!this.primitiveDataTypes.Contains(dataType)) { throw new TaupoInvalidOperationException( string.Format(CultureInfo.InvariantCulture, "Given type does not belong to this repository. Type: '{0}'.", dataType.ToString())); } var enumDataType = dataType as EnumDataType; var clrType = enumDataType != null ? enumDataType.Definition.UnderlyingType : dataType.GetFacetValue <PrimitiveClrTypeFacet, Type>(null); ExceptionUtilities.CheckObjectNotNull(clrType, "{0} has to be defined on the type: '{1}'.", enumDataType != null ? "UnderlyingType" : "PrimitiveClrTypeFacet", dataType); if (dataType.IsNullable && clrType.IsValueType() && !(clrType.IsGenericType() && clrType.GetGenericTypeDefinition() == typeof(Nullable <>))) { clrType = typeof(Nullable <>).MakeGenericType(clrType); } var hints = this.DataGenerationHintsResolver.ResolveDataGenerationHints(dataType); return(this.ResolveDataGenerator(clrType, random, isUnique, hints.ToArray())); }
private static PrimitiveDataType ResolveCommonPrecisionAndScale(PrimitiveDataType leftType, PrimitiveDataType rightType, PrimitiveDataType commonType) { if (commonType.HasFacet<NumericPrecisionFacet>()) { ExceptionUtilities.Assert(commonType is FixedPointDataType, "Precision and scale facets are not expected on type {}.", commonType.ToString()); var commonPrecision = GetCommonPrecision(leftType, rightType); var commonScale = GetCommonScale(leftType, rightType); commonType = EdmDataTypes.Decimal(commonPrecision, commonScale); } return commonType; }
private static PrimitiveDataType ResolveCommonPrecisionAndScale(PrimitiveDataType leftType, PrimitiveDataType rightType, PrimitiveDataType commonType) { if (commonType.HasFacet <NumericPrecisionFacet>()) { ExceptionUtilities.Assert(commonType is FixedPointDataType, "Precision and scale facets are not expected on type {}.", commonType.ToString()); var commonPrecision = GetCommonPrecision(leftType, rightType); var commonScale = GetCommonScale(leftType, rightType); commonType = EdmDataTypes.Decimal(commonPrecision, commonScale); } return(commonType); }