Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Any #341

Merged
merged 2 commits into from
Jul 1, 2024
Merged

Any #341

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,46 +22,48 @@ void ISourceGenerator.Execute(GeneratorExecutionContext context)
if(File.Exists(debugFilePath)){ File.Delete(debugFilePath); }
HEFileLogger logger = new HEFileLogger(debugFilePath);
HEProxy.ShowMessage = async msg => {
await logger.WriteUtf8FileAsync(msg + Environment.NewLine);
await logger.WriteUtf8FileAsync(msg);
};";
var syntaxTrees = context.Compilation.SyntaxTrees;
var fileList = syntaxTrees.Select(item => item.FilePath).ToList();
var classNodes = syntaxTrees
.SelectMany(t => t.GetRoot().DescendantNodes())
.OfType<ClassDeclarationSyntax>().ToList();
// 检查是否有继承自 System.Windows.Forms.Form 的类
var hasWinFormFormClass = classNodes
.Any(c => c.BaseList != null && c.BaseList.Types.Any(t => t.Type.ToString() == "Form"));

if (hasWinFormFormClass && fileList.Any(item=>item.EndsWith(".Designer.cs")))
if (classNodes != null && classNodes.Count>0)
{
// 这里可以根据判断结果执行相应的操作
// 例如生成特定的代码或输出信息
coreScript = $@"
// 检查是否有继承自 System.Windows.Forms.Form 的类
var hasWinFormFormClass = classNodes
.Any(c => c.BaseList != null && c.BaseList.Types.Any(t => t.Type.ToString() == "Form"));

if (hasWinFormFormClass && fileList.Any(item => item.EndsWith(".Designer.cs")))
{
// 这里可以根据判断结果执行相应的操作
// 例如生成特定的代码或输出信息
coreScript = $@"
{winformAndwpfLoggerScript}
HEProxy.SetProjectKind(HEProjectKind.Winform);
HEProxy.NatashaExtGlobalUsing.Add(""System.Windows.Controls"");
HEProxy.NatashaExtGlobalUsing.Add(""System.Windows"");
HEProxy.ExcludeGlobalUsing(""System.Windows.Controls"");
HEProxy.ExcludeGlobalUsing(""System.Windows"");
DelegateHelper<System.Windows.Forms.FormCollection, System.Windows.Forms.Form>.GetDelegate(""Remove"", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
";
}
else
{
}
else
{

var hasWPFWindowClass = classNodes
.Any(c => c.BaseList != null && c.BaseList.Types.Any(t => t.Type.ToString() == "Window"));
var hasWPFWindowClass = classNodes
.Any(c => c.BaseList != null && c.BaseList.Types.Any(t => t.Type.ToString() == "Window"));

if (hasWPFWindowClass && fileList.Any(item => item.EndsWith(".xaml.cs")))
{
coreScript = $@"
if (hasWPFWindowClass && fileList.Any(item => item.EndsWith(".xaml.cs")))
{
coreScript = $@"
{winformAndwpfLoggerScript}
HEProxy.SetProjectKind(HEProjectKind.WPF);
HEProxy.NatashaExtGlobalUsing.Add(""System.Windows.Forms"");
HEProxy.ExcludeGlobalUsing(""System.Windows.Forms"");
";
}
}
}


var nameSapce = context.Compilation.GetEntryPoint(cancellationToken: new System.Threading.CancellationToken())!.ContainingNamespace.Name;
string proxyMethodContent = $@"
//#if DEBUG
Expand All @@ -83,7 +85,7 @@ internal static void PreMain()
{coreScript}
HEProxy.SetCompileInitAction(()=>{{
NatashaManagement.RegistDomainCreator<NatashaDomainCreator>();
NatashaManagement.Preheating((asmName, @namespace) => !string.IsNullOrWhiteSpace(@namespace) && (@namespace.StartsWith(""Microsoft.VisualBasic"")|| HEProxy.NatashaExtGlobalUsing.Contains(@namespace)),true, true);
NatashaManagement.Preheating((asmName, @namespace) => !string.IsNullOrWhiteSpace(@namespace) && (@namespace.StartsWith(""Microsoft.VisualBasic"")|| HEProxy.IsExcluded(@namespace)),true, true);

}});
HEProxy.Run();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ public static void AsyncToHotExecutor(this IAsyncDisposable obj)
{
HEProxy.NeedBeDisposedObject(obj);
}
public static void AsyncInHotExecutor(this IEnumerable<IAsyncDisposable> objs)
public static void AsyncToHotExecutor(this IEnumerable<IAsyncDisposable> objs)
{
HEProxy.NeedBeDisposedObject(objs);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,15 @@ public static void SetArgumentsMethodName(string methodName)
{
_argumentsMethodName = methodName;
}

public static void ExcludeGlobalUsing(string usingCode)
{
NatashaExtGlobalUsing.Add(usingCode);
}
public static bool IsExcluded(string usingCode)
{
return NatashaExtGlobalUsing.Contains(usingCode);
}
#endregion
}

Loading