Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/piotrstenke/Durian
Durian is a collection of Roslyn-based analyzers and source generators that extend the default capabilities of C#.
https://github.com/piotrstenke/Durian
analysis csharp roslyn roslyn-analyzer source-generation
Last synced: 3 months ago
JSON representation
Durian is a collection of Roslyn-based analyzers and source generators that extend the default capabilities of C#.
- Host: GitHub
- URL: https://github.com/piotrstenke/Durian
- Owner: piotrstenke
- License: mit
- Created: 2021-04-16T19:34:18.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2022-09-19T07:32:37.000Z (about 2 years ago)
- Last Synced: 2024-05-12T13:31:51.734Z (6 months ago)
- Topics: analysis, csharp, roslyn, roslyn-analyzer, source-generation
- Language: C#
- Homepage:
- Size: 4.06 MB
- Stars: 51
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
- RSCG_Examples - Durian
- csharp-source-generators - Durian - ![stars](https://img.shields.io/github/stars/piotrstenke/Durian?style=flat-square&cacheSeconds=604800) ![last commit](https://img.shields.io/github/last-commit/piotrstenke/Durian?style=flat-square&cacheSeconds=86400) Extends the default capabilities of C# by mimicking features from other languages. (Source Generators / Other)
README
##
**Durian is a collection of Roslyn-based analyzers, source generators and utility libraries that bring many extensions to C#, with heavy emphasis on features that can be found in other existing languages. It's main goal is to make C# easier and more pleasant to use through reducing necessary boilerplate code, while at the same time providing additional layers of flexibility.**
## Table of Contents
1. [Current State](#current-state)
2. [Features](#features)
1. [DefaultParam](#defaultparam)
2. [InterfaceTargets](#interfacetargets)
3. [FriendClass](#friendclass)
3. [In Progress](#in-progress)
1. [CopyFrom](#copyfrom)
4. [Experimental](#experimental)
1. [ConstExpr](#constexpr)## Current State
Durian is at an early stage of its evolution - many core features are still missing, being either in early development or planning phase. As for now, three fully-fledged modules are ready - *DefaultParam*, *InterfaceTargets* and *FriendClass*.
## Features
To see more about a specific feature, click on its name.
### [DefaultParam](src/Durian.DefaultParam/README.md)
*DefaultParam* allows to specify a default type for a generic parameter.```csharp
using Durian;public class Test<[DefaultParam(typeof(string))]T>
{
public T Value { get; }public Test(T value)
{
Value = value;
}
}public class Program
{
static void Main()
{
// Test can be used without type parameters - 'T' defaults to 'string'.
Test test1 = new Test("");
// Type parameter can be stated explicitly.
Test test2 = new Test("");
}
}```
### [InterfaceTargets](src/Durian.InterfaceTargets/README.md)
*InterfaceTargets*, similar to how [System.AttributeUsageAttribute](https://docs.microsoft.com/en-us/dotnet/api/system.attributeusageattribute) works, allows to specify what kinds of members an interface can be implemented by.
```csharp
using Durian;[InterfaceTargets(InterfaceTargets.Class)]
public interface ITest
{
}// Success!
// ITest can be implemented, because ClassTest is a class.
public class ClassTest : ITest
{
}// Error!
// ITest cannot be implemented, because StructTest is a struct, and ITest is valid only for classes.
public struct StructTest : ITest
{
}```
### [FriendClass](src/Durian.FriendClass/README.md)
*FriendClass* allows to limit access to 'internal' members by specifying a fixed list of friend types.
```csharp
using Durian;[FriendClass(typeof(A))]
public class Test
{
internal static string Key { get; }
}public class A
{
public string GetKey()
{
// Success!
// Type 'A' is a friend of 'Test', so it can safely access internal members.
return Test.Key;
}
}public class B
{
public string GetKey()
{
// Error!
// Type 'B' is not a friend of 'Test', so it cannot access internal members.
return Test.Key;
}
}
```### [CopyFrom](src/Durian.CopyFrom/README.md)
*CopyFrom* allows to copy implementations of members to other members, without the need for inheritance. A regex pattern can be provided to customize the copied implementation.
```csharp
using Durian;[CopyFromType(typeof(Other)), Pattern("text", "name")]
public partial class Test
{
}public class Other
{
private string _text;void Set(string text)
{
_text = text;
}
}// Generated
partial class Test
{
private string _name;void Set(string name)
{
_name = name;
}
}```
## In Progress
The following modules are still in active development and are yet to be released in a not-yet-specified future.
## Experimental
Experimental stage is a playground of sorts - modules included here are very early in development and there in no guarantee that they will be ever actually released.
### [ConstExpr](src/Durian.ConstExpr/README.md)
*ConstExpr* allows a method to be executed at compile-time, producing actual constants.
```csharp
using Durian;public static class Utility
{
[ConstExpr]
public static int Sum(params int[] values)
{
int sum = 0;for(int i = 0; i < values.Length; i++)
{
sum += values[i];
}return sum;
}
}[ConstExprSource("Utility.Sum", 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, Name = "Sum_10")]
public static partial class Constants
{
}// Generated
public static partial class Constants
{
public const int Sum_10 = 55;
}```
##
*\(Written by Piotr Stenke\)*