The other day I was looking through some code and I came accross
SqlDataReader.Dispose. In 1.x the Dispose method was and explicit interface
implementation and as such not visible on the SqlDataReader type. This has
changed in 2.0 and it is now visible. What is odd is that it is decorated
with the EditorBrowsable attribute with a Never setting.

We can see the method by looking at DbDataReader where it is defined.

.method public hidebysig newslot virtual final instance void Dispose() cil
managed
{
     .custom instance void
[System]System.ComponentModel.EditorBrowsableAttribute::.ctor([System]System.ComponentModel.EditorBrowsableState)
= ( int32(0x00000001) )
     .maxstack 2
     L_0000: ldarg.0
     L_0001: ldc.i4.1
     L_0002: callvirt instance void
System.Data.Common.DbDataReader::Dispose(bool)
     L_0007: ret
}


It is not overriden in SqlDataReader. According to the documentation on this
attribute
http://msdn2.microsoft.com/en-us/library/system.componentmodel.editorbrowsableattribute.aspx
VS
should not show the method in intellisense. I figured it must be that I had
disabled this feature so I went and tried the example there (it is very
important that the library not be in  your current solution for those who
want to try). The example worked as advertised so apparently it was not my
setup that was ignoring the attribute.

My next thought was that the SqlDataReader was re-implementing its
interfaces (figured that may cause the attribute to be ignored). I wrote up
the following to test that case.

---library assembly
   public class Class1 : IAge{
       int ageval;
       [EditorBrowsable(EditorBrowsableState.Never)]
       public int Age {
           get { return ageval; }
           set {
               if (!ageval.Equals(value)) {
                   ageval = value;
               }
           }
       }
   }
   public class Class2 : Class1, IAge {
   }
   public interface IAge {
       int Age {
           get;
       }
   }

--- main assembly
   class Program {
       static void Main(string[] args) {
           Class2 f = new Class1();
           //no f.age
       }
   }

I generally assume I am missing something and that things are not bugs so ..
what am I missing here?

Cheers,

Greg

===================================
This list is hosted by DevelopMentorĀ®  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

Reply via email to