LeMP.MacroProcessor.GetMacros C# (CSharp) Method

GetMacros() static private method

static private GetMacros ( Type type, Symbol @namespace, IMessageSink sink, object instance = null ) : IEnumerable
type System.Type
@namespace Symbol
sink IMessageSink
instance object
return IEnumerable
		internal static IEnumerable<MacroInfo> GetMacros(Type type, Symbol @namespace, IMessageSink sink, object instance = null)
		{
			var flags = BindingFlags.Public | BindingFlags.Static;
			if (instance != null)
				flags |= BindingFlags.Instance;
			foreach(var method in type.GetMethods(flags)) {
				foreach (LexicalMacroAttribute attr in method.GetCustomAttributes(typeof(LexicalMacroAttribute), false)) {
					var @delegate = AsDelegate(method, sink, instance);
					if (@delegate != null)
						yield return new MacroInfo(@namespace, attr, @delegate);
				}
			}
		}
		static LexicalMacro AsDelegate(MethodInfo method, IMessageSink sink, object instance)

Usage Example

Exemplo n.º 1
0
 public MacroProcessorTask(MacroProcessor parent)
 {
     _parent = parent;
     _macros = parent.Macros.Clone();
     foreach (var mi in MacroProcessor.GetMacros(this.GetType(), null, _sink, this))
     {
         MacroProcessor.AddMacro(_macros, mi);
     }
     _macroNamespaces = new MSet <Symbol>(_macros.SelectMany(ms => ms.Value).Select(mi => mi.NamespaceSym).Where(ns => ns != null));
 }