help
Root Question Message
T desiredValue
.T
is int[]
.string desiredValue;
if (typeof(T) == typeof(int[]))
{
format = "{0} = [{1}]\n";
desiredValue = string.Join(", ", this.desiredValue);
}
System.Int32[]
any idea why?desiredValue
being a string..?desiredValue
that is of type T
. It's weird convention I have to follow :/desiredValue
is probably that System.Int32[]
stringdesiredValue
to newValue
to avoid confusiondesiredValue
gets, somehow, turned into a stringpublic class DirectionalitySetCalibrationData<T> : TestActionBase<HearingInstrumentContext>
{
public DirectionalitySetCalibrationData(string propertyName, T desiredValue)
{
this.propertyName = propertyName;
this.desiredValue = desiredValue;
}
public override bool Execute(HearingInstrumentContext hiContext, TestCaseContext testCaseContext)
{
const string assemblyName = "ReSound.Algorithm.Dooku3";
string pattern = propertyName + " = .*?\\n";
Type compress = Assembly.LoadFrom(assemblyName + ".Platform.dll").GetType(assemblyName + ".Compress");
object comCal = Activator.CreateInstance(compress, null);
var compressCalibrationData = (string)hiContext.SoundProgram.Blackboard.Properties[Directionality.CalibrationData.PropertyName].Value;
var calibrationData = (string)compress.GetMethod("DecompressString").Invoke(comCal, new object[] { compressCalibrationData });
string format = "{0} = {1}\n";
string newValue = string.Empty;
if (typeof(T) == typeof(int[]))
{
format = "{0} = [{1}]\n";
newValue = string.Join(", ", this.desiredValue);
}
else if (typeof(T) == typeof(Vector))
{
newValue = this.desiredValue.ToString().Replace(",", ".").Replace(";", ", ");
}
else
{
newValue = this.desiredValue.ToString().Replace(",", ".");
}
string testCalibrationData = Regex.Replace(
calibrationData, pattern,
string.Format(format, propertyName, desiredValue));
hiContext.SoundProgram.Blackboard.Properties[Directionality.CalibrationData.PropertyName].Value = compress
.GetMethod("CompressString").Invoke(comCal, new object[] { testCalibrationData });
return true;
}
private readonly string propertyName;
private readonly T desiredValue;
}