2
0
mirror of https://github.com/esiur/esiur-dotnet.git synced 2025-06-27 05:23:13 +00:00

Blazor support

This commit is contained in:
2022-08-30 22:28:19 +03:00
parent 4cc0657869
commit 216b891bf8
12 changed files with 282 additions and 187 deletions

View File

@ -43,7 +43,7 @@ public class ResourceGenerator : ISourceGenerator
{
if (tmp.Type == TemplateType.Resource)
{
var source = TemplateGenerator.GenerateClass(tmp, templates);
var source = TemplateGenerator.GenerateClass(tmp, templates, false);
// File.WriteAllText($@"C:\gen\{tmp.ClassName}.cs", source);
context.AddSource(tmp.ClassName + ".Generated.cs", source);
}
@ -100,7 +100,6 @@ public class ResourceGenerator : ISourceGenerator
continue;
//File.WriteAllLines("C:\\gen\\ref.log", context.Compilation.ReferencedAssemblyNames.Select(x => x.ToString()));
if (cache.Contains(path))
{
@ -131,7 +130,6 @@ public class ResourceGenerator : ISourceGenerator
catch (Exception ex)
{
ReportError(context, ex.Source, ex.Message, "Esiur");
//System.IO.File.AppendAllText("c:\\gen\\error.log", ex.ToString() + "\r\n");
}
//inProgress.Remove(path);

View File

@ -170,7 +170,7 @@ public static class TemplateGenerator
return (representationType.Nullable) ? name + "?" : name;
}
public static string GetTemplate(string url, string dir = null, string username = null, string password = null)
public static string GetTemplate(string url, string dir = null, string username = null, string password = null, bool asyncSetters = false)
{
try
{
@ -209,7 +209,7 @@ public static class TemplateGenerator
{
if (tmp.Type == TemplateType.Resource)
{
var source = GenerateClass(tmp, templates);
var source = GenerateClass(tmp, templates, asyncSetters);
File.WriteAllText(tempDir.FullName + Path.DirectorySeparatorChar + tmp.ClassName + ".Generated.cs", source);
}
else if (tmp.Type == TemplateType.Record)
@ -253,7 +253,7 @@ public static class TemplateGenerator
}
}
internal static string GenerateClass(TypeTemplate template, TypeTemplate[] templates)
internal static string GenerateClass(TypeTemplate template, TypeTemplate[] templates, bool asyncSetters)
{
var cls = template.ClassName.Split('.');
@ -353,7 +353,10 @@ public static class TemplateGenerator
var ptTypeName = GetTypeName(p.ValueType, templates);
rt.AppendLine($"[Public] public {ptTypeName} {p.Name} {{");
rt.AppendLine($"get => ({ptTypeName})properties[{p.Index}];");
rt.AppendLine($"set => _SetSync({p.Index}, value);");
if (asyncSetters)
rt.AppendLine($"set => _Set({p.Index}, value);");
else
rt.AppendLine($"set => _SetSync({p.Index}, value);");
rt.AppendLine("}");
}