Click here to Skip to main content
15,891,951 members

Can't port C# code to managed C++ implementing IDataErrorInfo

3umphant asked:

Open original thread
This part. Commented code is cs.
On compile catch an error:
Error 78 error C3766: 'Sample::NoteInfo' must provide an implementation for the interface method 'System::String ^System::ComponentModel::IDataErrorInfo::default::get(System::String ^)' d:\dev\docstreet\sample\pointInfoStoreClass.h 100

What's incorrect? Why VS compiler consider this not implemented?
C++
#pragma region IDataErrorInfo Members

        //Returns an error description set for the item's property
        //String^ IDataErrorInfo.this[String^ columnName] {
        //  get {
        //      return GetColumnError(columnName);
        //  }
        //}

        public: property String^ IDataErrorInfo[String^] {
            virtual String^ get(String^ index) override {
                return GetColumnError(index);
            }
        }

Full code:
C++
public ref class NoteInfo : IDataErrorInfo {
        int fDay;
        int fMonth;
        int fYear;
        int fNoteID;
        //References the item's owner
        ProjectNotes^ owner;
        //Stores error descriptions for the Day, Month, Year and NoteID properties
        Hashtable^ propertyErrors;
        //Stores an error description for the item
        String^ fNoteError;


    public: NoteInfo(int noteID, int day, int month, int year) {
            fNoteID = noteID;
            fDay = day;
            fMonth = month;
            fYear = year;
            //Set errors to empty strings
            propertyErrors = gcnew Hashtable();
            propertyErrors->Add("Day", "");
            propertyErrors->Add("Month", "");
            propertyErrors->Add("Year", "");
            propertyErrors->Add("NoteID", "");
            fNoteError = "";
            Owner = nullptr;
        }

    public: property int NoteID {
            int get() { return fNoteID; }
            void set(int value) {
                if(fNoteID == value) return;
                fNoteID = value;
            }
        }

    public: void ClearErrors() {
            SetColumnError("Day", "");
            SetColumnError("Month", "");
            SetColumnError("Year", "");
            fNoteError = "";
        }

        //Sets an error for an item's property
    public: void SetColumnError(String^ elem, String^ error) {
            if(propertyErrors->ContainsKey(elem)) {
                if((String^)propertyErrors[elem] == error) return;
                propertyErrors[elem] = error;
            }
        }

        //Gets an error for an item's property
    public: String^ GetColumnError(String^ elem) {
            if(propertyErrors->ContainsKey(elem))
                return (String^)propertyErrors[elem];
            else
                return "";
        }

        //The owner collection
    internal: property ProjectNotes^ Owner {
            ProjectNotes^ get() { return owner; }
            void set(ProjectNotes^ value) { owner = value; }
        }


#pragma region IDataErrorInfo Members

        //Returns an error description set for the item's property
        //String^ IDataErrorInfo.this[String^ columnName] {
        //  get {
        //      return GetColumnError(columnName);
        //  }
        //}

        public: property String^ IDataErrorInfo[String^] {
            virtual String^ get(String^ index) override {
                return GetColumnError(index);
            }
        }

        //Returns an error description set for the current item
    public: property String^ Error {
            virtual String^ get() { return fNoteError; }

        }
#pragma endregion
    };
Tags: C++, .NET, Managed

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900