I have a static class ‘Defaults’ which shall hold default matrices that are forwarded to an interface that asks for double[][] in the end. So far I simply put static properties in this class that return double[][]s.
Now to make this conform to our company’s coding standards, the code must comply to FxCop’s rule CA1819, which won’t allow me to return a jagged array from a property like I did. And instead of arrays, I shall return IList or IEnumerable (as discussed here).
“Fair enough” I thought, so I implemented the property to return IList<IList<double>> (although nested types are uncool too). However, as I said, the interface which I need to work with asks for double[][] matrices in the end.. I have no idea how to get this list of lists into an array of arrays without explicitly converting back each list. Of course, I could, but that would create an insane amount of overhead, especially since I don’t even access those matrices – I only pass them through to the interface.
(PS: I know, it’s the Interface’s fault, but at the moment we can’t change that.)
Edit: I found out that using ILists<IList<double>> donesn’t help anyway, since it violates CA1006. The easy solution that I took to make FxCop shut up was to make the properties internal. Anyway, the nicer solution is stated below. Alternatively, one may consider to use an indexed property, which is a bit messy in C# though.
I suggest, you create a class
Matrix<T>that accepts aT[][]into its constructor and can be converted toT[][]and make your properties inDefaultsreturn aMatrix<double>instance. The conversion can either be implemented implicitly, explicitly or using a method.