Skip to content

Clarify name prefix requirements for classes and enums #151

@michaeltlombardi

Description

@michaeltlombardi

Prerequisites

  • Existing Issue: Search the existing issues for this repository. If there is an issue that fits your needs do not file a new one. Subscribe, react, or comment on that issue instead.
  • Descriptive Title: Write the title for this issue as a short synopsis. If possible, provide context. For example, "Typo in Get-Foo cmdlet" instead of "Typo."
  • Verify Version: If there is a mismatch between documentation and the module on your system, ensure that the version you are using is the same as the documentation. Check this box if they match or the issue you are reporting is not version specific.

Version

v2.0

Links

Summary

If a class or enum is defined with the same name in more than one module, compiling configurations that use both of those modules fails due to the name collision.

Details

We already partially cover this problem for defining the Reasons property for machine configuration:

> [!NOTE]
> The class defined for the **Reasons** property is named `MyModuleReason` instead of `Reason`,
> using the module's name as a prefix. While you can give the class any name, if two or more
> modules define a class with the same name and are both used in a configuration, PowerShell raises
> an exception.
>
> To avoid exceptions caused by name conflicts in DSC and machine configuration, always prefix the
> name of the class you define for the **Reasons** property.

We should generalize this note and advice and surface it wherever it makes sense.

Suggested Fix

We should document this behavior, suggest that authors prefix their enums and classes with their module name, and add name prefixing to the best practices section for the Class-based DSC Resources article.

We may want to add an include that we can use throughout the documentation wherever we're talking about naming classes and enums for use as DSC Resource property types.

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions