2
0
mirror of https://github.com/esiur/esiur-dotnet.git synced 2025-06-27 13:33:13 +00:00
This commit is contained in:
2022-03-09 21:55:30 +03:00
parent 530df018ec
commit 9a174f406f
106 changed files with 5166 additions and 4398 deletions

View File

@ -74,6 +74,15 @@ public class ResourceGenerator : ISourceGenerator
static string SuggestPropertyName(string propertyName)
{
if (Char.IsUpper(propertyName[0]))
return propertyName.Substring(0, 1).ToLower() + propertyName.Substring(1);
else
return propertyName.Substring(0, 1).ToUpper() + propertyName.Substring(1);
}
public void Execute(GeneratorExecutionContext context)
{
@ -146,27 +155,30 @@ namespace { ci.ClassSymbol.ContainingNamespace.ToDisplayString() } {{
";
if (ci.HasInterface)
code += $"public partial class {ci.Name} {{";
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 void Destroy() {{ OnDestroy?.Invoke(this); }}
code +=
@$" public partial class {ci.Name} : IResource {{
public Instance Instance {{ get; set; }}
public event DestroyedEvent OnDestroy;
public virtual void Destroy() {{ OnDestroy?.Invoke(this); }}
";
if (!ci.HasTrigger)
code += "public AsyncReply<bool> Trigger(ResourceTrigger trigger) => new AsyncReply<bool>(true);\r\n";
code +=
" public AsyncReply<bool> Trigger(ResourceTrigger trigger) => new AsyncReply<bool>(true);\r\n";
}
//Debugger.Launch();
foreach (var f in ci.Fields)
{
var givenName = f.GetAttributes().Where(x => x.AttributeClass.Name == "PublicAttribute").FirstOrDefault()?.ConstructorArguments.FirstOrDefault().Value;
var givenName = f.GetAttributes().Where(x => x.AttributeClass.Name == "PublicAttribute").FirstOrDefault()?.ConstructorArguments.FirstOrDefault().Value as string;
var fn = f.Name;
var pn = givenName ?? fn.Substring(0, 1).ToUpper() + fn.Substring(1);
var pn =string.IsNullOrEmpty(givenName) ? SuggestPropertyName(fn): givenName;
//System.IO.File.AppendAllText("c:\\gen\\fields.txt", fn + " -> " + pn + "\r\n");