понедельник, 4 ноября 2019 г.

GetInterface from type

https://www.geeksforgeeks.org/c-sharp-type-getinterface-method/

using System;
using System.Globalization;
using System.Reflection;
  
class GFG {
  
    // Main Method
    public static void Main()
    {
        // Declaring and intializing object of Type
        Type objType = typeof(int);
  
        // try-catch block for handling Exception
        try {
  
            // Getting interface of specified name
            // using GetField(String) Method
            Type minterface = objType.GetInterface("IFormattable");
  
            // Display the Result
            Console.WriteLine("interface is: {0}", minterface);
        }
  
        // catch ArgumentNullException here
        catch (ArgumentNullException e) 
        {
            Console.Write("name is null.");
            Console.Write("Exception Thrown: ");
            Console.Write("{0}", e.GetType(), e.Message);
        }
    }
}

using System;
using System.Globalization;
using System.Reflection;
  
class GFG {
  
    // Main Method
    public static void Main()
    {
        // Declaring and intializing object of Type
        Type objType = typeof(int);
  
        // try-catch block for handling Exception
        try {
  
            // Getting interface of specified name
            // using GetField(String) Method
            Type minterface = objType.GetInterface(null);
  
            // Display the Result
            Console.WriteLine("interface is: {0}", minterface);
        }
  
        // catch ArgumentNullException here
        catch (ArgumentNullException e) 
        {
            Console.WriteLine("name is null.");
            Console.Write("Exception Thrown: ");
            Console.Write("{0}", e.GetType(), e.Message);
        }
    }
}


using System;
using System.Globalization;
using System.Reflection;
  
class GFG {
  
    // Main Method
    public static void Main()
    {
        // Declaring and intializing object of Type
        Type objType = typeof(int);
  
        // try-catch block for handling Exception
        try {
  
            // Getting interface of specified name
            // using GetField(String) Method
            Type minterface = objType.GetInterface("iformattable", true);
  
            // Display the Result
            Console.WriteLine("interface is: {0}", minterface);
        }
  
        // catch ArgumentNullException here
        catch (ArgumentNullException e) {
            Console.WriteLine("name is null.");
            Console.Write("Exception Thrown: ");
            Console.Write("{0}", e.GetType(), e.Message);
        }
    }
}

using System;
using System.Globalization;
using System.Reflection;
  
class GFG {
  
    // Main Method
    public static void Main()
    {
        // Declaring and intializing object of Type
        Type objType = typeof(int);
  
        // try-catch block for handling Exception
        try {
  
            // Getting interface of specified name
            // using GetField(String) Method
            Type minterface = objType.GetInterface(null, true);
  
            // Display the Result
            Console.WriteLine("interface is: {0}", minterface);
        }
  
        // catch ArgumentNullException here
        catch (ArgumentNullException e) 
        {
            Console.WriteLine("name is null.");
            Console.Write("Exception Thrown: ");
            Console.Write("{0}", e.GetType(), e.Message);
        }
    }
}

Комментариев нет:

Отправить комментарий