Shiny.Reflector 1.6.1

Prefix Reserved
dotnet add package Shiny.Reflector --version 1.6.1
                    
NuGet\Install-Package Shiny.Reflector -Version 1.6.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Shiny.Reflector" Version="1.6.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Shiny.Reflector" Version="1.6.1" />
                    
Directory.Packages.props
<PackageReference Include="Shiny.Reflector" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Shiny.Reflector --version 1.6.1
                    
#r "nuget: Shiny.Reflector, 1.6.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Shiny.Reflector@1.6.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Shiny.Reflector&version=1.6.1
                    
Install as a Cake Addin
#tool nuget:?package=Shiny.Reflector&version=1.6.1
                    
Install as a Cake Tool

Shiny Reflector

Reflection is awesome and super powerful, but also very slow and non-AOT compliant. Using source generators, we look to solve some of those pain points. This library gives you the power of reflection... without the actual reflection!

Features

  • List Properties as well as what have getters and setters
  • Read/Write Values using string keys and object values
  • Easy property indexer for loose typing access (ie. myreflector["MyProperty"] = 123)
  • Fallback to reflection when a reflector is not available
  • Generate build variables of your choice into a static class for easy access
  • Works with the MVVM Community Toolkit source generation

Usage

Internal Class "Reflection"

Using the following attribute and marking your class as partial

[Shiny.Reflector.ReflectorAttribute]
public partial class MyClass
{
    public int MyProperty { get; set; }
    public string Message { get; set;}
}

Works on records as well, but you must use the partial keyword and attribute just like a class.

Just that attribute allows you to do this:

var myClass = new MySampleClass
{
    Name = "Hello World",
    Age = null
};

// NOTE: the use of GetReflector - a reflector class is generated for each class marked with the ReflectorAttribute
var reflector = myClass.GetReflector();
foreach (var prop in reflector.Properties) 
{
    var objValue = reflector[prop.Name];
    Console.WriteLine($"Property: {prop.Name} ({prop.Type}) - Current Value: {objValue}");
}

// generics for type casting
var name = reflector.GetValue<string>("Name");
Console.WriteLine("Reflector Name: " + name);

// indexers for loose typing
Console.WriteLine("Reflector Value: " + reflector["age"]);

// set with generics
reflector.SetValue("Age", 99);

// or just an object on the indexer
reflector["name"] = "Something Else";
Console.WriteLine("Reflector Name Value: " + reflector["NaMe"]);
Console.WriteLine("Reflector Age Value: " + reflector["NaMe"]);

Assembly Info Generation

You can also generate assembly information for your project by adding the following attribute to your AssemblyInfo.cs file:

In your project file, you can add the following property to enable the generation of assembly info:

<Project>
    <PropertyGroup>
        <TargetFramework>net9.0</TargetFramework>
        <MyCustomVar>Hello World</MyCustomVar>
    </PropertyGroup>
    
    <ItemGroup>
        <ReflectorItem Include="MyReflectorItem" 
                       Value="This is a sample value" 
                       Visible="false" />
        
        
        <ReflectorItem Include="PropertyGroupMyCustomVar" 
                       Value="$(MyCustomVar)" 
                       Visible="false" />
    </ItemGroup>
</Project>

And a new AssemblyInfo static class with constants will be generated for you (NOTE: it grabbed defaulted variables like Company, Version, etc. from the project file):

public static class AssemblyInfo
{
    public const string Company = "Samples";
    public const string Version = "1.0.0";
    public const string TargetFramework = "net9.0";
    public const string TargetFrameworkVersion = "v9.0";
    public const string Platform = "AnyCPU";
    public const string MyReflectorItem = "This is a sample value";
    public const string PropertyGroupMyCustomVar = "Hello World";
}

and now you can do easy things like this:

Console.WriteLine("Target Framework: " + AssemblyInfo.TargetFramework);
Console.WriteLine("My Custom Var: " + AssemblyInfo.PropertyGroupMyCustomVar);

Using Reflector with MVVM Community Toolkit

If you are using the Community Toolkit MVVM and more specifically, the source generation that it uses. You need to do the following Reflector detects your properties.

In your csproj file, add the following:

<PropertyGroup>
    <LangVersion>preview</LangVersion>
</PropertyGroup>

Now, in your ObservableObject class, you can use the Reflector attribute. Note properties use the newer C# partial properties keyword.

[Shiny.Reflector.ReflectorAttribute]
public partial class MyObservableObject : ObservableObject
{
    [ObservableProperty]
    public partial string MyProperty { get; set; }
}
Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net9.0

    • No dependencies.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Shiny.Reflector:

Package Downloads
Shiny.Extensions.Stores

Store anything in a key/value store - Abstractions for iOS, Android and Windows preferences/secure storage

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.6.1 155 7/7/2025
1.6.0 130 7/3/2025
1.6.0-beta-0014 126 7/15/2025
1.6.0-beta-0013 125 7/15/2025
1.6.0-beta-0012 130 7/15/2025
1.6.0-beta-0011 123 7/7/2025
1.6.0-beta-0010 131 7/3/2025
1.6.0-beta-0009 127 7/3/2025
1.6.0-beta-0006 121 7/1/2025
1.6.0-beta-0005 125 7/1/2025
1.6.0-beta-0004 125 7/1/2025
1.6.0-beta-0003 129 6/30/2025
1.5.1 466 6/30/2025
1.5.0 127 6/30/2025
1.4.0 134 6/30/2025
1.4.0-beta-0002 130 6/30/2025
1.4.0-beta-0001 125 6/30/2025
1.4.0-alpha-0002 120 6/29/2025
1.3.0 128 6/29/2025
1.2.0 126 6/29/2025
1.1.0 132 6/29/2025
1.1.0-alpha-0004 130 6/29/2025
1.1.0-alpha-0001 129 6/29/2025
1.0.0 133 6/29/2025
1.0.0-g0d103c2df8 88 6/28/2025
1.0.0-alpha-0013 131 6/29/2025
1.0.0-alpha-0012 87 6/28/2025
1.0.0-alpha-0007 65 6/27/2025
1.0.0-alpha-0006 68 6/27/2025
1.0.0-alpha-0005 71 6/27/2025
1.0.0-alpha-0004 121 6/27/2025