| Register | FAQ | Calendar | Search | Today's Posts | Mark Forums Read |
|
#1
| |||
| |||
| Should a class implementing an interface define the methods in the interface? That seems logical to me but I have the following code: public class XmlDataSourceMarc : XmlDataSource { protected DataSourceView tst; public override DataSourceView GetView(string viewName) { return tst; } } This gives the error: 'XmlDataSourceMarc.GetView(string)': no suitable method found to override Now if I look at the base class, it's true GetView is not defined in the class public class XmlDataSource : HierarchicalDataSourceControl, IDataSource, IListSource { public XmlDataSource(); public virtual int CacheDuration { get; set; } public virtual DataSourceCacheExpiry CacheExpirationPolicy { get; set; } public virtual string CacheKeyDependency { get; set; } public virtual string Data { get; set; } public virtual string DataFile { get; set; } public virtual bool EnableCaching { get; set; } public virtual string Transform { get; set; } public virtual XsltArgumentList TransformArgumentList { get; set; } public virtual string TransformFile { get; set; } public virtual string XPath { get; set; } public event EventHandler Transforming; protected override HierarchicalDataSourceView GetHierarchicalView(string viewPath); public XmlDocument GetXmlDocument(); protected virtual void OnTransforming(EventArgs e); public void Save(); } But the IDataSource interface it should implement has. public interface IDataSource { event EventHandler DataSourceChanged; DataSourceView GetView(string viewName); ICollection GetViewNames(); } So what am I missing? Why XmlDataSource does not have an implementation of DataSourceView GetView(string viewName) while it implements the interface IDataSource that defines it? Marc Wentink |
|
#2
| |||
| |||
| Marc brought next idea : > Should a class implementing an interface define the methods in the interface? > That seems logical to me but I have the following code: > > public class XmlDataSourceMarc : XmlDataSource > { > protected DataSourceView tst; > public override DataSourceView GetView(string viewName) > { > return tst; > } > } > > This gives the error: 'XmlDataSourceMarc.GetView(string)': no suitable > method found to override > > > Now if I look at the base class, it's true GetView is not defined in the > class > > public class XmlDataSource : HierarchicalDataSourceControl, IDataSource, > IListSource > { > public XmlDataSource(); > public virtual int CacheDuration { get; set; } > public virtual DataSourceCacheExpiry CacheExpirationPolicy { get; > set; } > public virtual string CacheKeyDependency { get; set; } > public virtual string Data { get; set; } > public virtual string DataFile { get; set; } > public virtual bool EnableCaching { get; set; } > public virtual string Transform { get; set; } > public virtual XsltArgumentList TransformArgumentList { get; set; } > public virtual string TransformFile { get; set; } > public virtual string XPath { get; set; } > public event EventHandler Transforming; > protected override HierarchicalDataSourceView > GetHierarchicalView(string viewPath); > public XmlDocument GetXmlDocument(); > protected virtual void OnTransforming(EventArgs e); > public void Save(); > } > > But the IDataSource interface it should implement has. > > public interface IDataSource > { > event EventHandler DataSourceChanged; > DataSourceView GetView(string viewName); > ICollection GetViewNames(); > } > > So what am I missing? Why XmlDataSource does not have an implementation of > DataSourceView GetView(string viewName) while it implements the interface > IDataSource that defines it? > > Marc Wentink The method does exist but is defined as "explicit interface implementation". If you cast the XmlDataSource to IDataSource, then you can use the GetView method. Hans Kesting |
|
#3
| |||
| |||
| If I look at XmlDataSource with Reflector, it does have an implementation of GetView. "Marc" <m.wentink5@removethischello.nl> wrote in message news:%23tweqIFCJHA.4884@TK2MSFTNGP02.phx.gbl... > Should a class implementing an interface define the methods in the > interface? > That seems logical to me but I have the following code: > > public class XmlDataSourceMarc : XmlDataSource > { > protected DataSourceView tst; > public override DataSourceView GetView(string viewName) > { > return tst; > } > } > > This gives the error: 'XmlDataSourceMarc.GetView(string)': no suitable > method found to override > > > Now if I look at the base class, it's true GetView is not defined in the > class > > public class XmlDataSource : HierarchicalDataSourceControl, > IDataSource, IListSource > { > public XmlDataSource(); > public virtual int CacheDuration { get; set; } > public virtual DataSourceCacheExpiry CacheExpirationPolicy { get; > set; } > public virtual string CacheKeyDependency { get; set; } > public virtual string Data { get; set; } > public virtual string DataFile { get; set; } > public virtual bool EnableCaching { get; set; } > public virtual string Transform { get; set; } > public virtual XsltArgumentList TransformArgumentList { get; set; } > public virtual string TransformFile { get; set; } > public virtual string XPath { get; set; } > public event EventHandler Transforming; > protected override HierarchicalDataSourceView > GetHierarchicalView(string viewPath); > public XmlDocument GetXmlDocument(); > protected virtual void OnTransforming(EventArgs e); > public void Save(); > } > > But the IDataSource interface it should implement has. > > public interface IDataSource > { > event EventHandler DataSourceChanged; > DataSourceView GetView(string viewName); > ICollection GetViewNames(); > } > > So what am I missing? Why XmlDataSource does not have an implementation of > DataSourceView GetView(string viewName) while it implements the interface > IDataSource that defines it? > > Marc Wentink > > |
|
#4
| |||
| |||
| "Hans Kesting" <news.hansdk@spamgourmet.com> wrote > The method does exist but is defined as "explicit interface > implementation". Aha. I will do some reading on that! Thanks. |
|
#5
| |||
| |||
| "Hans Kesting" <news.hansdk@spamgourmet.com> wrote > The method does exist but is defined as "explicit interface > implementation". If you cast the XmlDataSource to IDataSource, then you > can use the GetView method. But let us say I do not want to use the GetView method, as a method of a instantated variable of type XmlDataSource , but I want to define a new subclass of XmlDataSource that overrides the GetView method? How do I do that? public class XmlDataSourceMarc : XmlDataSource /* fails */ /* HierarchicalDataSourceControl fails */ /* DataSourceControl works */ { DataSourceView myView; protected override DataSourceView GetView(string viewName) { return myView; } } |
|
#6
| |||
| |||
| On Wed, 27 Aug 2008 09:18:39 -0700, Marc <m.wentink5@removethischello.nl> wrote: > "Hans Kesting" <news.hansdk@spamgourmet.com> wrote > > >> The method does exist but is defined as "explicit interface >> implementation". If you cast the XmlDataSource to IDataSource, then you >> can use the GetView method. > > But let us say I do not want to use the GetView method, as a method of a > instantated variable of type XmlDataSource , but I want to define a new > subclass of XmlDataSource that overrides the GetView method? How do I do > that? You need to declare your sub-class as also implementing the interface, and then explicitly implement your override: public class XmlDataSourceMarc : XmlDataSource, IDataSource { protected DataSourceView tst; public DataSourceView IDataSource.GetView(string viewName) { return tst; } } Pete |
|
#7
| |||
| |||
| "Peter Duniho" <NpOeStPeAdM@nnowslpianmk.com> wrote > You need to declare your sub-class as also implementing the interface, and > then explicitly implement your override: > > public class XmlDataSourceMarc : XmlDataSource, IDataSource > { > protected DataSourceView tst; > public DataSourceView IDataSource.GetView(string viewName) > { > return tst; > } > } Ok, now I am reallly starting to feel stupid but I got this and it still gives an error. using System; using System.Data; using System.Configuration; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; public class XmlDataSourceMarc : XmlDataSource, IDataSource { DataSourceView myView; public override DataSourceView GetView(string viewName) { return myView; } } Error 1 'XmlDataSourceMarc.GetView(string)': no suitable method found to override E:\user\m.wentink\My Documents\Visual Studio 2008\H4SPXML1\App_Code\XmlDataSourceMarc.cs 16 36 E:\...\H4SPXML1\ I tried to change public in protected but that's not it either. And here some link with information about GetView http://msdn.microsoft.com/en-us/libr...ew(VS.85).aspx |
|
#8
| |||
| |||
| Marc brought next idea : > "Peter Duniho" <NpOeStPeAdM@nnowslpianmk.com> wrote > >> You need to declare your sub-class as also implementing the interface, and >> then explicitly implement your override: >> >> public class XmlDataSourceMarc : XmlDataSource, IDataSource >> { >> protected DataSourceView tst; >> public DataSourceView IDataSource.GetView(string viewName) >> { >> return tst; >> } >> } > > > Ok, now I am reallly starting to feel stupid but I got this and it still > gives an error. > > using System; > using System.Data; > using System.Configuration; > using System.Linq; > using System.Web; > using System.Web.Security; > using System.Web.UI; > using System.Web.UI.WebControls; > > public class XmlDataSourceMarc : XmlDataSource, IDataSource > { > DataSourceView myView; > public override DataSourceView GetView(string viewName) > { > return myView; > } > } > > Error 1 'XmlDataSourceMarc.GetView(string)': no suitable method found to > override E:\user\m.wentink\My Documents\Visual Studio > 2008\H4SPXML1\App_Code\XmlDataSourceMarc.cs 16 36 E:\...\H4SPXML1\ > > I tried to change public in protected but that's not it either. > > And here some link with information about GetView > > http://msdn.microsoft.com/en-us/libr...ew(VS.85).aspx You missed something on the methodname: it's "IDataSource.GetView" (note the extra "IDataSource" that signals this is an explicit interface implementation. Hans Kesting |
|
#9
| |||
| |||
| "Hans Kesting" <news.hansdk@spamgourmet.com> wrote > You missed something on the methodname: it's "IDataSource.GetView" (note > the extra "IDataSource" that signals this is an explicit interface > implementation. public class XmlDataSourceMarc : XmlDataSource, IDataSource { DataSourceView myView; DataSourceView IDataSource.GetView(string viewName) { return myView; } } Ok this works and I will do some study on interface semantics, and write some C# code on it. But thanks for the help on my probably newbee questions. |
![]() |
| Thread Tools | |
| Display Modes | |
In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.