I have a naming problem for some of my classes. I need to wrap some primitive .net types into a class like the following. There will be about 20 of such classes.
(The naming is crap, of course. Just for a demonstrative purpose)
public class Int32Single
{
public int Value { get; set; }
}
public class Int32Double
{
public int Value1 { get; set; }
public int Value2 { get; set; }
}
public class DoubleSingle
{
public double Value { get; set; }
}
I can’t use a generic approach for this.
How should I name such wrapper classes, where each class name should provide the necessary information which primite types are wrapped and in which quantity?
It might also be possible that I have class that contains mixed primite types.
This doesn’t seem like a very good idea at all. You have both the
Tupleclass and a standardarrayavailable, that both make more sense in any conceivable use case. However, that doesn’t answer your question, so…The most intuitive name for a wrapper class would follow the convention of
{type-name}Wrapper, or for example,Int32Wrapper. In your case, the wrapped object is a primitive type, so makes sense to call the class a “Tuple”. Since you want to specify the size of the Tuple in your class name,{primitive-type-name}{size}Tupleseems like the most intuitive naming convention but this causes several problems.SingleandDoublebecause they conflict with the Type names). (e.g.DoubleDoubleis bad)Int322Tupleis bad).We can’t move the size to the beginning such as
2Int32Tuplebecause integers are not valid characters to begin a class name. So, There are two approaches that I think could work.I think your best bet to get around these constraints, is to use a
{primitive-type-name}{text-represented-size}Tupleconvention. (e.g.Int32TwoTupleorDoubleTwoTuple). This convention expresses the contents of the wrapper class without ambiguity, so it seems like a good approach. In addition the name begins with the primitive type name, so, if you have a lot of these classes, it will be easier for your IntelliSense to fill in the correct class name, and it will alphabetically be listed next to the primitive type that is being wrapped.