We've removed the IndexableAttribute from the i4o library and replaced it with the IndexSpecification<T>. Below I'll explain how you can add/remove/change the index for an IndexableCollection<T>.
Let's show several examples on how to create an IndexableCollection<T>.
Given any enumeration of objects you can translate into an IndexableCollection<T>. For the examples below we're going to use an enumeration of the System.IO.FileInfo class. We are going to index the list of FileInfos by file Extension and weather the file IsReadOnly or not.
Setup the list:
// Get our thing to index
string dir = @"C:\Windows\System32\";
var fileInfosFromDir = (from f in System.IO.Directory.GetFiles(dir, "*.*", SearchOption.AllDirectories)
select new FileInfo(f)).ToList();
Can create the IndexSpecification...
...for the FileInfo's "Extension" and "IsReadOnly" properties and turn the list of FileInfos into an IndexableCollection using the IndexSpecification.// Create the index specification
var spec = new IndexSpecification<FileInfo>()
.Add(i => i.Extension)
.Add(i => i.IsReadOnly);
// Turn the list of files into an Indexed collection of files
var indexedFileInfosFromDir = fileInfosFromDir.ToIndexableCollection(spec);
Create IndexableCollection<T> without IndexSpecification<T>:
You are not required to specify and IndexSpecification<T> when creating the IndexableCollection<T>. You can translate the list into an IndexableCollection<T> and add properties to index after the fact. EX:
var indexedFileInfosFromDir = fileInfosFromDir.ToIndexableCollection();
// Specify the properties to index dynamically (more late bound)
indexedFileInfosFromDir
.CreateIndexFor(i => i.Extension)
.CreateIndexFor(i => i.IsReadOnly);
Swap one IndexSpecification<T> for another:
If you want to completely swap out the index at run time, you can give the IndexableCollection a new IndexSpecification
var list = new List<FileInfo>();
var indexedList = list.ToIndexableCollection();
indexedList.UseIndexSpecification(
new IndexSpecification<FileInfo>()
.Add(o => o.Directory)
.Add(o => o.Name));
I think that should cover most of the general cases. Hope this helps...
