© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•2y ago•
3 replies
Nothavid

✅ Finding all FieldInfo's of BackingFields of a type

I have following code snippet to find all
FieldInfo
FieldInfo
's of a type
t
t
which are BackingFields of public properties of type double.

FieldInfo[] doubleFields = t
    .GetProperties(BindingFlags.Public | BindingFlags.Instance)
    .Where(p => p.PropertyType == typeof(double))
    .Select(p => t.GetField($"<{p.Name}>k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance)!)
    .Where(f => f is not null)
    .ToArray();
FieldInfo[] doubleFields = t
    .GetProperties(BindingFlags.Public | BindingFlags.Instance)
    .Where(p => p.PropertyType == typeof(double))
    .Select(p => t.GetField($"<{p.Name}>k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance)!)
    .Where(f => f is not null)
    .ToArray();


I was now wondering if the
CompilerGeneratedAttribute
CompilerGeneratedAttribute
is only applied to BackingFields or if there are other instances of fields having that attribute since I cannot currently think of any. If it is only applied to BackingFields, I could skip the step of getting all properties.
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Unable to get the FieldInfo's value
C#CC# / help
2y ago
Retrive TypeDeclarationSyntax from a referenced type
C#CC# / help
4y ago
✅ Finding all possibilities of N length in an array
C#CC# / help
9mo ago