using System.Collections.Generic;
public class AllowedCharsBase {
public AllowedCharsBase() { }
public virtual List<byte> GetBytes(ICollection<byte> bytes) {
return (List<byte>)bytes;
public class SeqNumber : AllowedCharsBase {
public override List<byte> GetBytes(ICollection<byte> bytes) {
return bytes.Skip(1).Take(1).ToList<byte>();
class CommdResp : AllowedCharsBase {
public override List<byte> GetBytes(ICollection<byte> bytes) {
return bytes.Skip(2).Take(1).ToList();
class DataBlock : AllowedCharsBase {
public override List<byte> GetBytes(ICollection<byte> bytes) {
var part = bytes.Skip(3).TakeWhile(b => b != 3).ToList();
return part.GetRange(0, part.Count() - 2);
class Checksum : AllowedCharsBase {
public override List<byte> GetBytes(ICollection<byte> bytes) {
return bytes.ToList().GetRange(bytes.Count() - 3, 2);
public static void cout(string s) { Console.WriteLine(s); }
public static void Main()
var data = new List<byte> { 0x02, 0x31, 0x85, 0x31, 0x32, 0x33, 0x47, 0x31, 0x03 };
var block = Get<SeqNumber>(data);
private static List<byte> Get<T>(ICollection<byte> bytes)
where T : AllowedCharsBase
var c = new AllowedCharsBase() as T;
var ret = new List<byte>();