mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-02-14 19:29:36 +01:00
Use enum for access level in XamlUiPartialClassGenerator (#2161)
This commit is contained in:
@@ -13,5 +13,6 @@
|
||||
<Compile Link="XamlX\filename" Include="../XamlX/src/XamlX/**/*.cs" />
|
||||
<Compile Remove="../XamlX/src/XamlX/**/SreTypeSystem.cs" />
|
||||
<Compile Remove="../XamlX/src/XamlX/obj/**" />
|
||||
<Compile Include="..\Robust.Client\UserInterface\ControlPropertyAccess.cs" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
||||
@@ -6,6 +6,7 @@ using System.Text;
|
||||
using Microsoft.CodeAnalysis;
|
||||
using Microsoft.CodeAnalysis.CSharp;
|
||||
using Microsoft.CodeAnalysis.Text;
|
||||
using Robust.Client.UserInterface;
|
||||
using XamlX.Ast;
|
||||
using XamlX.Emit;
|
||||
using XamlX.IL;
|
||||
@@ -37,10 +38,10 @@ namespace Robust.Client.AutoGenerated
|
||||
|
||||
class NameVisitor : IXamlAstVisitor
|
||||
{
|
||||
private readonly List<(string name, string type, string access)> _names =
|
||||
new List<(string name, string type, string access)>();
|
||||
private readonly List<(string name, string type, AccessLevel access)> _names =
|
||||
new List<(string name, string type, AccessLevel access)>();
|
||||
|
||||
public static List<(string name, string type, string access)> GetNames(IXamlAstNode node)
|
||||
public static List<(string name, string type, AccessLevel access)> GetNames(IXamlAstNode node)
|
||||
{
|
||||
var visitor = new NameVisitor();
|
||||
node.Visit(visitor);
|
||||
@@ -88,7 +89,7 @@ namespace Robust.Client.AutoGenerated
|
||||
|
||||
var reg = (nameText.Text,
|
||||
$@"{clrtype.Namespace}.{clrtype.Name}",
|
||||
accessText?.Text ?? "Protected");
|
||||
accessText != null ? (AccessLevel) Enum.Parse(typeof(AccessLevel), accessText.Text) : AccessLevel.Protected);
|
||||
if (!_names.Contains(reg))
|
||||
{
|
||||
_names.Add(reg);
|
||||
@@ -137,36 +138,38 @@ namespace Robust.Client.AutoGenerated
|
||||
|
||||
var namedControls = names.Select(info =>
|
||||
{
|
||||
(string name, string type, string access) = info;
|
||||
(string name, string type, AccessLevel access) = info;
|
||||
|
||||
string accessStr;
|
||||
switch (access)
|
||||
{
|
||||
case "Public":
|
||||
access = "public";
|
||||
case AccessLevel.Public:
|
||||
accessStr = "public";
|
||||
break;
|
||||
case "Protected" when classSymbol.IsSealed:
|
||||
case "PrivateProtected" when classSymbol.IsSealed:
|
||||
case "Private":
|
||||
access = "private";
|
||||
case AccessLevel.Protected when classSymbol.IsSealed:
|
||||
case AccessLevel.PrivateProtected when classSymbol.IsSealed:
|
||||
case AccessLevel.Private:
|
||||
accessStr = "private";
|
||||
break;
|
||||
case "Protected":
|
||||
access = "protected";
|
||||
case AccessLevel.Protected:
|
||||
accessStr = "protected";
|
||||
break;
|
||||
case "Internal":
|
||||
case "ProtectedInternal" when classSymbol.IsSealed:
|
||||
access = "internal";
|
||||
case AccessLevel.PrivateProtected:
|
||||
accessStr = "private protected";
|
||||
break;
|
||||
case "ProtectedInternal":
|
||||
access = "protected internal";
|
||||
case AccessLevel.Internal:
|
||||
case AccessLevel.ProtectedInternal when classSymbol.IsSealed:
|
||||
accessStr = "internal";
|
||||
break;
|
||||
case "PrivateProtected":
|
||||
access = "private protected";
|
||||
case AccessLevel.ProtectedInternal:
|
||||
accessStr = "protected internal";
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentException($"Invalid access level for control {name} in {fileName}: {access}.");
|
||||
throw new ArgumentException($"Invalid access level \"{Enum.GetName(typeof(AccessLevel), access)}\" " +
|
||||
$"for control {name} in file {fileName}.");
|
||||
}
|
||||
|
||||
return $" {access} global::{type} {name} => this.FindControl<global::{type}>(\"{name}\");";
|
||||
return $" {accessStr} global::{type} {name} => this.FindControl<global::{type}>(\"{name}\");";
|
||||
});
|
||||
|
||||
return $@"// <auto-generated />
|
||||
@@ -182,7 +185,6 @@ namespace {nameSpace}
|
||||
";
|
||||
}
|
||||
|
||||
|
||||
public void Execute(GeneratorExecutionContext context)
|
||||
{
|
||||
var comp = (CSharpCompilation) context.Compilation;
|
||||
|
||||
@@ -998,14 +998,4 @@ namespace Robust.Client.UserInterface
|
||||
public readonly int OldIndex;
|
||||
public readonly int NewIndex;
|
||||
}
|
||||
|
||||
public enum AccessLevel
|
||||
{
|
||||
Public,
|
||||
Protected,
|
||||
Internal,
|
||||
ProtectedInternal,
|
||||
Private,
|
||||
PrivateProtected,
|
||||
}
|
||||
}
|
||||
|
||||
12
Robust.Client/UserInterface/ControlPropertyAccess.cs
Normal file
12
Robust.Client/UserInterface/ControlPropertyAccess.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
namespace Robust.Client.UserInterface
|
||||
{
|
||||
public enum AccessLevel
|
||||
{
|
||||
Public,
|
||||
Protected,
|
||||
Internal,
|
||||
ProtectedInternal,
|
||||
Private,
|
||||
PrivateProtected,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user