private IEnumerable <(string typeName, string attributeCreator)> CollectAttributedTypes( ICompilingContext context) { var collected = from type in context.Assembly.GetTypes() let attribute = (CompileAttribute)type.Attributes.FirstOrDefault(a => a.Match(_attributeType)) where attribute != null select(type, attribute); foreach (var(type, attribute) in collected) { if (attribute.GetValues().Union(attribute.GetProperties().Select(x => x.value)) .Any(x => x.Contains("typeof"))) { RequireNamespaces(type.UsingNamespaceList.Union(new[] { type.Namespace })); } yield return(type.FullName, ToCreator(attribute)); } }
public CompileCodeSnippetBuilder(ICompilingContext context) { _context = context ?? throw new ArgumentNullException(nameof(context)); }
/// <summary> /// 执行占位符对 <see cref="Placeholder"/> 中外部方法(extern)的调用,得到代码片段字符串。 /// </summary> /// <param name="placeholderInfo">包含表达式树中解析出来的占位符信息。</param> /// <param name="context">编译期代码执行所需的上下文信息。</param> /// <returns>占位符中的编译期代码执行后得到的代码片段字符串。</returns> internal static string Execute(this PlaceholderVisitor.PlaceholderInfo placeholderInfo, ICompilingContext context) { var lambda = placeholderInfo.Compile(); var codeSnippet = lambda(context); codeSnippet = placeholderInfo.Wrap(codeSnippet); return(codeSnippet); }