ParameterBuilder
Create parameter declarations for methods, constructors, and indexers.
See also: Emit Overview | MethodBuilder | ConstructorBuilder | IndexerBuilder
Factory Methods
| Method |
Description |
For(string name, string type) |
Create a parameter |
For<T>(string name, ValidSymbol<T> type) |
Create a parameter using a symbol's globally qualified name |
Configuration
param.WithDefaultValue("0")
param.WithDefaultValue("\"default\"")
param.WithDefaultValue("null")
param.AsRef()
param.AsOut()
param.AsIn()
param.AsParams()
param.AsThis() // for extension method target
Attributes
param.WithAttribute("CallerMemberName")
param.WithAttribute("NotNull")
param.WithAttribute("FromQuery", a => a.WithArgument("Name = \"id\""))
param.WithAttribute(preConfiguredAttribute)
Example
// Simple parameter
MethodBuilder.For("Process")
.AddParameter("input", "string")
.AddParameter("count", "int", p => p.WithDefaultValue("0"))
// Extension method
MethodBuilder.For("ToUpper")
.AddParameter("value", "string", p => p.AsThis())
// Out parameter
MethodBuilder.For("TryParse")
.AddParameter("input", "string")
.AddParameter("result", "int", p => p.AsOut())
Properties
param.Name // string
param.Type // string
param.IsExtensionTarget // bool — true if 'this' modifier
param.Modifier // ParameterModifier
param.DefaultValue // string?
ParameterModifier Enum
| Value |
Description |
None |
No modifier |
Ref |
ref parameter |
Out |
out parameter |
In |
in parameter |
Params |
params parameter |
This |
this parameter (extension method target) |
ParameterValidationKind Enum
| Value |
Description |
ThrowIfNull |
ArgumentNullException if null |
ThrowIfNullOrEmpty |
ArgumentException if null or empty |
ThrowIfNullOrWhiteSpace |
ArgumentException if null, empty, or whitespace |
ThrowIfOutOfRange |
ArgumentOutOfRangeException if outside specified range |
ThrowIfNotPositive |
ArgumentOutOfRangeException if zero or negative |
ThrowIfNegative |
ArgumentOutOfRangeException if negative |
ThrowIfZero |
ArgumentOutOfRangeException if zero |