Skip to main content

C# Generics for reducing redundancies

Tweeted twitter.com/#!/StackCodeReview/status/160458749092433920

As you can see, there are two ifif branches that are the same. Essentially they create a generic class using floatfloat and intint type.

The class ArrayBufferObjectArrayBufferObject is the base of ArrayBufferObject<T>ArrayBufferObject<T>, but only the latter implements an indexer (strongly typed). It is implemented as following:

The source of the assigned item comes from a ColladaArrayColladaArray class, that is an abstract class wrapping an array of values. To resolve the data accessor I've defined in it a generic numeric accessor like the following:

How would you suggest to remove the GetAccessorArrayGetAccessorArray routine redundancies? Help! Soon it will grow up with all possible numeric types!

As you can see, there are two if branches that are the same. Essentially they create a generic class using float and int type.

The class ArrayBufferObject is the base of ArrayBufferObject<T>, but only the latter implements an indexer (strongly typed). It is implemented as following:

The source of the assigned item comes from a ColladaArray class, that is an abstract class wrapping an array of values. To resolve the data accessor I've defined in it a generic numeric accessor like the following:

How would you suggest to remove the GetAccessorArray routine redundancies? Help! Soon it will grow up with all possible numeric types!

As you can see, there are two if branches that are the same. Essentially they create a generic class using float and int type.

The class ArrayBufferObject is the base of ArrayBufferObject<T>, but only the latter implements an indexer (strongly typed). It is implemented as following:

The source of the assigned item comes from a ColladaArray class, that is an abstract class wrapping an array of values. To resolve the data accessor I've defined in it a generic numeric accessor like the following:

How would you suggest to remove the GetAccessorArray routine redundancies? Help! Soon it will grow up with all possible numeric types!

Fixed some typo
Source Link
Luca
  • 204
  • 1
  • 7

I have a routine that can potentially be potentially reduced.

As you can see, there are two ifif branches that are the same. Essentially they create a generic class using floatfloat and intint type.

The class ArrayBufferObjectArrayBufferObject is the base of ArrayBufferObject<T>ArrayBufferObject<T>, but only the latter implements an indexer (strongly typed). It is implemented as following:

The source of the assigned item comes from a ColladaArrayColladaArray class, that is an abstract class wrapping an array of values. To resolve the data accessor I've defined in it a generic numeric accessor like the following:

Which is implemented in each derived class returning the real array value casted to doubledouble (all arrays containcontains numeric data... hopefully).

How would you suggest to remove the GetAccessorArrayGetAccessorArray routine redundancies? Help! Soon it will grow up with all possible numeric types!

I have a routine that can potentially be reduced.

As you can see, there are two if branches that are the same. Essentially they create a generic class using float and int type.

The class ArrayBufferObject is the base of ArrayBufferObject<T>, but only the latter implements an indexer (strongly typed). It is implemented as following:

The source of the assigned item comes from a ColladaArray class, that is an abstract class wrapping an array of values. To resolve the data accessor I've defined in it a generic numeric accessor like the following:

Which is implemented in each derived class returning the real array value casted to double (all arrays contain numeric data... hopefully).

How would you suggest to remove the GetAccessorArray routine redundancies? Help! Soon it will grow up with all possible numeric types!

I have a routine that can be potentially reduced.

As you can see, there are two if branches that are the same. Essentially they create a generic class using float and int type.

The class ArrayBufferObject is the base of ArrayBufferObject<T>, but only the latter implements an indexer (strongly typed). It is implemented as following:

The source of the assigned item comes from a ColladaArray class, that is an abstract class wrapping an array of values. To resolve the data accessor I've defined in it a generic numeric accessor like the following:

Which is implemented in each derived class returning the real array value casted to double (all arrays contains numeric data... hopefully).

How would you suggest to remove the GetAccessorArray routine redundancies? Help! Soon it will grow up with all possible numeric types!

Source Link
Luca
  • 204
  • 1
  • 7
Loading