-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ModuleInitializer class to help resolve assemblies before attributes
- Loading branch information
1 parent
34f4553
commit cd99a90
Showing
3 changed files
with
66 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
src/SourceGenerator.Foundations/Templates/ModuleInitializerTemplate.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using Microsoft.CodeAnalysis.Text; | ||
using System.Text; | ||
|
||
namespace System.Runtime.CompilerServices | ||
{ | ||
public static class ModuleInitializerTemplate | ||
{ | ||
public static SourceText Render() => SourceText.From($$""" | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
namespace System.Runtime.CompilerServices | ||
{ | ||
/// <summary> | ||
/// Used to indicate to the compiler that a method should be called | ||
/// in its containing module's initializer. | ||
/// </summary> | ||
/// <remarks> | ||
/// When one or more valid methods | ||
/// with this attribute are found in a compilation, the compiler will | ||
/// emit a module initializer which calls each of the attributed methods. | ||
/// | ||
/// Certain requirements are imposed on any method targeted with this attribute: | ||
/// - The method must be `static`. | ||
/// - The method must be an ordinary member method, as opposed to a property accessor, constructor, local function, etc. | ||
/// - The method must be parameterless. | ||
/// - The method must return `void`. | ||
/// - The method must not be generic or be contained in a generic type. | ||
/// - The method's effective accessibility must be `internal` or `public`. | ||
/// | ||
/// The specification for module initializers in the .NET runtime can be found here: | ||
/// https://github.com/dotnet/runtime/blob/main/docs/design/specs/Ecma-335-Augments.md#module-initializer | ||
/// </remarks> | ||
[global::System.AttributeUsage(global::System.AttributeTargets.Method, Inherited = false)] | ||
internal sealed class ModuleInitializerAttribute : global::System.Attribute | ||
{ | ||
public ModuleInitializerAttribute() | ||
{ | ||
} | ||
} | ||
} | ||
""", Encoding.UTF8); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters