using System;
using System.Linq;
public class Mecanismo: IDisposable
{
public void Dispose()
{
}
}
public class Test
{
public static void Main()
{
Mecanismo mecanismo = new Mecanismo();
Type mectype = mecanismo.GetType();
var c = mectype.GetInterface("System.IDisposable"); //forma direta
if (c != null)
{
System.Console.WriteLine("Sim");
}
if (mectype.GetInterfaces().Where(x => x.Name.Equals("IDisposable")).Any())
{
System.Console.WriteLine("Sim");
}
}
}
dXNpbmcgU3lzdGVtOwp1c2luZyBTeXN0ZW0uTGlucTsKCnB1YmxpYyBjbGFzcyBNZWNhbmlzbW86IElEaXNwb3NhYmxlCnsgICAgICAgIAogICBwdWJsaWMgdm9pZCBEaXNwb3NlKCkKICAgewogICAgICAKICAgfQp9CgpwdWJsaWMgY2xhc3MgVGVzdAp7CglwdWJsaWMgc3RhdGljIHZvaWQgTWFpbigpCgl7CgkJTWVjYW5pc21vIG1lY2FuaXNtbyA9IG5ldyBNZWNhbmlzbW8oKTsKICAgICAgICBUeXBlIG1lY3R5cGUgPSBtZWNhbmlzbW8uR2V0VHlwZSgpOwogICAgICAgIHZhciBjID0gbWVjdHlwZS5HZXRJbnRlcmZhY2UoIlN5c3RlbS5JRGlzcG9zYWJsZSIpOyAvL2Zvcm1hIGRpcmV0YQogICAgICAgIGlmIChjICE9IG51bGwpCiAgICAgICAgewogICAgICAgICAgICBTeXN0ZW0uQ29uc29sZS5Xcml0ZUxpbmUoIlNpbSIpOwogICAgICAgIH0KICAgICAgICBpZiAobWVjdHlwZS5HZXRJbnRlcmZhY2VzKCkuV2hlcmUoeCA9PiB4Lk5hbWUuRXF1YWxzKCJJRGlzcG9zYWJsZSIpKS5BbnkoKSkKICAgICAgICB7CiAgICAgICAgICAgIFN5c3RlbS5Db25zb2xlLldyaXRlTGluZSgiU2ltIik7CiAgICAgICAgfQoJfQp9