0

Hi guys!

I was wondering if there is a way to apply date when marking a method as obsolete? What I mean about a date is that this date represents the "date" when this function should be removed for good.

And a NooB question, is there a way to display error message in winform using MessageBox.show()?

Code:

`

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        [Obsolete("This class is obsolete; use class B instead")]
        class A
        {
            public void F() { }
        }
        class B
        {
            public void F() { }

        }



        private void button1_Click(object sender, EventArgs e)
        {
            A a = new A();       // Warning
            a.F();

        }

        private void button2_Click(object sender, EventArgs e)
        {
            B b = new B();
            b.F();
        }
    }
}

`

3
Contributors
2
Replies
14
Views
4 Years
Discussion Span
Last Post by ChrisHunter
0

Not that I'm aware of. You should note in the comment and in your documentation that the method is obsolete and will be removed after X date. After that date, simply remove the method from your libraries and documentation.

If you wish to retain true backwards compatibility, then retain the methods, mark them obsolete, but include a reference to the new method that should be used (which you should be doing anyway)

0

If by Error message you mean an exception then you can put a Try/Catch in you method like this:

private void myMethod()
{
    try
    {
        .....
    }
    catch (Exception ex)
    {
        MessageBox.show("" + ex);
    }
 }

As for the obsolete problem can you not add DateTime.Now.ToString() to the end of the obsolete message?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.