C#C
C#15mo ago
DrinkWater623

Null Warnings

I am making a class with 3 overloaded constructor, but I cannot bring myself to put the same code in 3 constructors, so I did it like this:
        public enum InsertMode
        {
            Append = 0,
            Truncate = 1,
            ReCreate = -1
        }
        public CsvFileInfo File { get; private set; } //init keyword - see if useful here
        public SqlTable Tb { get; private set; }
        public string ErrMsg { get; private set; }
        public InsertMode AppendMode { get; set; }     
   
        private void Initialize ( FileInfo fileInfo, SqlTable tableObj, InsertMode insertMode, bool throwExceptions )
        {
            ErrMsg = "";
            AppendMode = insertMode;
            File = new CsvFileInfo(fileInfo, 100);
            Tb = tableObj;

            if ( !InitialValidation() )
                if ( throwExceptions ) throw new Exception($"Error: {ErrMsg}");
                else return;

        }
        //============================================================================================                
        public Text2Sql ( FileInfo fileInfo, SqlTable tableObj, InsertMode insertMode, bool throwExceptions )
        {
            Initialize(fileInfo, tableObj, insertMode, throwExceptions);

        }
        public Text2Sql ( FileInfo fileInfo, SqlTable tableObj, bool throwExceptions )
        {
            Initialize(fileInfo, tableObj, InsertMode.Append, throwExceptions);
           
        }
        public Text2Sql ( FileInfo fileInfo, SqlTable tableObj ) => Initialize(fileInfo, tableObj, InsertMode.Append,true);
But I get CS8618 non-nullable property warnings. How do I get rid of the warnings? Or is there a better way?
Was this page helpful?