how does c# know that there are indexers an an IL assembly ?

  • Thread starter Thread starter bonk
  • Start date Start date
B

bonk

Hello,

IL does not have indexers. Infact the c# compiler compiles indexers to
Set_Item and Get_Item (or whatever name I choose via the
IndexerNameAttribute ).
So how does c# (compiler) know that something in a IL Assembly is supposed
to be an indexer ?
And more important, what ways do I have to influence that ?
 
bonk,

I believe that the compiler first looks for the property with the
IndexerNameAttribute. Failing that, I think it will then look for a
property which has the name "Item" (I am pretty shaky on this, but it's the
most prominent thought in my mind right now on the subject).

Hope this helps.
 
Well, that sounds somhow strange to me. Also there is a
PropertyInfo.GetIndexParameters Method.


Nicholas Paldino said:
bonk,

I believe that the compiler first looks for the property with the
IndexerNameAttribute. Failing that, I think it will then look for a
property which has the name "Item" (I am pretty shaky on this, but it's
the most prominent thought in my mind right now on the subject).

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

bonk said:
Hello,

IL does not have indexers. Infact the c# compiler compiles indexers to
Set_Item and Get_Item (or whatever name I choose via the
IndexerNameAttribute ).
So how does c# (compiler) know that something in a IL Assembly is
supposed to be an indexer ?
And more important, what ways do I have to influence that ?
 
bonk,

Why would it be strange? And the GetIndexParameters method is only
going to return the parameters for the property if it is an indexer.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

bonk said:
Well, that sounds somhow strange to me. Also there is a
PropertyInfo.GetIndexParameters Method.


Nicholas Paldino said:
bonk,

I believe that the compiler first looks for the property with the
IndexerNameAttribute. Failing that, I think it will then look for a
property which has the name "Item" (I am pretty shaky on this, but it's
the most prominent thought in my mind right now on the subject).

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

bonk said:
Hello,

IL does not have indexers. Infact the c# compiler compiles indexers to
Set_Item and Get_Item (or whatever name I choose via the
IndexerNameAttribute ).
So how does c# (compiler) know that something in a IL Assembly is
supposed to be an indexer ?
And more important, what ways do I have to influence that ?
 
Could it be possible that information about indexers are stored somwhere in
the metadata ?

Nicholas Paldino said:
bonk,

Why would it be strange? And the GetIndexParameters method is only
going to return the parameters for the property if it is an indexer.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

bonk said:
Well, that sounds somhow strange to me. Also there is a
PropertyInfo.GetIndexParameters Method.


Nicholas Paldino said:
bonk,

I believe that the compiler first looks for the property with the
IndexerNameAttribute. Failing that, I think it will then look for a
property which has the name "Item" (I am pretty shaky on this, but it's
the most prominent thought in my mind right now on the subject).

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Hello,

IL does not have indexers. Infact the c# compiler compiles indexers to
Set_Item and Get_Item (or whatever name I choose via the
IndexerNameAttribute ).
So how does c# (compiler) know that something in a IL Assembly is
supposed to be an indexer ?
And more important, what ways do I have to influence that ?
 
Back
Top