Esempio n. 1
0
        private static IEnumerable <EAttributeType> EvaluateAttributeTypes(PropertyInfo pi)
        {
            if (pi == null)
            {
                throw new ArgumentNullException("pi");
            }

            var t = ArffUtils.GetNonNullableType(pi.PropertyType);

            if (t.IsEnum || InternalHelpers.IsAtt <NominalAttribute>(pi))
            {
                return(new [] { EAttributeType.Nominal });
            }
            if (t == typeof(string))
            {
                return(new [] { EAttributeType.String });
            }
            if (t == typeof(DateTime))
            {
                return(new [] { EAttributeType.Date });
            }
            if (t == typeof(bool))
            {
                return(new [] { EAttributeType.Binary });
            }
            if (typeof(IEnumerable).IsAssignableFrom(t) &&
                InternalHelpers.IsAtt <FlattenAttribute>(pi))
            {
                // TODO: Only numerics supported at the moment.  Should recurse into something
                // similar to this function to get the actual type of the attribute.
                return(Enumerable.Range(0, InternalHelpers.ToAtt <FlattenAttribute>(pi).IntoHowMany).
                       Select(i => EAttributeType.Numeric).
                       ToArray());
            }
            var tc = Type.GetTypeCode(t);

            if (tc >= TypeCode.SByte && tc <= TypeCode.Decimal)
            {
                return(new [] { EAttributeType.Numeric });
            }
            throw new NotSupportedException(t.Name + " is not a supported attribute atttype.");
        }
Esempio n. 2
0
        private string[] GetAttributePossibleValues(PropertyInfo prop)
        {
            var type = ArffUtils.GetNonNullableType(prop.PropertyType);
            var att  = InternalHelpers.ToAtt <NominalAttribute>(prop);

            if (att != null && !String.IsNullOrWhiteSpace(att.CommaSeparatedValues))
            {
                return(att.CommaSeparatedValues.Split(','));
            }
            if (type.IsEnum)
            {
                return(Enum.GetNames(type));
            }

            var attvals = data.Select(row => InternalHelpers.ToStringSafe(Helpers.GetValue(row, prop.Name))).ToArray();

            return(att is GroupedNominalAttribute?
                   GetGroupedAttributePossibleValues(prop, att, attvals) :
                       attvals.Distinct().ToArray());
        }
Esempio n. 3
0
 public void GetNonNullableTypeTest()
 {
     Assert.AreEqual(typeof(int), ArffUtils.GetNonNullableType(typeof(int?)));
     Assert.AreEqual(typeof(DateTime), ArffUtils.GetNonNullableType(typeof(DateTime?)));
     Assert.AreEqual(typeof(bool), ArffUtils.GetNonNullableType(typeof(bool?)));
 }