Пример #1
0
 public override int GetHashCode()
 {
     unchecked
     {
         int result = (NullStringValue != null ? NullStringValue.GetHashCode() : 0);
         result = (result * 397) ^ (NotNullStringValue != null ? NotNullStringValue.GetHashCode() : 0);
         result = (result * 397) ^ (NullStringArrayValue != null ? NullStringArrayValue.GetHashCode() : 0);
         result = (result * 397) ^ (NotNullStringArrayValue != null ? NotNullStringArrayValue.GetHashCode() : 0);
         result = (result * 397) ^ (NullBoolValue.HasValue ? NullBoolValue.Value.GetHashCode() : 0);
         result = (result * 397) ^ (NotNullBoolValue.HasValue ? NotNullBoolValue.Value.GetHashCode() : 0);
         result = (result * 397) ^ BoolValue.GetHashCode();
         result = (result * 397) ^ (NullIntValue.HasValue ? NullIntValue.Value : 0);
         result = (result * 397) ^ (NotNullIntValue.HasValue ? NotNullIntValue.Value : 0);
         result = (result * 397) ^ IntValue;
         result = (result * 397) ^ (NullDecimalValue.HasValue ? NullDecimalValue.Value.GetHashCode() : 0);
         result = (result * 397) ^ (NotNullDecimalValue.HasValue ? NotNullDecimalValue.Value.GetHashCode() : 0);
         result = (result * 397) ^ DecimalValue.GetHashCode();
         result = (result * 397) ^ (NullGuidValue.HasValue ? NullGuidValue.Value.GetHashCode() : 0);
         result = (result * 397) ^ (NotNullGuidValue.HasValue ? NotNullGuidValue.Value.GetHashCode() : 0);
         result = (result * 397) ^ GuidValue.GetHashCode();
         result = (result * 397) ^ (NullGuidArrayValue != null ? NullGuidArrayValue.GetHashCode() : 0);
         result = (result * 397) ^ (NotNullGuidArrayValue != null ? NotNullGuidArrayValue.GetHashCode() : 0);
         result = (result * 397) ^ (NullDateTimeValue.HasValue ? NullDateTimeValue.Value.GetHashCode() : 0);
         result = (result * 397) ^ (NotNullDateTimeValue.HasValue ? NotNullDateTimeValue.Value.GetHashCode() : 0);
         result = (result * 397) ^ (NullPartialDateValue.HasValue ? NullPartialDateValue.Value.GetHashCode() : 0);
         result = (result * 397) ^ (NotNullPartialDateValue.HasValue ? NotNullPartialDateValue.Value.GetHashCode() : 0);
         result = (result * 397) ^ EnumValue.GetHashCode();
         result = (result * 397) ^ (NullEnumValue.HasValue ? NullEnumValue.Value.GetHashCode() : 0);
         result = (result * 397) ^ (NotNullEnumValue.HasValue ? NotNullEnumValue.Value.GetHashCode() : 0);
         result = (result * 397) ^ EnumFlagsValue.GetHashCode();
         result = (result * 397) ^ (NullEnumFlagsValue.HasValue ? NullEnumFlagsValue.Value.GetHashCode() : 0);
         result = (result * 397) ^ (NotNullEnumFlagsValue.HasValue ? NotNullEnumFlagsValue.Value.GetHashCode() : 0);
         return(result);
     }
 }
Пример #2
0
        public void Converter_ChangeTypeWithType_With_TypeValues()
        {
            var typedDateTime = DateTimeValue.ChangeTypeWithType(typeof(DateTime), CultureInfo.InvariantCulture);

            Assert.AreEqual(DateTimeValue, typedDateTime);

            var typedDecimal = DecimalValue.ChangeTypeWithType(typeof(Decimal), CultureInfo.InvariantCulture);

            Assert.AreEqual(DecimalValue, typedDecimal);

            var typedString = StringValue.ChangeTypeWithType(typeof(String), CultureInfo.InvariantCulture);

            Assert.AreEqual(StringValue, typedString);

            var typedGuid = GuidValue.ChangeTypeWithType(typeof(Guid), CultureInfo.InvariantCulture);

            Assert.AreEqual(GuidValue, typedGuid);

            var typedInt16 = Int16Value.ChangeTypeWithType(typeof(Int16), CultureInfo.InvariantCulture);

            Assert.AreEqual(Int16Value, typedInt16);

            var typedInt32 = Int32Value.ChangeTypeWithType(typeof(Int32), CultureInfo.InvariantCulture);

            Assert.AreEqual(Int32Value, typedInt32);

            var typedInt64 = Int64Value.ChangeTypeWithType(typeof(Int64), CultureInfo.InvariantCulture);

            Assert.AreEqual(Int64Value, typedInt64);

            var typedBool = BoolValue.ChangeTypeWithType(typeof(bool), CultureInfo.InvariantCulture);

            Assert.AreEqual(BoolValue, typedBool);
        }
Пример #3
0
        public ShortGuid(string value)
        {
            CheckIsNotNullOrWhitespace(nameof(value), value);
            CheckIsNotCondition(nameof(value), value.Length < 22, () => $"{value} is not a shortguid.");

            _guidValue = new GuidValue(value);
        }
Пример #4
0
 public override int GetHashCode()
 {
     unchecked
     {
         var result = GuidValue.GetHashCode();
         result = (result * 397) ^ (StringValue != null ? StringValue.GetHashCode() : 0);
         result = (result * 397) ^ IntValue;
         result = (result * 397) ^ LongValue.GetHashCode();
         result = (result * 397) ^ BoolValue.GetHashCode();
         result = (result * 397) ^ ByteValue.GetHashCode();
         result = (result * 397) ^ DecimalValue.GetHashCode();
         result = (result * 397) ^ DoubleValue.GetHashCode();
         result = (result * 397) ^ DateTimeValue.GetHashCode();
         result = (result * 397) ^ MaybeMoney.GetHashCode();
         return(result);
     }
 }
Пример #5
0
 protected bool Equals(ClassWithAllTypes other)
 {
     return(CharValue == other.CharValue &&
            ByteValue == other.ByteValue &&
            SByteValue == other.SByteValue &&
            ShortValue == other.ShortValue &&
            UShortValue == other.UShortValue &&
            IntValue == other.IntValue &&
            UIntValue == other.UIntValue &&
            LongValue == other.LongValue &&
            ULongValue == other.ULongValue &&
            FloatValue.Equals(other.FloatValue) &&
            DoubleValue.Equals(other.DoubleValue) &&
            DecimalValue == other.DecimalValue &&
            DateTimeValue.Equals(other.DateTimeValue) &&
            GuidValue.Equals(other.GuidValue) &&
            StringValue.Equals(other.StringValue));
 }
Пример #6
0
        static Constants()
        {
            BoolValue          = true;
            DateTimeValue      = DateTime.Parse(DateTime.MaxValue.ToString(), CultureInfo.InvariantCulture);
            DecimalValue       = Decimal.MaxValue;
            GuidValue          = Guid.NewGuid();
            Int16Value         = Int16.MaxValue;
            Int32Value         = Int32.MaxValue;
            Int64Value         = Int64.MaxValue;
            StringValue        = Guid.NewGuid().ToString();
            NullableInt64Value = Int64.MaxValue;

            BoolStringValue          = BoolValue.ToString();
            DateTimeStringValue      = DateTimeValue.ToString();
            DecimalStringValue       = DecimalValue.ToString();
            GuidStringValue          = GuidValue.ToString();
            Int16StringValue         = Int16Value.ToString();
            Int32StringValue         = Int32Value.ToString();
            Int64StringValue         = Int64Value.ToString();
            NullableInt64StringValue = NullableInt64Value.ToString();
        }
Пример #7
0
 public override int GetHashCode()
 {
     unchecked
     {
         var hashCode = CharValue.GetHashCode();
         hashCode = (hashCode * 397) ^ ByteValue.GetHashCode();
         hashCode = (hashCode * 397) ^ SByteValue.GetHashCode();
         hashCode = (hashCode * 397) ^ ShortValue.GetHashCode();
         hashCode = (hashCode * 397) ^ UShortValue.GetHashCode();
         hashCode = (hashCode * 397) ^ IntValue;
         hashCode = (hashCode * 397) ^ (int)UIntValue;
         hashCode = (hashCode * 397) ^ LongValue.GetHashCode();
         hashCode = (hashCode * 397) ^ ULongValue.GetHashCode();
         hashCode = (hashCode * 397) ^ FloatValue.GetHashCode();
         hashCode = (hashCode * 397) ^ DoubleValue.GetHashCode();
         hashCode = (hashCode * 397) ^ DecimalValue.GetHashCode();
         hashCode = (hashCode * 397) ^ DateTimeValue.GetHashCode();
         hashCode = (hashCode * 397) ^ GuidValue.GetHashCode();
         hashCode = (hashCode * 397) ^ StringValue.GetHashCode();
         return(hashCode);
     }
 }
Пример #8
0
 public override string AsJson()
 {
     return(JsonFormat.Inject("\"" + StructureId.ToString("N") + "\"", SortOrder, IntegerValue, NullableIntegerValue, StringValue, GuidValue.ToString("N"), BoolValue.ToString().ToLower()));
 }
Пример #9
0
 public static string GetGuidSqlValue(IDbContext dbContext)
 {
     return(dbContext.DbType == DbTypeName.SqlServer? $"'{GuidValue}'" : $"hextoraw('{GuidValue.ToString().Replace("-","")}')");
 }
Пример #10
0
        public static void CreateTestTableWithAllTypes(IDbContext dbContext, string tableName, bool addDepercatedTypes)
        {
            var columnFactory = dbContext.PowerPlant.CreateColumnFactory();
            var columns       = new List <IColumn>
            {
                columnFactory.CreateInstance(ColumnTypeName.BinaryDouble, "binarydouble_col", 0, 0, 0, false, false, "0", ""),
                columnFactory.CreateInstance(ColumnTypeName.BinaryFloat, "binaryfloat_col", 0, 0, 0, false, false, "0", ""),
                columnFactory.CreateInstance(ColumnTypeName.Blob, "blob_col", true, ""),
                columnFactory.CreateInstance(ColumnTypeName.Bool, "bool_col", 0, 1, 0, false, false, "0", ""),
                columnFactory.CreateInstance(ColumnTypeName.Char, "char_col", 2, false, "' '", "Danish_Norwegian_CI_AS"),
                columnFactory.CreateInstance(ColumnTypeName.Date, "date_col", false, "MIN_DATE"),
                columnFactory.CreateInstance(ColumnTypeName.DateTime, "datetime_col", false, "MIN_DATE"),
                columnFactory.CreateInstance(ColumnTypeName.Dec, "dec_col", 0, 8, 5, false, false, "0", ""),
                columnFactory.CreateInstance(ColumnTypeName.Float, "float_col", 0, 0, 0, false, false, "0", ""),
                columnFactory.CreateInstance(ColumnTypeName.Float, "float47_col", 47, 0, 0, false, false, "0", ""),
                columnFactory.CreateInstance(ColumnTypeName.Guid, "guid_col", true, ""),
                columnFactory.CreateInstance(ColumnTypeName.Int, "int_col", 0, 15, 0, false, false, "0", ""),
                columnFactory.CreateInstance(ColumnTypeName.Int16, "int16_col", 0, 5, 0, false, false, "0", ""),
                columnFactory.CreateInstance(ColumnTypeName.Int64, "int64_col", 0, 20, 0, false, false, "0", ""),
                columnFactory.CreateInstance(ColumnTypeName.Int8, "int8_col", 0, 3, 0, false, false, "0", ""),
                columnFactory.CreateInstance(ColumnTypeName.LongText, "longtext_col", 0, false, "' '", "Danish_Norwegian_CI_AS"),
                columnFactory.CreateInstance(ColumnTypeName.Money, "money_col", 0, 19, 4, false, false, "0", ""),
                columnFactory.CreateInstance(ColumnTypeName.NChar, "nchar_col", 2, false, "' '", "Danish_Norwegian_CI_AS"),
                columnFactory.CreateInstance(ColumnTypeName.NLongText, "nlongtext_col", 0, false, "' '", "Danish_Norwegian_CI_AS"),
                columnFactory.CreateInstance(ColumnTypeName.NVarchar, "nvarchar_col", 50, false, "' '", "Danish_Norwegian_CI_AS"),
                columnFactory.CreateInstance(ColumnTypeName.Raw, "raw_col", 1000, 0, 0, true, false, "", ""),
                columnFactory.CreateInstance(ColumnTypeName.SmallDateTime, "smalldatetime_col", false, "MIN_DATE"),
                columnFactory.CreateInstance(ColumnTypeName.SmallMoney, "smallmoney_col", 0, 10, 4, false, false, "0", ""),
                columnFactory.CreateInstance(ColumnTypeName.Time, "time_col", false, "MIN_DATE"),
                columnFactory.CreateInstance(ColumnTypeName.Timestamp, "timestamp_col", false, ""),
                columnFactory.CreateInstance(ColumnTypeName.Varchar, "varchar_col", 50, false, "' '", "Danish_Norwegian_CI_AS")
            };

            if (addDepercatedTypes)
            {
                columns.Add(columnFactory.CreateInstance(ColumnTypeName.OldBlob, "oldblob_col", true, ""));
                columns.Add(columnFactory.CreateInstance(ColumnTypeName.OldText, "oldtext_col", 0, false, "' '", "Danish_Norwegian_CI_AS"));
            }
            var tableDefinition = new TableDefinition(tableName, columns, "");
            var dbSchema        = dbContext.PowerPlant.CreateDbSchema();

            dbSchema.CreateTable(tableDefinition);
            var stmt = new StringBuilder();

            stmt.Append($"insert into {tableName} (");
            stmt.Append("binarydouble_col, ");
            stmt.Append("binaryfloat_col, ");
            stmt.Append("blob_col, ");
            stmt.Append("bool_col, ");
            stmt.Append("char_col, ");
            stmt.Append("date_col, ");
            stmt.Append("datetime_col, ");
            stmt.Append("dec_col, ");
            stmt.Append("float_col, ");
            stmt.Append("float47_col, ");
            stmt.Append("guid_col, ");
            stmt.Append("int_col, ");
            stmt.Append("int16_col, ");
            stmt.Append("int64_col, ");
            stmt.Append("int8_col, ");
            stmt.Append("longtext_col, ");
            stmt.Append("money_col, ");
            stmt.Append("nchar_col, ");
            stmt.Append("nlongtext_col, ");
            stmt.Append("nvarchar_col, ");
            stmt.Append("raw_col, ");
            stmt.Append("smalldatetime_col, ");
            stmt.Append("smallmoney_col, ");
            stmt.Append("time_col, ");
            stmt.Append("timestamp_col, ");
            stmt.Append("varchar_col");
            if (addDepercatedTypes)
            {
                stmt.Append(", oldblob_col, ");
                stmt.Append("oldtext_col ");
            }
            stmt.Append(")");

            stmt.Append("values (");

            stmt.Append(GetBinaryDoubleSqlValue());
            stmt.Append(GetBinaryFloatSqlValue());
            stmt.Append(GetBlobSqlValue(dbContext));
            stmt.Append(GetBoolSqlValue());
            stmt.Append(GetCharSqlValue());
            stmt.Append(GetDateSqlValue(dbContext));
            stmt.Append(GetDateTimeSqlValue(dbContext));
            stmt.Append(GetDecSqlValue());
            stmt.Append(GetFloatSqlValue());
            stmt.Append(GetFloat47SqlValue());
            stmt.Append(GetGuidSqlValue(dbContext));
            stmt.Append(GetIntSqlValue());
            stmt.Append(GetInt16SqlValue());
            stmt.Append(GetInt64SqlValue());
            stmt.Append(GetInt8SqlValue());
            stmt.Append(GetLongTextSqlValue());
            stmt.Append(GetMoneySqlValue());
            stmt.Append(GetNCharSqlValue(dbContext));
            stmt.Append(GetNLongTextSqlValue(dbContext));
            stmt.Append(GetNVarcharSqlValue(dbContext));
            stmt.Append(GetRawSqlValue(dbContext));
            stmt.Append(GetSmallDateTimeSqlValue(dbContext));
            stmt.Append(GetSmallMoneySqlValue());
            stmt.Append(GetTimeSqlValue(dbContext));
            stmt.Append(GetTimeStampSqlValue(dbContext));
            stmt.Append(GetVarcharSqlValue());

            stmt.Append($"{BinaryDoubleValue:F15}, ");
            stmt.Append($"{BinaryFloatValue:F10}, ");
            stmt.Append(dbContext.DbType == DbTypeName.SqlServer ? $"convert(varbinary, '{BlobValue}'), " : $"utl_raw.cast_to_raw('{BlobValue}'), ");
            stmt.Append(BoolValue ? "1, ": "0, ");
            stmt.Append($"'{CharValue}', ");
            stmt.Append(dbContext.DbType == DbTypeName.SqlServer ? $"'{DateValue:MMM dd yyyy}', " : $"to_date('{DateValue:MMM dd yyyy}', 'Mon DD YYYY'), ");
            stmt.Append(dbContext.DbType == DbTypeName.SqlServer ? $"'{DateTimeValue:MMM dd yyyy HH:mm:ss}', " : $"to_date('{DateTimeValue:MMM dd yyyy HH:mm:ss}', 'Mon DD YYYY HH24:MI:SS'), ");
            stmt.Append($"{DecValue:###.#####}, ");
            stmt.Append($"{FloatValue:F15}, ");
            stmt.Append($"{Float47Value:F15}, ");
            stmt.Append(dbContext.DbType == DbTypeName.SqlServer ? $"'{GuidValue}', " : $"hextoraw('{GuidValue.ToString().Replace("-","")}'), ");
            stmt.Append($"{IntValue}, ");
            stmt.Append($"{Int16Value}, ");
            stmt.Append($"{Int64Value}, ");
            stmt.Append($"{Int8Value}, ");
            stmt.Append($"'{LongTextValue}', ");
            stmt.Append($"{MoneyValue}, ");
            stmt.Append($"'{NCharValue}', ");
            stmt.Append($"'{NLongTextValue}', ");
            stmt.Append($"'{NVarcharValue}', ");
            stmt.Append(dbContext.DbType == DbTypeName.SqlServer ? $"convert(varbinary, '{RawValue}'), " : $"utl_raw.cast_to_raw('{RawValue}'), ");
            stmt.Append(dbContext.DbType == DbTypeName.SqlServer ? $"'{SmallDateTimeValue:MMM dd yyyy}', " : $"to_date('{SmallDateTimeValue:MMM dd yyyy}', 'Mon DD YYYY'), ");
            stmt.Append($"{SmallMoneyValue:F3}, ");
            stmt.Append(dbContext.DbType == DbTypeName.SqlServer ? $"'{TimeValue:HH:mm:ss}', " : $"to_date('{TimeValue:HH:mm:ss}', 'HH24:MI:SS'), ");
            stmt.Append(dbContext.DbType == DbTypeName.SqlServer ? $"'{TimeStampValue:MMM dd yyyy HH:mm:ss.fffffff}', " : $"to_timestamp('{TimeStampValue:MMM dd yyyy HH:mm:ss.fffffff}', 'Mon DD YYYY HH24:MI:SS.FF'), ");
            stmt.Append($"'{VarcharValue}'");
            if (addDepercatedTypes)
            {
                stmt.Append(", ");
                stmt.Append(dbContext.DbType == DbTypeName.SqlServer ? $"convert(image, '{BlobValue}'), " : $"utl_raw.cast_to_raw('{BlobValue}'), ");
                stmt.Append($"'{LongTextValue}'");
            }
            stmt.Append(")");

            var commands = dbContext.PowerPlant.CreateCommands();

            commands.ExecuteNonQuery(stmt.ToString());
        }
Пример #11
0
 public ShortGuid(Guid guid)
 {
     _guidValue = new GuidValue(guid);
 }
Пример #12
0
 public object ChangeType_Guid()
 {
     return(GuidValue.ChangeType(typeof(Guid), CultureInfo.InvariantCulture));
 }