Skip to content

Streamline API by using IConvertible. #7

Description

@vpenades

I've noticed there's a current repetition of APIs that can be greatly simplified...

Let's take Scatter.X for example:

        public static Box<IScatterProperty> x(Literals.PlotData[] values);
        
        public static Box<IScatterProperty> x(IEnumerable<bool[]> values);

        public static Box<IScatterProperty> x(int val);
        public static Box<IScatterProperty> x(bool val);
        public static Box<IScatterProperty> x(float val);
        public static Box<IScatterProperty> x(string val);
        public static Box<IScatterProperty> x(DateTime val);

        public static Box<IScatterProperty> x(params int[][] values);
        public static Box<IScatterProperty> x(params bool[][] values);
	public static Box<IScatterProperty> x(params float[][] values);
        public static Box<IScatterProperty> x(params string[][] values);

        public static Box<IScatterProperty> x(IEnumerable<IEnumerable<int>> values);
        public static Box<IScatterProperty> x(IEnumerable<IEnumerable<float>> values);
        public static Box<IScatterProperty> x(IEnumerable<IEnumerable<string>> values);

        public static Box<IScatterProperty> x(IEnumerable<int?> values);
        public static Box<IScatterProperty> x(IEnumerable<bool?> values);
        public static Box<IScatterProperty> x(IEnumerable<float?> values);
        public static Box<IScatterProperty> x(IEnumerable<DateTime?> values);

        public static Box<IScatterProperty> x(List<int[]> values);
        public static Box<IScatterProperty> x(List<bool[]> values);
        public static Box<IScatterProperty> x(List<float[]> values);
        public static Box<IScatterProperty> x(List<string[]> values);

        public static Box<IScatterProperty> x(IEnumerable<int> values);
        public static Box<IScatterProperty> x(IEnumerable<bool> values);
        public static Box<IScatterProperty> x(IEnumerable<float> values);
        public static Box<IScatterProperty> x(IEnumerable<string> values);
        public static Box<IScatterProperty> x(IEnumerable<DateTime> values);       

This API could be greatly simplified by using the IConvertible interface.

        public static Box<IScatterProperty> x(T)(T val) where T:IConvertible;

	public static Box<IScatterProperty> x(T)(IEnumerable<T> val) where T:IConvertible;

	public static Box<IScatterProperty> x(T)(IEnumerable<T?> val) where T:struct, IConvertible;

	public static Box<IScatterProperty> x(T)(IEnumerable<T[]> val) where T:IConvertible;

	public static Box<IScatterProperty> x(T)(params T[] val) where T:IConvertible;

Since IConvertible is defined in all the BCL types; int, double, float, DateTime, bool, string, it could greatly simplify the whole API, allowing more compatible types, and also providing more flexibility to mix & match types.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions