public ReaderGroup(ReaderAttribute attribute, object reader, Type type) { version = attribute.version; readType = attribute.ReadType; this.reader = reader; this.type = type; }
public CompiledReaders(Assembly assembly) { foreach ((MethodInfo method, ReaderAttribute attribute) in from type in assembly.GetTypes() from method in type.GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static) let attribute = method.GetCustomAttribute <ReaderAttribute>() where attribute != null select(method, attribute)) { Type type = ReaderAttribute.CheckMethod(method); var compiledReaders = method.IsStatic ? staticReaders : instanceReaders; List <ReaderGroup> readerList = compiledReaders.TryGetValue(type); if (readerList == null) { readerList = new List <ReaderGroup>(); compiledReaders.Add(type, readerList); } //Find location int index = readerList.BinarySearch(attribute.version, GroupComparer.comparer); if (index < 0) { object reader = CreateReader(method); readerList.Insert(~index, new ReaderGroup(attribute, reader, type)); } else { throw ExceptionHelper.Invalid(nameof(method), method, InvalidType.foundDuplicate); } } //Finalize foreach (var pair in staticReaders) { pair.Value.TrimExcess(); } foreach (var pair in instanceReaders) { pair.Value.TrimExcess(); } }