Some context would be helpful, but it sounds like you've got something like
class Foo<T> where T : Y {
object GetIndexer() { /* ... */ }
}
In that case, why not just
SomeCollection<Y> GetIndexer() { /* */ }
That way, no cast is required.
But I am a little confused by your use of the term 'indexer'. An indexer for a C# is a way of overloading the [] operator for a type, so that you can do things like:
MyCollectionType c = new MyCollectionType()
c["someValue"]
They are defined like so:
class MyCollectionType {
public string this [string index] // This particular indexer maps strings to strings, but we could use other types if we wished.
get {} // Defines what to do when people do myCollection["foo"]
set {} // Defines what to do when people do myCollection["foo"] = "bar"
}
An object of type SomeCollection<Y>
isn't an indexer, it's a collection.