I'd like to be able to set a datatype for an entire application with a single using clause. My solution contains a bunch of classes, each in its own .cs file, each of which contains the statement:
using ptype = System.Double; // or System.Decimal, etc
By declaring subsequent variables as ptype, I can change from computing in decimal, double, float, by changing this one line of code. Typecasting is equally automatic:
e.Position_full_mid[i_row] = (ptype)((decimal)this_Position + ((decimal)d_Position / 2M));
Where, in this case the division arithmetic must be performed with Decimal accuracy, then the quotient is explicitly cast to ptype. It's nice to have this point of control, but the using clause only has scope for the file it lives in (even though it's declared outside the class). It doesn't appear in the identical namespace in other files; I have to declare it each time.
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
namespace procC
{
using ptype = System.Double;
class Commutation_Proc
{
[System.Serializable]
public class input_data_val // magnetics data parsed from the FEMM results datafiles
{
public int Positions_Count_repeat = 0; //total number of positions in the range equaling <json>PositionStart to equaling <json>PositionRepeat.
public int Positions_Count_unique = 0; //total number of positions in the range equaling <json>PositionStart through less than <json>PositionRepeat. (Positions_Count_repeat - 1)
public ptype[] Position_raw, Position_full; //[Position Index] = double, containing position of the force-measured "moving group", where Position Index is "r_index" and the value is "x_mm" or "r_deg"
public ptype[,,,,] Current_raw, Current_full; //[File index, Position Index, Current / Phase Index, Winding Sector, Winding Series] = double. For Commutated data, use Phase index; this resolves down rows where "phase_idx" is index of winding polarization pattern phase rotation
So far, I haven't found anyplace at the Solution level to define ptype just once, so changing the representation (like switching from Double to Decimal) means editing the
using ptype = System.<whatever>;
statement in a dozen classes (and counting). Can this be defined globally?