Description
A simple template base system of macros for Visual Studio that can be executed in design time
CsharpMacros alternatives and similar packages
Based on the "Code Analysis and Metrics" category.
Alternatively, view CsharpMacros alternatives based on common mentions on social networks and blogs.
-
App.Metrics
App Metrics is an open-source and cross-platform .NET library used to record and report metrics within an application. -
CodeMaid
CodeMaid is an open source Visual Studio extension to cleanup and simplify our C#, C++, F#, VB, PHP, PowerShell, JSON, XAML, XML, ASP, HTML, CSS, LESS, SCSS, JavaScript and TypeScript coding. -
.NET Compiler Platform ("Roslyn") Analyzers
A number of Roslyn diagnostic analyzers initially developed to help flesh out the design and implementation of the static analysis APIs. -
StyleCop
Analyzes C# source code to enforce a set of style and consistency rules. -
Metrics-Net
The Metrics.NET library provides a way of instrumenting applications with custom metrics (timers, histograms, counters etc) that can be reported in various ways and can provide insights on what is happening inside a running application. -
Beat Pulse
Liveness, health check library for ASP.NET Core Applications -
NsDepCop
NsDepCop is a static code analysis tool that helps to enforce namespace dependency rules in C# projects. No more unplanned or unnoticed dependencies in your system. -
Gendarme
Gendarme is a extensible rule-based tool to find problems in .NET applications and libraries. Gendarme inspects programs and libraries that contain code in ECMA CIL format (Mono and .NET) and looks for common problems with the code, problems that compiler do not typically check or have not historically checked. -
AspNet.Metrics
No longer maintained, instead see - https://github.com/alhardy/AppMetrics/ -
Codinion
Enhanced syntax highlighting for C# and some other "Visual" features. -
NDepend
is a Visual Studio and VS Team Services extension that estimates your .NET code quality and Technical-Debt, that lets create code rules with C# LINQ syntax, visualize code structure and focus on changes and evolution.[$] -
Bencher
Suite of continuous benchmarking tools designed to catch performance regressions in CI. -
PVS-Studio
PVS-Studio is a static analyzer on guard of code quality, security (SAST), and code safety. [Free for OSS] [$]
Access the most powerful time series database as a service
* Code Quality Rankings and insights are calculated and provided by Lumnify.
They vary from L1 to L5 with "L5" being the highest.
Do you think we are missing an alternative of CsharpMacros or a related project?
README
CsharpMacros
A simple template base system of macros for Visual Studio that can be executed in design time
[examplle usage](doc/generate_assertions_animated.gif)
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
Every macro consists of the following parts
Macro Header
in the following formatmacros.macro_function(macro_params)
.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.macro_function
represents one of the predefined functions that generate input data for the template.macro_params
is the input for macro function.- 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 propertytype
- type of the propertytypeLong
- type of the property. For primitives fromSystem
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 methodreturnType
- name of the return typereturnTypeLong
- name of the return type. For primitives fromSystem
namespace, holds the full name. Example:int
->Int32
)signature
- a complete method signature. Example:int Calculate(int a, int b)
returnOperator
- empty string forvoid
methods, otherwisereturn
keywordparameters
- 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 fromSystem
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 interfaceinterface
- 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 classbased
- 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 listvalueX
- 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 valuefrom
- The begin of the rangeto
- 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}");