All Projects → cezarypiatek → CsharpMacros

cezarypiatek / CsharpMacros

Licence: MIT License
A simple template base system of macros for C# that can be executed in design time

Programming Languages

C#
18002 projects
powershell
5483 projects

Labels

Projects that are alternatives of or similar to CsharpMacros

DynamicRun
Dynamically run code using .NET 7, Roslyn and AssemblyLoadContext
Stars: ✭ 83 (+76.6%)
Mutual labels:  roslyn
QSharp
Q# is a C# to C++ compiler using the Qt library for the classlib
Stars: ✭ 16 (-65.96%)
Mutual labels:  roslyn
DDDToolbox
A set of Roslyn refactorings supporting DDD design
Stars: ✭ 31 (-34.04%)
Mutual labels:  roslyn
Cometary
Roslyn extensions, with a touch of meta-programming.
Stars: ✭ 31 (-34.04%)
Mutual labels:  roslyn
SmartCodeGenerator
No description or website provided.
Stars: ✭ 37 (-21.28%)
Mutual labels:  roslyn
Mockaco
🐵 HTTP mock server, useful to stub services and simulate dynamic API responses, leveraging ASP.NET Core features, built-in fake data generation and pure C# scripting
Stars: ✭ 213 (+353.19%)
Mutual labels:  roslyn
Avalonia.PropertyGenerator
Avalonia.PropertyGenerator generates the appropriate CLR members for Avalonia property definitions.
Stars: ✭ 20 (-57.45%)
Mutual labels:  roslyn
Codist
A visual studio extension which enhances syntax highlighting, quick info (tooltip), navigation bar, scrollbar, display quality and brings smart tool bar to code editor.
Stars: ✭ 134 (+185.11%)
Mutual labels:  roslyn
doteasy.rpc
Inspired by microservices, a lightweight framework that looks like a rabbit, based on NET Core 2.0 Standard 2 core library
Stars: ✭ 62 (+31.91%)
Mutual labels:  roslyn
UnitTestBoilerplateGenerator
An extension for Visual Studio that generates a unit test boilerplate from a given class, setting up mocks for all dependencies. Supports NUnit, Visual Studio Test, XUnit and many mock frameworks.
Stars: ✭ 39 (-17.02%)
Mutual labels:  roslyn
ThisAssembly
Exposes project and assembly level information as constants in the ThisAssembly class using source generators powered by Roslyn.
Stars: ✭ 209 (+344.68%)
Mutual labels:  roslyn
CqrsMessagingTools
jelster.github.com/CqrsMessagingTools/
Stars: ✭ 39 (-17.02%)
Mutual labels:  roslyn
DotNet.SystemCollections.Analyzers
A set of code analyzers & code fix providers to help developers use the proper .NET Collection & API in their algorithms
Stars: ✭ 72 (+53.19%)
Mutual labels:  roslyn
code-contracts-remover
tool for removing .net code contracts from project
Stars: ✭ 13 (-72.34%)
Mutual labels:  roslyn
ThunderboltIoc
One of the very first IoC frameworks for .Net that has no reflection. An IoC that casts its services before thunder casts its bolts.
Stars: ✭ 40 (-14.89%)
Mutual labels:  roslyn
icsharp.kernel
Roslyn based C# kernel for Jupyter Notebook
Stars: ✭ 26 (-44.68%)
Mutual labels:  roslyn
Rosalina
Rosalina is a code generation tool for Unity's UI documents. It generates C# code-behind script based on a UXML template.
Stars: ✭ 57 (+21.28%)
Mutual labels:  roslyn
Ref12
Sends F12 in Visual Studio to the new .Net Reference Source Browser
Stars: ✭ 76 (+61.7%)
Mutual labels:  roslyn
replay-csharp
An editable C# REPL (Read Eval Print Loop) powered by Roslyn and .NET Core
Stars: ✭ 69 (+46.81%)
Mutual labels:  roslyn
Uno.CodeGen
A set of source generators for equality, immutability, ...
Stars: ✭ 85 (+80.85%)
Mutual labels:  roslyn

CsharpMacros

A simple template base system of macros for Visual Studio that can be executed in design time

examplle usage

Releases

Support for VisualStudio.

Install as a NuGet package or VSIX. Verify your Roslyn integration option in case you are using R#.

Support JetBrains Rider

Install as a nuget package

Support for VSCode

Install as a NuGet package and check Enable support for Roslyn analyzers, code fixes and rulesets in Settings.

LiveTemplates for CsharpMacros

To facilitate usage of CsharpMacros I created a couple of Resharper LiveTemplates. You can read more about that on the snippets sub-page.

Macro anatomy

macro anatomy

Every macro consists of the following parts

  1. Macro Header in the following format macros.macro_function(macro_params).
  2. Macro Template - a template of code that will be repeated for every element returned by the macro function. The template can contain placeholders in the following format ${attribute_name} that will be replaced with a given attribute value of the element returned by the macro function.
  3. macro_function represents one of the predefined functions that generate input data for the template.
  4. macro_params is the input for macro function.
  5. The placeholder that will be replaced with the value of the given attribute. Placeholders can also contain filters that transform the attribute value. Syntax for placeholder with filter ${attribute_Name | filter_name}. The filters can be combined together by chaining them with | operator. Currently available filters: lowercase, uppercase, pascalcase, camelcase, snakecase.

Macro functions

properties

Description: Returns a list of properties of given type accepted as the parameter.

Parameters: Type name. For types from other projects/assemblies include also the namespace.

Attributes:

  • name - name of the property
  • type - type of the property
  • typeLong - type of the property. For primitives from System namespace, holds the full name (example: int -> Int32)

Examples:

// macros.properties(SampleType)
// Console.WriteLine("Property '${name}' of type '${type}'")

methods

Description: Returns a list of methods of a given type accepted as the parameter.

Parameters: Type name. For types from other projects/assemblies include also the namespace.

Attributes:

  • name - name of the method
  • returnType - name of the return type
  • returnTypeLong - name of the return type. For primitives from System namespace, holds the full name. Example: int -> Int32)
  • signature - a complete method signature. Example: int Calculate(int a, int b)
  • returnOperator - empty string for void methods, otherwise return keyword
  • parameters - comma separated list of parameters wrapped in parenthesis. Example: (a, b, c)
  • genericParameters - comma separated list of generic type parameters wrapped in angle brackets. Example: <T1, T2, T3>
  • paramNameX - name of the parameter. X marks the number of the parameter.
  • paramTypeX - name of the parameter type. X marks the number of the parameter.
  • paramTypeLongX - name of the parameter type. X marks the number of the parameter. For primitives from System namespace, holds the full name (example: int -> Int32)

Examples:

// macros.methods(SampleType)
// Console.WriteLine("Method name: ${name}")
// Console.WriteLine("\t Return type: ${returnType}")
// Console.WriteLine("\t First parameter name: ${paramName1}")
// Console.WriteLine("\t First parameter type: ${paramType1}")

implement

Description: Returns a list of types that implement a given interface accepted as the parameter. Parameters: Interface name. For interfaces from other projects/assemblies include also the namespace.

Attributes:

  • name - the name of the class that implements the given interface
  • interface - for a non-generic interface, this is the same as the parameter of the macro function. For generic interface contains the name of the interface with generic parameter values.

Examples:

// macros.implement(ISampleInterface<>)
// Console.WriteLine("Interface ${interface} is implemented by ${name}")

derived

Description: Returns a list of types that inherit from a given class accepted as the parameter.

Parameters: Type name. For types from other projects/assemblies include also the namespace.

Attributes:

  • name - the name of the type that inherits from a given class
  • based - for generic non-generic base class this is the same as the parameter of the macro function. For generic base class contains the name of the class with generic parameter values.

Examples:

// macros.derived(BaseClass<>)
// Console.WriteLine("Class ${name} inherits from ${based}")

values

Description: Returns values from the predefined list provided as a macro parameter.

Parameters: List of comma-separated values or list of comma-separated tuples

Attributes:

  • value - for simple list
  • valueX - for list of tuples. X marks the number of the value inside the tuple

Examples:

Simple list:

// macros.values(banana, strawberry, apple)
// Console.WriteLine("Fruit ${value}")

List of tuples:

// macros.values((banana, yellow), (strawberry, red), (apple, green))
// Console.WriteLine("${value1} fruit has ${value2} color.")

Range

Description: Returns values from the predefined range.

Parameters: The begin and end of the range

Attributes:

  • index - current counter value
  • from - The begin of the range
  • to - The end of the range

Examples:

// macros.range(10, 15)
//Console.WriteLine("Value ${index} from range [${from} - ${to}");

Enum

Description: Returns a list of enum values

Parameters: Enum type. For types from other projects/assemblies include also the namespace.

Attributes:

  • name - the name of enum option

Examples:

// macros.enum(SampleEnumType)
//Console.WriteLine("Option: ${name}");
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].