public static void ReadCodeBits <T>(this T source, IBitArrayReader input, int bit) { if (!ReaderDictionary.ContainsKey(typeof(T))) { ReaderDictionary.Add(typeof(T), ConstructCodeBitReader(typeof(T))); } var reader = ReaderDictionary[typeof(T)]; source.ReadCodeBits(reader, input, bit); }
private static void ReadCodeBits <T>(this T source, IEnumerable <Tuple <MemberInfo, int, int> > reader, IBitArrayReader input, int bit) { foreach (var tuple in reader.Where(tuple => tuple.Item2 == bit)) { if (tuple.Item1 is FieldInfo) { ((FieldInfo)tuple.Item1).SetValue(source, input.ReadBitString(tuple.Item3)); return; } if (tuple.Item1 is PropertyInfo) { ((PropertyInfo)tuple.Item1).SetValue(source, input.ReadBitString(tuple.Item3)); return; } } throw new Exception(typeof(T).Name + ":NoChoice had been choose"); }