static AtrPreambleTokenAdapter() { ObservableObject.IPropertyAdapterFactory <AtrPreambleTokenAdapter> PropertyFactory = ObservableObject.GetPropertyAdapterFactory <AtrPreambleTokenAdapter>(); AtrPreambleTokenAdapter.codingConventionAdapter = PropertyFactory.Create( nameof(AtrPreambleTokenAdapter.CodingConvention), instance => AtrPreambleTokenAdapter.ToString(instance.preamble.CodingConvention) ); AtrPreambleTokenAdapter.numberOfHistoricalCharactersAdapter = PropertyFactory.Create( nameof(AtrPreambleTokenAdapter.NumberOfHistoricalCharacters), instance => instance.preamble.NumberOfHistoricalCharacters ); AtrPreambleTokenAdapter.nextBytesTypeAdapter = PropertyFactory.Create( nameof(AtrPreambleTokenAdapter.NextBytes), instance => instance.preamble.NextInterfaceBytesIndicator != null ? AtrTokenAdapterBase.ToString(instance.preamble.NextInterfaceBytesIndicator.TaExists, instance.preamble.NextInterfaceBytesIndicator.TbExists, instance.preamble.NextInterfaceBytesIndicator.TcExists, instance.preamble.NextInterfaceBytesIndicator.TdExists) : "not set" ); }
static AtrInterfaceByteGroupTokenAdapter() { ObservableObject.IPropertyAdapterFactory <AtrInterfaceByteGroupTokenAdapter> PropertyFactory = ObservableObject.GetPropertyAdapterFactory <AtrInterfaceByteGroupTokenAdapter>(); AtrInterfaceByteGroupTokenAdapter.groupNumberAdatper = PropertyFactory.Create( nameof(AtrInterfaceByteGroupTokenAdapter.GroupNumber), instance => instance.atrInterfaceByteGroupToken.Number ); AtrInterfaceByteGroupTokenAdapter.typeAdatper = PropertyFactory.Create( nameof(AtrInterfaceByteGroupTokenAdapter.Type), instance => EnumerationAdapter <InterfaceByteGroupType> .GetInstanceFor(instance.atrInterfaceByteGroupToken.Type) ); AtrInterfaceByteGroupTokenAdapter.taAdapter = PropertyFactory.Create( nameof(AtrInterfaceByteGroupTokenAdapter.Ta), instance => instance.atrInterfaceByteGroupToken.Ta.HasValue ? instance.atrInterfaceByteGroupToken.Ta.Value.ToHexString() : null, (instance, value) => instance.atrInterfaceByteGroupToken.Ta = !string.IsNullOrEmpty(value)?byte.Parse(value.Substring(0, Math.Min(value.Length, 2)), NumberStyles.HexNumber):(byte?)null ); AtrInterfaceByteGroupTokenAdapter.tbAdapter = PropertyFactory.Create( nameof(AtrInterfaceByteGroupTokenAdapter.Tb), instance => instance.atrInterfaceByteGroupToken.Tb.HasValue ? instance.atrInterfaceByteGroupToken.Tb.Value.ToHexString() : null, (instance, value) => instance.atrInterfaceByteGroupToken.Tb = !string.IsNullOrEmpty(value) ? byte.Parse(value.Substring(0, Math.Min(value.Length, 2)), NumberStyles.HexNumber) : (byte?)null ); AtrInterfaceByteGroupTokenAdapter.tcAdapter = PropertyFactory.Create( nameof(AtrInterfaceByteGroupTokenAdapter.Tc), instance => instance.atrInterfaceByteGroupToken.Tc.HasValue ? instance.atrInterfaceByteGroupToken.Tc.Value.ToHexString() : null, (instance, value) => instance.atrInterfaceByteGroupToken.Tc = !string.IsNullOrEmpty(value) ? byte.Parse(value.Substring(0, Math.Min(value.Length, 2)), NumberStyles.HexNumber) : (byte?)null ); AtrInterfaceByteGroupTokenAdapter.nextGroupTypeAdapter = PropertyFactory.Create( nameof(AtrInterfaceByteGroupTokenAdapter.NextGroupType), instance => EnumerationAdapter <InterfaceByteGroupType> .GetInstanceFor(instance.atrInterfaceByteGroupToken.NextInterfaceBytesIndicator != null?instance.atrInterfaceByteGroupToken.NextInterfaceBytesIndicator.GroupType:(InterfaceByteGroupType?)null) ); AtrInterfaceByteGroupTokenAdapter.nextBytesTypeAdapter = PropertyFactory.Create( nameof(AtrInterfaceByteGroupTokenAdapter.NextBytes), instance => instance.atrInterfaceByteGroupToken.NextInterfaceBytesIndicator != null?AtrTokenAdapterBase.ToString(instance.atrInterfaceByteGroupToken.NextInterfaceBytesIndicator.TaExists, instance.atrInterfaceByteGroupToken.NextInterfaceBytesIndicator.TbExists, instance.atrInterfaceByteGroupToken.NextInterfaceBytesIndicator.TcExists, instance.atrInterfaceByteGroupToken.NextInterfaceBytesIndicator.TdExists):"not set" ); AtrInterfaceByteGroupTokenAdapter.possibleTypesToChangeToAdapter = PropertyFactory.Create( nameof(AtrInterfaceByteGroupTokenAdapter.PossibleTypesToChangeTo), instance => ((InterfaceByteGroupType[])Enum.GetValues(typeof(InterfaceByteGroupType))) .Where(_ => _ != InterfaceByteGroupType.Global) //gloabl cannot be set; the first group automatically is global .Where(_ => instance.atrInterfaceByteGroupToken.NextGroup != null) //nothing cannot be set if no next group .Where(_ => _ != instance.atrInterfaceByteGroupToken.NextInterfaceBytesIndicator.GroupType) //we can skip what is already set .OrderBy(_ => (int)_) //Sort by id .SkipWhile(value => value < instance.atrInterfaceByteGroupToken.Type) //Next Group cannot be less than this group. Same is OK .TakeWhile(value => instance.atrInterfaceByteGroupToken.NextGroup.NextInterfaceBytesIndicator == null || value <= instance.atrInterfaceByteGroupToken.NextGroup.NextInterfaceBytesIndicator.GroupType), //next group cannot be higher than next to next group. Same is OK (instance, item) => EnumerationAdapter <InterfaceByteGroupType> .GetInstanceFor(item) ); AtrInterfaceByteGroupTokenAdapter.possibleTypesToAddNextGroupAdapter = PropertyFactory.Create( nameof(AtrInterfaceByteGroupTokenAdapter.PossibleTypesToAddNextGroup), instance => ((InterfaceByteGroupType[])Enum.GetValues(typeof(InterfaceByteGroupType))) .Where(_ => _ != InterfaceByteGroupType.Global) //gloabl cannot be set; the first group automatically is global .OrderBy(_ => (int)_) //Sort by id .SkipWhile(value => value < instance.atrInterfaceByteGroupToken.Type) //Next Group cannot be less than this group. Same is OK .TakeWhile(value => instance.atrInterfaceByteGroupToken.NextInterfaceBytesIndicator == null || value <= instance.atrInterfaceByteGroupToken.NextInterfaceBytesIndicator.GroupType), //next group cannot be higher than next to next group. Same is OK (instance, item) => EnumerationAdapter <InterfaceByteGroupType> .GetInstanceFor(item) ); }