I wrote some VB code that I converted to C # using the Sharp Develop IDE program. I defined an IElement interface that is implemented by objects that return the XML views themselves. Any object that implements this interface should be able to return its tag name and its representation of the XML string. To get an XML string, it may need to loop through a child / sub collection to get an XML representation of all its children.
Classes that inherit from Element can use GetXml and GetNestedXml of their base class or override it, but the GetNestedXml function should not be publicly available, since it will only be called from the public GetXml function of derived classes. Therefore, in the original version of VB, the scope of GetNestedXML was configured to protect. However, Sharp Develop and I have problems trying to convert this code to C #. See the error below.
On the side of the note, I understand that there may be better ways to implement this, and I will be interested in side offers that are easy to flame. :-) Thank you.
Public Interface IElement ReadOnly Property TagName() As String ReadOnly Property GetXml(Optional ByVal targetXml As Integer = TargetXmlEnum.All) As String Function GetNestedXml() As String End Interface Public Class Element Implements IElement Public ReadOnly Property TagName() As String Implements IElement.TagName Get '.... End Get End Property Public Overridable ReadOnly Property GetXml(Optional ByVal targetXml As Integer = TargetXmlEnum.All) _ As String Implements IElement.GetXml Get '.... End Get End Property Protected Overridable Function GetNestedXml() As String Implements IElement.GetNestedXml '.... End Function End Class
Converted C #:
public interface IElement { string TagName { get; } string GetXml { get; } string GetNestedXml(); } public class Element : IElement { public string TagName { get {
Mistake:
Error 1 'Smit.SpreadsheetML.Element' does not implement interface member 'Smit.SpreadsheetML.IElement.GetNestedXml()'. 'Smit.SpreadsheetML.Element.GetNestedXml()' cannot implement an interface member because it is not public. D:\Users\Chad\Desktop\SMIT\SMIT.SpreadsheetML.ConvertedToC
c #
Chadd
source share