Friday 19 March 2021

MVC - Simplest Extension Method example

 Watch this example on YouTube


 1. Model

   public interface IExtensionTest
    {
         void DoSomething();
    }
    public class ExtensionTest: IExtensionTest
    {
        public void DoSomething() { }
    }
    public static class SomethingElse {
        public static string ReturnSomething(this IExtensionTest t, string s)
        {
            return "returning: " + s;
        }
    }


2. Controller

        public ActionResult Index()
        {
            IExtensionTest e = new ExtensionTest();
            var res = e.ReturnSomething("bbbbb");
            return View();
        }

No comments:

Post a Comment