Skip to content

Instantly share code, notes, and snippets.

@bamboo
Created May 27, 2011 14:03
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 bamboo/995311 to your computer and use it in GitHub Desktop.
Save bamboo/995311 to your computer and use it in GitHub Desktop.
Macro resolving a type argument
import Boo.Lang.Compiler
import Boo.Lang.Compiler.Ast
import Boo.Lang.Compiler.MetaProgramming // compile_
import Boo.Lang.Compiler.TypeSystem
import Boo.Lang.Compiler.TypeSystem.Services
import Boo.Lang.Environments
struct Vector3:
x as single
y as single
z as single
macro swizzle(typeExpression as Expression):
def ResolveType():
typeRef = TypeReference.Lift(typeExpression)
my(NameResolutionService).ResolveTypeReference(typeRef)
return typeRef.Entity cast IType
type = ResolveType()
for member in type.GetMembers():
print member
code = [|
namespace Test
swizzle Vector3:
pass
|]
result = compile_(code, typeof(Vector3).Assembly)
print result.Errors
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment