Created
September 7, 2010 03:28
-
-
Save Diullei/567822 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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