Skip to content

Instantly share code, notes, and snippets.

@Diullei
Created September 7, 2010 03:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Diullei/567822 to your computer and use it in GitHub Desktop.
Save Diullei/567822 to your computer and use it in GitHub Desktop.
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace TestProject3
{
public interface IExecuteType<T>
{
bool IsExecuted { get; set; }
}
public class ClassA { }
public class ClassB { }
public class ClassC { }
public class MyImplClass : IExecuteType<ClassA>, IExecuteType<ClassB>, IExecuteType<ClassC>
{
// outras operações desta classe...
public void DoOperation()
{
((IExecuteType<ClassB>)this).IsExecuted = true;
}
//...
bool IExecuteType<ClassA>.IsExecuted { get; set; }
bool IExecuteType<ClassB>.IsExecuted { get; set; }
bool IExecuteType<ClassC>.IsExecuted { get; set; }
public bool IsExecutedToType(Type type)
{
return (bool)typeof(IExecuteType<>).MakeGenericType(new [] { type }).GetMethod("get_IsExecuted").Invoke(this, new object[] { });
}
}
[TestClass]
public class UnitTest1
{
[TestMethod]
public void TestMethod1()
{
var aClass = new MyImplClass();
aClass.DoOperation();
Assert.IsTrue(aClass.IsExecutedToType(typeof(ClassB)));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment