AdaskoTheBeAsT/Typewriter

Support for public static readonly fields

JBBianchi opened this issue · 5 comments

From frhagn#205

I cannot get public static readonly fields to get picked up by TypeWriter.

models.tst

$Classes(c => c.Name == "SignalRNotifications" || c.Name == "SignalRChannels")[export class $Name {$Fields[
    static $name: string = '$Value';]}
]

C# class

public static class SignalRNotifications
    {
        public static readonly string ImportProgress = "ImportProgressUpdated";
        public static readonly string ImportCompleted = "ImportCompleted";
        ...
    }

Indeed, for some reason, the static fields are excluded in RoslynFieldMetadata:

public static IEnumerable<IFieldMetadata> FromFieldSymbols(IEnumerable<IFieldSymbol> symbols, Settings settings)
{
    return symbols
        .Where(
            s => s.DeclaredAccessibility == Accessibility.Public && !s.IsConst && !s.IsStatic)
        .Select(s => new RoslynFieldMetadata(s, settings));
}

It would be great to be able to opt-in for static members in the settings (and maybe also other more "in-depth" reflection settings like private/protected members ...)

I wanted to try to contribute to the project but I can't get it to build in its default state (I had to remove StyleCop and SecurityCodeScan) and all the tests are failing (except one) because var document = _workspace.CurrentSolution.GetDocumentIdsWithFilePath(path).FirstOrDefault(); returns null.

to build you need to have latest VS and also execute submodules-sync.bat

and tests works on my machine ;)
image

classes and records have StaticReadOnlyFields property which contains collection of such fields (with values)