private Type GetPropertyType(PropertyDefinition propertyDefinition)
        {
            var propertyType = propertyDefinition.IsObjectID ? propertyDefinition.PropertyInfo.PropertyType : propertyDefinition.PropertyType;

            if (NullableTypeUtility.IsNullableType(propertyType))
            {
                propertyType = NullableTypeUtility.GetBasicType(propertyType);
            }
            return(propertyType);
        }
Пример #2
0
        public void CollectPropertyType(PropertyDefinition propertyDefinition)
        {
            ArgumentUtility.CheckNotNull("propertyDefinition", propertyDefinition);

            var propertyType = propertyDefinition.PropertyType;

            if (NullableTypeUtility.IsNullableType(propertyType))
            {
                propertyType = NullableTypeUtility.GetBasicType(propertyType);
            }

            if (propertyType.IsEnum)
            {
                _enumTypes.Add(propertyType);
            }
        }
Пример #3
0
        private void CheckEnumValue(object value, PropertyDefinition definition)
        {
            if (value != null)
            {
                Type underlyingType = definition.IsNullable ? NullableTypeUtility.GetBasicType(definition.PropertyType) : definition.PropertyType;
                if (!EnumUtility.IsValidEnumValue(underlyingType, value))
                {
                    string message = string.Format(
                        "Value '{0}' for property '{1}' is not defined by enum type '{2}'.",
                        value,
                        definition.PropertyName,
                        underlyingType);

                    throw new InvalidEnumValueException(message, definition.PropertyName, underlyingType, value);
                }
            }
        }
Пример #4
0
 public void GetBasicType_ReferenceType()
 {
     Assert.That(NullableTypeUtility.GetBasicType(typeof(string)), Is.EqualTo(typeof(string)));
 }
Пример #5
0
 public void GetBasicType_NullableValueType()
 {
     Assert.That(NullableTypeUtility.GetBasicType(typeof(int?)), Is.EqualTo(typeof(int)));
 }
Пример #6
0
 public void GetBasicType_WithNull_ThrowsArgumentNullException()
 {
     Assert.That(
         () => NullableTypeUtility.GetBasicType(null),
         Throws.TypeOf <ArgumentNullException>().With.Message.EndsWith("Parameter name: type"));
 }