<commit_before>﻿using System;
using System.Reflection;

namespace ExpressiveAnnotations.ConditionalAttributes
{
    public class Assert
    {
        public static void ConsistentTypes(PropertyInfo dependentField, object targetValue, string field, string attribute)
        {
            if (targetValue == null || string.Equals(targetValue as string, "*"))
                return; // type doesn't matter when null or star is involved

            if (dependentField.PropertyType != targetValue.GetType())
                throw new InvalidOperationException(
                    string.Format(
                        "Type mismatch detected in {0} definition for {1} field. Types consistency is required for {2} field and its corresponding target value (unless target is null or *).",
                        attribute, field, dependentField.Name));
        }
    }
}<commit_msg>Types consistency assertion fix for nullable types.<commit_after>﻿using System;
using System.Reflection;

namespace ExpressiveAnnotations.ConditionalAttributes
{
    public class Assert
    {
        public static void ConsistentTypes(PropertyInfo dependentField, object targetValue, string field, string attribute)
        {
            if (targetValue == null || string.Equals(targetValue as string, "*"))
                return; // type doesn't matter when null or star is involved

            var propertyType = dependentField.PropertyType;
            propertyType = propertyType.IsGenericType && propertyType.GetGenericTypeDefinition() == typeof (Nullable<>)
                ? Nullable.GetUnderlyingType(propertyType)
                : propertyType;
            var targetType = targetValue.GetType();
            targetType = targetType.IsGenericType && targetType.GetGenericTypeDefinition() == typeof (Nullable<>)
                ? Nullable.GetUnderlyingType(targetType)
                : targetType;

            if (propertyType != targetType)
                throw new InvalidOperationException(
                    string.Format(
                        "Type mismatch detected in {0} definition for {1} field. Types consistency is required for {2} field and its corresponding target value (unless target is null or *).",
                        attribute, field, dependentField.Name));
        }
    }
}
{'fraction_non_alphanumeric': 0.07705703090988246, 'fraction_numerical': 0.00261210274270788, 'mean_word_length': 2.4247391952309987, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6099605', 'n_tokens_mistral': 522, 'n_tokens_neox': 492, 'n_words': 170}