CircularReflection 1.0.2

There is a newer version of this package available.
See the version list below for details.
dotnet add package CircularReflection --version 1.0.2                
NuGet\Install-Package CircularReflection -Version 1.0.2                
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="CircularReflection" Version="1.0.2" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add CircularReflection --version 1.0.2                
#r "nuget: CircularReflection, 1.0.2"                
#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.
// Install CircularReflection as a Cake Addin
#addin nuget:?package=CircularReflection&version=1.0.2

// Install CircularReflection as a Cake Tool
#tool nuget:?package=CircularReflection&version=1.0.2                

CircularReflection

MSBuild task that re-writes classes as abstract definitions, to allow circular references

This is useful for:

  • Auto-generation of references (such as URLs from ASPNet)
  • Making nameof(...) references
  • Making <see cref="..."/> references in doc comments

Applying the build task to your project

  1. Reference the NuGet package in the project that wants to read the types
  2. Add <InputBase>$(MSBuildProjectDirectory)\..\SourceProject\CsFileDirectory</InputBase> into a <PropertyGroup> of any project referencing this package
  3. Rebuild, and start referencing types
    <PropertyGroup>
        <ReflectionInputBase>$(MSBuildProjectDirectory)\..\SourceProject\CsFileDirectory</ReflectionInputBase>
    </PropertyGroup>

Referencing types in your project

The types in the source files will be added with the namespace prefix Reflection. So if the source has a class Me.MyPackage.MyClass, the generated type will be Reflection.Me.MyPackage.MyClass

Adding more using directives

If you are referencing files between different targets, you may need to include extra namespaces into the output.

    <PropertyGroup>
        <ReflectionAdditionalUsings>System;System.Collections.Generic;System.Threading.Tasks;</ReflectionAdditionalUsings>
    </PropertyGroup>

Removing namespace Stubs

By default, each using ...; namespace will have a stub class defined for it. This means the generated code should compile without requiring additional code to get generated code to build, but can result in the compiled assembly containing leaked namespaces.

If you set ReflectionNamespaceStubs to false, no stub are added, so namespaces are not leaked into generated assemblies. You may need to add some 'fake' namespaced classes to have a reliable build.

    <PropertyGroup>
        <ReflectionNamespaceStubs>false</ReflectionNamespaceStubs>
    </PropertyGroup>

Generated files

The generated files are written to the project's obj directory in a file named CircularReflection.generated.cs. This will be linked into the sources as part of the build.

If required, the output can be moved with the ReflectionOutputBase setting

Development of the package

Building the NuGet package

First, always do a clean and rebuild.

Update the versions to match in the project properties ( assembly and nuget), and the nuspec file.

Open a terminal in the directory of CircularReflection.csproj, and run the command dotnet pack -o ...

References

There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.4 555 9/9/2024
1.0.3 541 7/2/2024
1.0.2 114 7/2/2024
1.0.1 123 7/2/2024
1.0.0 119 7/1/2024