Last active
December 13, 2015 23:08
-
-
Save ElemarJR/4989116 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| [Test] | |
| public void ExpressionsWithChildrenShouldOverrideVisitMethod() | |
| { | |
| var expressionTypes = typeof(IExpression) | |
| .Assembly.GetTypes() | |
| .Where(t => typeof(IExpression).IsAssignableFrom(t)) | |
| .Where(t => !t.IsInterface); | |
| var withChildren = expressionTypes | |
| .Where(t => t.GetFields(BindingFlags.Instance | | |
| BindingFlags.Static | | |
| BindingFlags.NonPublic | | |
| BindingFlags.Public) | |
| .Any(f => typeof(IExpression).IsAssignableFrom(f.FieldType))); | |
| var withChildrenAndNoVisitOverride = withChildren | |
| .Where(t => t.GetMethod("Visit").DeclaringType != t) | |
| .Select(t => t.Name) | |
| .ToArray() | |
| ; | |
| if (withChildrenAndNoVisitOverride.Length > 0) | |
| { | |
| string names = withChildrenAndNoVisitOverride.Length > 1 ? | |
| withChildrenAndNoVisitOverride.Aggregate((a, b) => string.Format("{0}, {1}", a, b)) : | |
| withChildrenAndNoVisitOverride.First(); | |
| Assert.Fail(string.Format("Expressions with children ({0}) should override the Visit method", | |
| names)); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment