2
0
mirror of https://github.com/esiur/esiur-dotnet.git synced 2025-09-13 20:43:19 +00:00

MAUI Support

This commit is contained in:
2022-08-29 19:08:18 +03:00
parent 3b39c9bd28
commit 4cc0657869
17 changed files with 147 additions and 216 deletions

View File

@@ -154,21 +154,21 @@ using Esiur.Core;
namespace { ci.ClassSymbol.ContainingNamespace.ToDisplayString() } {{
";
if (ci.HasInterface)
if (ci.IsInterfaceImplemented(receiver.Classes))
code += $"public partial class {ci.Name} {{\r\n";
else
{
code +=
@$" public partial class {ci.Name} : IResource {{
public Instance Instance {{ get; set; }}
public event DestroyedEvent OnDestroy;
public virtual Instance Instance {{ get; set; }}
public virtual event DestroyedEvent OnDestroy;
public virtual void Destroy() {{ OnDestroy?.Invoke(this); }}
public virtual void Destroy() {{ OnDestroy?.Invoke(this); }}
";
if (!ci.HasTrigger)
code +=
" public AsyncReply<bool> Trigger(ResourceTrigger trigger) => new AsyncReply<bool>(true);\r\n";
code +=
"\tpublic virtual AsyncReply<bool> Trigger(ResourceTrigger trigger) => new AsyncReply<bool>(true);\r\n\r\n";
}
//Debugger.Launch();
@@ -183,8 +183,8 @@ namespace { ci.ClassSymbol.ContainingNamespace.ToDisplayString() } {{
//System.IO.File.AppendAllText("c:\\gen\\fields.txt", fn + " -> " + pn + "\r\n");
// copy attributes
var attrs = string.Join(" ", f.GetAttributes().Select(x => $"[{x.ToString()}]"));
code += $"{attrs} public {f.Type} {pn} {{ get => {fn}; set {{ {fn} = value; Instance?.Modified(); }} }}\r\n";
var attrs = string.Join("\r\n\t", f.GetAttributes().Select(x => $"[{x.ToString()}]"));
code += $"\t{attrs}\r\n\t public {f.Type} {pn} {{ \r\n\t\t get => {fn}; \r\n\t\t set {{ \r\n\t\t {fn} = value; \r\n\t\t Instance?.Modified(); \r\n\t\t}}\r\n\t}}\r\n";
}
code += "}}\r\n";

View File

@@ -16,4 +16,13 @@ public struct ResourceGeneratorClassInfo
public ClassDeclarationSyntax ClassDeclaration { get; set; }
public bool IsInterfaceImplemented(Dictionary<string, ResourceGeneratorClassInfo> classes)
{
if (HasInterface)
return true;
// Are we going to generate the interface for the parent ?
var fullName = ClassSymbol.BaseType.ContainingAssembly + "." + ClassSymbol.BaseType.Name;
return classes.ContainsKey(fullName);
}
}

View File

@@ -55,7 +55,7 @@ public class ResourceGeneratorReceiver : ISyntaxContextReceiver
//if (!Debugger.IsAttached)
//{
// if (cls.Name == "User")
// if (cls.Name == "MyChildResource")
// Debugger.Launch();
//}
@@ -68,11 +68,12 @@ public class ResourceGeneratorReceiver : ISyntaxContextReceiver
// Partial class check
if (Classes.ContainsKey(fullName))
{
// append fields
var c = Classes[fullName];
c.Fields.AddRange(fields);
if (!c.HasInterface)
c.HasInterface = cls.Interfaces.Any(x => x.ToDisplayString() == "Esiur.Resource.IResource");
c.HasInterface = cls.AllInterfaces.Any(x => x.ToDisplayString() == "Esiur.Resource.IResource");
if (!c.HasTrigger)
c.HasTrigger = hasTrigger;
}
@@ -84,9 +85,13 @@ public class ResourceGeneratorReceiver : ISyntaxContextReceiver
ClassDeclaration = cds,
ClassSymbol = cls,
Fields = fields.ToList(),
HasInterface = cls.Interfaces.Any(x => x.ToDisplayString() == "Esiur.Resource.IResource"),
HasInterface = cls.AllInterfaces.Any(x => x.ToDisplayString() == "Esiur.Resource.IResource"),
HasTrigger = hasTrigger
});
}

View File

@@ -344,6 +344,7 @@ public static class TemplateGenerator
rt.AppendLine("return rt; }");
}
foreach (var p in template.Properties)
{
if (p.Inherited)
@@ -352,7 +353,7 @@ 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 => _Set({p.Index}, value);");
rt.AppendLine($"set => _SetSync({p.Index}, value);");
rt.AppendLine("}");
}