Skip to content

Instantly share code, notes, and snippets.

@controlflow
Last active September 20, 2015 22:51
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 controlflow/cb6d3fb4e21adb743bb7 to your computer and use it in GitHub Desktop.
Save controlflow/cb6d3fb4e21adb743bb7 to your computer and use it in GitHub Desktop.
class Foo {
[ProvidesContext] IPredefinedType _predefinedTypes = ...;
void DoSomething(ITreeNode node) {
if (Check(node)) {
var expressionType = node.GetExpressionType();
if (expressionType.Equals(node.GetPredefinedType().Bool) {
// ^^^^^^^^^^^^^^^^^^^^^^^^
// Use aleady provided 'IPredefinedType' value from '_predefinedTypes' field
}
}
}
}
/*
Allow on fields/properties
Allow in parameters?
Check staticness of provided field/property
Allow on methods? var foo = Foo() can provide context for inner scope
Should it work recursively? We can check for [ProvidesContext] members of [ProvidesContext] type
What about subtyping? What about multiple equal types? Introduce context types traversing subtypes until common subtype?
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment