public static bool IsPossiblyNullablePrimitive(this ExcelPropertyType excelPropertyType)
 {
     return(excelPropertyType ==
            ExcelPropertyType.Boolean ||
            excelPropertyType == ExcelPropertyType.DateTime ||
            excelPropertyType == ExcelPropertyType.Decimal ||
            excelPropertyType == ExcelPropertyType.Enum ||
            excelPropertyType == ExcelPropertyType.Number ||
            excelPropertyType == ExcelPropertyType.TimeSpan);
 }
 public VisitedGivenSimpleProperty(
     string propertyOrFunctionName,
     string cSharpCodeRepresentation,
     ExcelPropertyType excelPropertyType,
     bool nullable = false)
 {
     PropertyOrFunctionName   = propertyOrFunctionName;
     CsharpCodeRepresentation = cSharpCodeRepresentation;
     ExcelPropertyType        = excelPropertyType;
     Nullable = nullable;
 }
 public static bool IsSimpleProperty(this ExcelPropertyType excelPropertyType)
 {
     return(excelPropertyType ==
            ExcelPropertyType.Boolean ||
            excelPropertyType == ExcelPropertyType.DateTime ||
            excelPropertyType == ExcelPropertyType.Decimal ||
            excelPropertyType == ExcelPropertyType.Enum ||
            excelPropertyType == ExcelPropertyType.Null ||
            excelPropertyType == ExcelPropertyType.Number ||
            excelPropertyType == ExcelPropertyType.String ||
            excelPropertyType == ExcelPropertyType.TimeSpan);
 }
 static void AssertContains(
     IEnumerable <IGivenClassProperty> properties,
     string propertyOrFunctionName,
     ExcelPropertyType excelPropertyType)
 =>
 CollectionAssert.Contains(
     properties,
     new GivenClassSimpleProperty(
         propertyOrFunctionName,
         excelPropertyType
         )
     );
Esempio n. 5
0
 static void AssertContains(
     GivenSimplePropertyVisitRecorder visitRecorder,
     string propertyOrFunctionName,
     string cSharpCodeRepresentation,
     ExcelPropertyType excelPropertyType)
 =>
 CollectionAssert.Contains(
     visitRecorder.RecordedSimpleProperties,
     new VisitedGivenSimpleProperty(
         propertyOrFunctionName,
         cSharpCodeRepresentation,
         excelPropertyType
         )
     );
        string CsharpPropertyTypeName(ExcelPropertyType type, string propertyValue, bool nullable)
        {
            var questionMark = nullable ? "?" : "";

            switch (type)
            {
            case ExcelPropertyType.Null:
                return(typeof(object).Name);

            case ExcelPropertyType.Number:
                return("Double" + questionMark);

            case ExcelPropertyType.Decimal:
                return("Deciml" + questionMark);

            case ExcelPropertyType.String:
                return(typeof(string).Name);

            case ExcelPropertyType.DateTime:
                return("DateTime" + questionMark);

            case ExcelPropertyType.TimeSpan:
                return("TimeSpan" + questionMark);

            case ExcelPropertyType.Enum:
                return(propertyValue?.Substring(0, Math.Max(propertyValue.IndexOf('.'), 1)) ?? "Enum /* no value in excel tests for value of this enum, so unable to deduce the type */");

            case ExcelPropertyType.Boolean:
                return("bool" + questionMark);

            case ExcelPropertyType.Object:
                return(typeof(object).Name);

            case ExcelPropertyType.List:
                return(typeof(IEnumerable).Name);

            default:
                throw new ArgumentOutOfRangeException(nameof(type));
            }
            ;
        }
        public GivenClassSimpleProperty(
            string name,
            ExcelPropertyType type,
            string exampleValue = "",
            bool nullable       = true)
        {
            if (string.IsNullOrWhiteSpace(name))
            {
                throw new System.ArgumentException("name is required", nameof(name));
            }

            // this is a code smell, but not going to worry too much for now. A Sum type is really
            // what I want here but they don't easily exist in C#. There almost certainly is a better
            // solution though
            if (type == ExcelPropertyType.Object)
            {
                throw new System.ArgumentException("ExcelPropertyType cannot be ExcelPropertyType.Object for simple properties", nameof(name));
            }

            Name         = name;
            Type         = type;
            ExampleValue = exampleValue;
            Nullable     = nullable;
        }