While implementing the IDictionaryEnumerator i saw that the explicit implementation differs considerably with the implicit implementation in terms of the coding
//At first the implicit one --- writing only one of the several properties:-
public object Value
{
get { throw new NotImplementedException(); }
}
//Now the explicit implementation
object IDictionaryEnumerator.Value
{
get { throw new NotImplementedException(); }
}
Q1 ) can you explain the 2nd coding (explicit implementation) with reference to the way we normally understand properties
Q2) what is IDictionaryEnumerator.Value
How does the interface IDictionaryEnumerator contain IDictionaryEnumerator.Value
Without IDictionaryEnumerator being created by far? Why is the dot operator there?
An explicit interface implementation includes the name of the interface (IDictionaryEnumerator in this case), that's what makes it explicit - the name of the interface is explicity mentioned.
Because the interface is implemented explicitly the access_specifier for the property is taken from the interface declaration and is not shown again in the implementation. There is no point, the property can only be accessed through a variable which is
typed to the interface and so the access-specifier is already known.
In the case of an implicitly implemented interface the implmentation may be used by variables that are not typed to the interface and so the access_specifier needs to be present as part of the implementation.
1)Are you worried about the throwing of the exception? That just means that no one has got around to writing the code yet. If you wish to use the interface that this class promises to implment then the getter will need to be written at some point.
Again, are you getting an error? What is the business problem you are trying to solve.
2) No, you cannot instantiate an interface. So what? An interface is a contract it is not an actual action. What problem are you seeing? What is your business requirement.
I have posted a opcode output which I was trying to follow
there is no business requirement as I was doing this for academic interest
-- there was this problem
that a class is complied at compile time
and the instantiation takes place at runtime --- or is it so?
but the fully qualified name for a property say a Value is represented as
get_Value in the opcode and there are so many things that are missing which theoritically is not possible in the way we program as it must implement a Complete interface
thus the question is such that I got into a problem to find out a fully qualified name specified forna property in the explicit implementation
and I took it this way that the IDictionaryEnumerator.Value name has an existing class / interface from which theValue is derived
-------------------- now from the above disccussion I followed that the
interface existed even before the implementation of the interface is taking place ---- is not it
I am not clear. Do you have a problem? I can't tell from your last post if you have a problem or what it might be.
Are you asking if compiling happens at compile time? Yes it does.
Are you asking if classes are instantiated at runtime? Yes they are, if someone wants them.
The fully qualified name for a property called Value is not get_Value. get_Value is an internal name that is generated by the compiler to implement the getter method of a property (properties are just one or two methods - getters and setters). As far as
I am aware the name get_Value is an implementation detail and is not part of the c# language eg, don't look at it, it could go away or change at any time.
I don't understand why you think that the names used when explicity defining an interface are some how related to names that the compiler generates for its own internal use.
An interface is a promise or a contract. That promise is stored in a file. If a class chooses to implement an interface it must obey the promise that the interface specifies. Does the interface exist before the implementation? I guess that depends on
the order in which you write the code, but the natural way would be to define what you are promising and then deliver the promise.
amigo 1
Member
60 Points
199 Posts
Property complexity
Jan 10, 2013 05:36 AM|LINK
I know what we mean by the word property
Normally it is defined as
< access_specifier> < return_type> < property_name> { get{// code set} set{//code set}}While implementing the IDictionaryEnumerator i saw that the explicit implementation differs considerably with the implicit implementation in terms of the coding
//At first the implicit one --- writing only one of the several properties:- public object Value { get { throw new NotImplementedException(); } } //Now the explicit implementation object IDictionaryEnumerator.Value { get { throw new NotImplementedException(); } }Q1 ) can you explain the 2nd coding (explicit implementation) with reference to the way we normally understand properties
Q2) what is IDictionaryEnumerator.Value
How does the interface IDictionaryEnumerator contain IDictionaryEnumerator.Value
Without IDictionaryEnumerator being created by far? Why is the dot operator there?
<div>
</div>
Paul Linton
Star
13421 Points
2535 Posts
Re: Property complexity
Jan 10, 2013 05:48 AM|LINK
An explicit interface implementation includes the name of the interface (IDictionaryEnumerator in this case), that's what makes it explicit - the name of the interface is explicity mentioned.
Because the interface is implemented explicitly the access_specifier for the property is taken from the interface declaration and is not shown again in the implementation. There is no point, the property can only be accessed through a variable which is typed to the interface and so the access-specifier is already known.
In the case of an implicitly implemented interface the implmentation may be used by variables that are not typed to the interface and so the access_specifier needs to be present as part of the implementation.
amigo 1
Member
60 Points
199 Posts
Re: Property complexity
Jan 10, 2013 06:06 AM|LINK
but about the dot operator if you throw some light
Paul Linton
Star
13421 Points
2535 Posts
Re: Property complexity
Jan 10, 2013 06:40 AM|LINK
I am not sure what your question is
An explicit interface member implementation is written using the fully qualified interface member name. See section 13.4 in the C# standard.
amigo 1
Member
60 Points
199 Posts
Re: Property complexity
Jan 10, 2013 06:46 AM|LINK
okay
But can they be brought into question without creating the object that impleements the class and the interface
Paul Linton
Star
13421 Points
2535 Posts
Re: Property complexity
Jan 10, 2013 06:50 AM|LINK
'brought into question' means 'cast doubt on', I don't think you are using the right expression.
Can you explain your question with some code? What business need are you trying to solve?
amigo 1
Member
60 Points
199 Posts
Re: Property complexity
Jan 10, 2013 07:05 AM|LINK
Actually what I mean is that the following expression is a part of the class as we define them
object IDictionaryEnumerator.Value { get { throw new NotImplementedException(); } }this means :
1) ----- the class is getting defined but not defined yet defined
2)------- the interface does not have any existence as it cannot be instantiated and carries no implementation at all.
then how come IDictionaryEnumerator.Value --- carry a meaning
Paul Linton
Star
13421 Points
2535 Posts
Re: Property complexity
Jan 10, 2013 07:14 AM|LINK
1)Are you worried about the throwing of the exception? That just means that no one has got around to writing the code yet. If you wish to use the interface that this class promises to implment then the getter will need to be written at some point.
Again, are you getting an error? What is the business problem you are trying to solve.
2) No, you cannot instantiate an interface. So what? An interface is a contract it is not an actual action. What problem are you seeing? What is your business requirement.
amigo 1
Member
60 Points
199 Posts
Re: Property complexity
Jan 10, 2013 07:32 AM|LINK
if we see this thread
http://forums.asp.net/t/1873068.aspx/1?interface+and+Ildasm
I have posted a opcode output which I was trying to follow
there is no business requirement as I was doing this for academic interest
-- there was this problem
that a class is complied at compile time
and the instantiation takes place at runtime --- or is it so?
but the fully qualified name for a property say a Value is represented as
get_Value in the opcode and there are so many things that are missing which theoritically is not possible in the way we program as it must implement a Complete interface
thus the question is such that I got into a problem to find out a fully qualified name specified forna property in the explicit implementation
and I took it this way that the IDictionaryEnumerator.Value name has an existing class / interface from which theValue is derived
-------------------- now from the above disccussion I followed that the
interface existed even before the implementation of the interface is taking place ---- is not it
Paul Linton
Star
13421 Points
2535 Posts
Re: Property complexity
Jan 10, 2013 08:08 AM|LINK
I am not clear. Do you have a problem? I can't tell from your last post if you have a problem or what it might be.
Are you asking if compiling happens at compile time? Yes it does.
Are you asking if classes are instantiated at runtime? Yes they are, if someone wants them.
The fully qualified name for a property called Value is not get_Value. get_Value is an internal name that is generated by the compiler to implement the getter method of a property (properties are just one or two methods - getters and setters). As far as I am aware the name get_Value is an implementation detail and is not part of the c# language eg, don't look at it, it could go away or change at any time.
I don't understand why you think that the names used when explicity defining an interface are some how related to names that the compiler generates for its own internal use.
An interface is a promise or a contract. That promise is stored in a file. If a class chooses to implement an interface it must obey the promise that the interface specifies. Does the interface exist before the implementation? I guess that depends on the order in which you write the code, but the natural way would be to define what you are promising and then deliver the promise.