예제 #1
0
        public static string ConvertToSQLProperty(this PropertyInfo property)
        {
            bool NotNullValue  = Attribute.IsDefined(property, typeof(NotNullAttribute));
            bool IdentityValue = Attribute.IsDefined(property, typeof(IdentityAttribute));
            MaxLenghtAttribute MaxLenghtValue = (MaxLenghtAttribute)Attribute.GetCustomAttribute(property, typeof(MaxLenghtAttribute));

            switch (property.PropertyType.ToString())
            {
            case Boolean:
                return($"{property.Name} BIT,");

            case DateTime:
                return($"{property.Name} DATETIME2 {(NotNullValue ? "NOT NULL" : string.Empty )},");

            case Guid:
                return($"{property.Name} UNIQUEIDENTIFIER {(NotNullValue ? "NOT NULL" : string.Empty)},");

            case Int32:
                return($"{property.Name} INT {(NotNullValue ? "NOT NULL" : string.Empty)} {(IdentityValue ? "IDENTITY(1,1)" : string.Empty)},");

            case Int64:
                return($"{property.Name} BIGINT {(NotNullValue ? "NOT NULL" : string.Empty)}");

            case String:
                return($"{property.Name} NVARCHAR({((MaxLenghtValue != null) ? MaxLenghtValue.MaxLenght : "max")}) {(NotNullValue ? "NOT NULL" : string.Empty)},");

            default:
                throw new InvalidOperationException("PropertyInfo value is not valid");
            }
        }
예제 #2
0
        public void Should_Be_Max_Flase(object value)
        {
            var attr = new MaxLenghtAttribute(2);

            Assert.False(attr.IsValid(value));
        }
예제 #3
0
        public void Should_Be_Max_True(object value)
        {
            var attr = new MaxLenghtAttribute(4);

            Assert.True(attr.IsValid(value));
        }