XmlSerializers created by XmlSerializer.FromType(new[] {typeof(...)})[0]; This prevents throwing an exception => better debugging.

This commit is contained in:
Milan Hanajik
2017-06-22 21:37:05 +02:00
parent 7ad8c986d7
commit 17f6f7c3be
193 changed files with 450 additions and 182 deletions
@@ -21,7 +21,7 @@ namespace TBF.BenchControl.TestMethods.FixedStartMassCollection.Compound
public IComponentCfg CmpntCfgFromCmpntEntity(Config.Entities.Component component)
{
return ComponentCfgBase.CreateFromDbEntity(typeof(TestMethodCfg), component, this);
return ComponentCfgBase.CreateFromDbEntity(TestMethodCfg.Serializer, component, this);
}
}
}
@@ -20,7 +20,7 @@ namespace TBF.BenchControl.TestMethods.FixedStartMassCollection.HeatMeters
public IComponentCfg CmpntCfgFromCmpntEntity(Config.Entities.Component component)
{
return ComponentCfgBase.CreateFromDbEntity(typeof(TestMethodCfg), component, this);
return ComponentCfgBase.CreateFromDbEntity(TestMethodCfg.Serializer, component, this);
}
}
}
@@ -12,6 +12,9 @@ namespace TBF.BenchControl.TestMethods.FixedStartMassCollection.HeatMeters
{
public class TestMethodCfg : ComponentCfgBase, Generic.IComponentCfg
{
public static XmlSerializer Serializer = XmlSerializer.FromTypes(new[] { typeof(TestMethodCfg) })[0];
protected override XmlSerializer GetSerializer() { return Serializer; }
public IComponentCfgCtrl GetControl() { return new TestMethodCfgCtrl(); }
/// <summary> Test parameters </summary>
@@ -13,6 +13,9 @@ namespace TBF.BenchControl.TestMethods.FixedStartMassCollection.HeatMeters
{
public class TestParams : TestParamsBase, IParamsProvider, ITestParams
{
public static XmlSerializer Serializer = XmlSerializer.FromTypes(new[] { typeof(TestParams) })[0];
protected override XmlSerializer GetSerializer() { return Serializer; }
public float ErrorLimitLo; /// [%]
public float ErrorLimitHi; /// [%]
public bool EvaluateVolume; /// true = evaluate also the volume, false = evaluate only energy
@@ -159,14 +162,13 @@ namespace TBF.BenchControl.TestMethods.FixedStartMassCollection.HeatMeters
if (dbEntity == null) return;
try
{
TestParams tmp = (TestParams)(new XmlSerializer(typeof(TestParams)))
.Deserialize(new StringReader(dbEntity.Parameters));
TestParams tmp = Serializer.Deserialize(new StringReader(dbEntity.Parameters)) as TestParams;
testParamsEntity = dbEntity;
componentName = dbEntity.CmpntName;
test = dbEntity.Test;
tmp.CopyContentTo(this);
if (tmp != null) tmp.CopyContentTo(this);
}
catch
{
@@ -21,7 +21,7 @@ namespace TBF.BenchControl.TestMethods.FixedStartMassCollection.Single
public IComponentCfg CmpntCfgFromCmpntEntity(Config.Entities.Component component)
{
return ComponentCfgBase.CreateFromDbEntity(typeof(TestMethodCfg), component, this);
return ComponentCfgBase.CreateFromDbEntity(TestMethodCfg.Serializer, component, this);
}
}
}