reflaxe.CSharp icon indicating copy to clipboard operation
reflaxe.CSharp copied to clipboard

Enhancement: Support Various Meta for Class Access Modifiers

Open AndrewDRX opened this issue 1 year ago • 2 comments

Request

Add support for the following meta for class access modifiers: @:file for file @:internal for internal @:public for public

Suggested Syntax

The syntax could be as follows:

@:public
class MyClass { }

To generate C# as follows:

public class MyClass { }

Details

Currently, classes are generated with no access modifiers. C# has the default modifier of internal when not specified, so all generated classes effectively have that modifier. This makes it impossible to develop a library package since all generated classes would be inaccessible when references by other projects.

Suggested Code Change

I can submit a pull request to show a rough idea of what this would look like.

Other Notes

There are also other class access modifiers (and accessibility levels) that would be applicable to nested classes, but I am not sure about the feasibility of generating nested classes, so those are excluded from this request.

References

Microsoft-documented C# access modifiers and accessibility levels: https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/access-modifiers

AndrewDRX avatar Feb 18 '24 21:02 AndrewDRX

I think this is a good thing to add, but better wait for my current ongoing changes before submitting a PR

jeremyfa avatar Feb 18 '24 22:02 jeremyfa

Okay. I noticed this logic in CSClass.hx:

// Compile metadata (built-in Reflaxe function)
var clsMeta = compiler.compileMetadata(classType.meta, MetadataTarget.Class) ?? "";
declaration += clsMeta;

// Basic declaration
declaration += "class " + csClassName;

So I was wondering if there was some existing process for adding/updating a metadata template where that would be able to handle it.

But I'll wait on investigating any changes for pull request until you are all set.

AndrewDRX avatar Feb 19 '24 01:02 AndrewDRX