/// <summary> /// Tries to create an instance of a chunk type that has specified ID. /// </summary> /// <param name="chunkId">ID of the chunk that need to be created.</param> /// <param name="chunksTypes">Collection of the chunks types to search for the one with /// <paramref name="chunkId"/> ID.</param> /// <returns>An instance of the chunk type with the specified ID or null if <paramref name="chunksTypes"/> /// doesn't contain chunk type with it.</returns> private static MidiChunk TryCreateChunk(string chunkId, ChunkTypesCollection chunksTypes) { Type type = null; return(chunksTypes?.TryGetType(chunkId, out type) == true && IsChunkType(type) ? (MidiChunk)Activator.CreateInstance(type) : null); }