read-only-interface-generator
Описание
This repository contains Roslyn generator of read-only interfaces.
Языки
- C#93,2%
- PowerShell3,6%
- Shell3%
- Batchfile0,2%
Read-only interface generator
This repository contains Roslyn generator of read-only interfaces.
Russian version of documentation
Installation
Add NuGet package to your project:
Generation of read-only interface
If you want to generate a read-only interface for your type, you must do the following things:
- Make your type
,partial - Augment it with
attribute fromWithReadOnlynamespace.EdlinSoftware.Generators.ReadOnlyInterface
Properties of generated read-only interface
The generated interface will contain all public readable properties of your type, including inherited properties from base types.
Supported types
You can generate read-only interface for:
- Classes
- Structures
- Records
- Interfaces
Nested types
You can generate read-only interface for a nested type. But in this case you must make partial not only the type itself, but all containing types:
Type accessibility
Read-only interface can be generated for a type of any accessibility:
- public
- protected
- internal
- protected internal
- private
By default, generated read-only interface has the same accessibility as its underlying type.
But you also may change accessibility of generated read-only interface. It can be done using property of attribute:
As new read-only interface will be generated inside the same containing type, as your underlying type, it is your responsibility to provide valid interface accessibility for this place.
Name of read-only interface
By default the name of a read-only interface is generated from the name of underlying type by adding prefix. For example, for a class with name there will be generated a read-only interface with name . For an interface with name there will be generated a read-only interface with name .
But you have an ability to change this prefix. It can be done using property of attribute:
In this case, you are fully responsible for providing a prefix which forms a valid .NET name of type.
Types of properties of read-only interface
Usually types of properties of the read only interface are the same as in the initial class. But there can be a case, when such type has read-only interface itself:
Here property of has type which itself has read-only interface. In this case, generated interface will change type of this property to corresponding read-only interface:
If you don't want such behavior, you can use attribute:
You can set this attribute to particular properties or to the whole type:
Appreciations
NuGet package icon is created by Freepik on Flaticon