mirror of
https://github.com/esiur/esiur-dotnet.git
synced 2025-05-06 03:32:57 +00:00
a
This commit is contained in:
parent
62343d7761
commit
0207b037f3
@ -1,4 +1,4 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
|
@ -31,9 +31,11 @@ namespace Esiur.AspNetCore.Example
|
||||
[Resource]
|
||||
public partial class MyResource
|
||||
{
|
||||
[Export] int number;
|
||||
|
||||
[Annotation("sss","bb")][Export] int number;
|
||||
|
||||
[Export]
|
||||
|
||||
public string[] GetInfo() => new string[] { Environment.MachineName, Environment.UserName, Environment.CurrentDirectory,
|
||||
Environment.CommandLine, Environment.OSVersion.ToString(), Environment.ProcessPath };
|
||||
|
||||
|
@ -5,7 +5,7 @@
|
||||
<Copyright>Ahmed Kh. Zamil</Copyright>
|
||||
<PackageProjectUrl>http://www.esiur.com</PackageProjectUrl>
|
||||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
||||
<Version>2.4.7</Version>
|
||||
<Version>2.4.8</Version>
|
||||
<RepositoryUrl>https://github.com/esiur/esiur-dotnet</RepositoryUrl>
|
||||
<Authors>Ahmed Kh. Zamil</Authors>
|
||||
<AssemblyVersion></AssemblyVersion>
|
||||
|
13
Esiur/Properties/launchSettings.json
Normal file
13
Esiur/Properties/launchSettings.json
Normal file
@ -0,0 +1,13 @@
|
||||
{
|
||||
"profiles": {
|
||||
"Esiur": {
|
||||
"commandName": "Project"
|
||||
},
|
||||
"Profile 1": {
|
||||
"commandName": "Project"
|
||||
},
|
||||
"Profile 2": {
|
||||
"commandName": "Executable"
|
||||
}
|
||||
}
|
||||
}
|
@ -1,4 +1,5 @@
|
||||
using Microsoft.CodeAnalysis;
|
||||
using Microsoft.CodeAnalysis.CSharp;
|
||||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
using Microsoft.CodeAnalysis.Text;
|
||||
using System;
|
||||
@ -44,13 +45,11 @@ public class ResourceGenerator : ISourceGenerator
|
||||
if (tmp.Type == TemplateType.Resource)
|
||||
{
|
||||
var source = TemplateGenerator.GenerateClass(tmp, templates, false);
|
||||
// File.WriteAllText($@"C:\gen\{tmp.ClassName}.cs", source);
|
||||
context.AddSource(tmp.ClassName + ".Generated.cs", source);
|
||||
}
|
||||
else if (tmp.Type == TemplateType.Record)
|
||||
{
|
||||
var source = TemplateGenerator.GenerateRecord(tmp, templates);
|
||||
// File.WriteAllText($@"C:\gen\{tmp.ClassName}.cs", source);
|
||||
context.AddSource(tmp.ClassName + ".Generated.cs", source);
|
||||
}
|
||||
}
|
||||
@ -66,8 +65,6 @@ public class ResourceGenerator : ISourceGenerator
|
||||
|
||||
"\r\n } \r\n}";
|
||||
|
||||
//File.WriteAllText($@"C:\gen\Esiur.Generated.cs", gen);
|
||||
|
||||
context.AddSource("Esiur.Generated.cs", typesFile);
|
||||
|
||||
}
|
||||
@ -82,9 +79,63 @@ public class ResourceGenerator : ISourceGenerator
|
||||
return fieldName.Substring(0, 1).ToUpper() + fieldName.Substring(1);
|
||||
}
|
||||
|
||||
public string FormatAttribute(AttributeData attribute)
|
||||
{
|
||||
if (attribute.AttributeClass is object)
|
||||
{
|
||||
string className = attribute.AttributeClass.ToDisplayString();
|
||||
|
||||
if (!attribute.ConstructorArguments.Any() & !attribute.ConstructorArguments.Any())
|
||||
{
|
||||
return className;
|
||||
}
|
||||
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
|
||||
stringBuilder.Append(className);
|
||||
stringBuilder.Append('(');
|
||||
|
||||
bool first = true;
|
||||
|
||||
foreach (var constructorArgument in attribute.ConstructorArguments)
|
||||
{
|
||||
if (!first)
|
||||
{
|
||||
stringBuilder.Append(", ");
|
||||
}
|
||||
|
||||
stringBuilder.Append(constructorArgument.ToCSharpString());
|
||||
first = false;
|
||||
}
|
||||
|
||||
foreach (var namedArgument in attribute.NamedArguments)
|
||||
{
|
||||
if (!first)
|
||||
{
|
||||
stringBuilder.Append(", ");
|
||||
}
|
||||
|
||||
stringBuilder.Append(namedArgument.Key);
|
||||
stringBuilder.Append(" = ");
|
||||
stringBuilder.Append(namedArgument.Value.ToCSharpString());
|
||||
first = false;
|
||||
}
|
||||
|
||||
stringBuilder.Append(')');
|
||||
|
||||
return stringBuilder.ToString();
|
||||
}
|
||||
|
||||
throw new Exception("Attribute not found");
|
||||
}
|
||||
|
||||
public void Execute(GeneratorExecutionContext context)
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
|
||||
if (!(context.SyntaxContextReceiver is ResourceGeneratorReceiver receiver))
|
||||
return;
|
||||
|
||||
@ -177,10 +228,11 @@ namespace { ci.ClassSymbol.ContainingNamespace.ToDisplayString() } {{
|
||||
var fn = f.Name;
|
||||
var pn = string.IsNullOrEmpty(givenName) ? SuggestExportName(fn) : givenName;
|
||||
|
||||
//System.IO.File.AppendAllText("c:\\gen\\fields.txt", fn + " -> " + pn + "\r\n");
|
||||
|
||||
// copy attributes
|
||||
var attrs = string.Join("\r\n\t", f.GetAttributes().Select(x => $"[{x.ToString()}]"));
|
||||
//Debugger.Launch();
|
||||
|
||||
var attrs = string.Join("\r\n\t", f.GetAttributes().Select(x => $"[{x.AttributeClass.Name}({x.ConstructorArguments.Select(x => x.Values.ToString())})]"));// x.ToString()}]"));
|
||||
|
||||
//Debugger.Launch();
|
||||
if (f.Type.Name.StartsWith("ResourceEventHandler") || f.Type.Name.StartsWith("CustomResourceEventHandler"))
|
||||
{
|
||||
@ -194,14 +246,18 @@ namespace { ci.ClassSymbol.ContainingNamespace.ToDisplayString() } {{
|
||||
|
||||
code += "}}\r\n";
|
||||
|
||||
//System.IO.File.WriteAllText("c:\\gen\\" + ci.Name + "_esiur.cs", code);
|
||||
context.AddSource(ci.Name + ".Generated.cs", code);
|
||||
context.AddSource(ci.Name + ".g.cs", code);
|
||||
|
||||
}
|
||||
catch //(Exception ex)
|
||||
catch (Exception ex)
|
||||
{
|
||||
//System.IO.File.AppendAllText("c:\\gen\\error.log", ci.Name + " " + ex.ToString() + "\r\n");
|
||||
context.AddSource(ci.Name + ".Error.g.cs", $"/*\r\n {ex}\r\n*/");
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
context.AddSource("Error.g.cs", $"/*\r\n {ex}\r\n*/");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user