Interface ICSharpHelper
- Namespace
- Microsoft.EntityFrameworkCore.Design
- Assembly
- Microsoft.EntityFrameworkCore.dll
Helper for generating C# code.
public interface ICSharpHelper
Remarks
See Implementation of database providers and extensions for more information and examples.
Methods
Arguments(IEnumerable<object>)
Generates a comma-sepearated argument list of values.
string Arguments(IEnumerable<object> values)
Parameters
values
IEnumerable<object>The values.
Returns
- string
The argument list.
Expression(Expression, ISet<string>)
Translates a node representing an expression into source code that would produce it.
[EntityFrameworkInternal]
string Expression(Expression node, ISet<string> collectedNamespaces)
Parameters
node
ExpressionThe node to be translated.
collectedNamespaces
ISet<string>Any namespaces required by the translated code will be added to this set.
Returns
- string
Source code that would produce
node
.
Remarks
This is an internal API that supports the Entity Framework Core infrastructure and not subject to the same compatibility standards as public APIs. It may be changed or removed without notice in any release. You should only use it directly in your code with extreme caution and knowing that doing so can result in application failures when updating to a new Entity Framework Core release.
Fragment(AttributeCodeFragment)
Generates an attribute specification.
string Fragment(AttributeCodeFragment fragment)
Parameters
fragment
AttributeCodeFragmentThe attribute code fragment.
Returns
- string
The attribute specification code.
Fragment(IMethodCallCodeFragment?, int)
Generates a method call code fragment.
string Fragment(IMethodCallCodeFragment? fragment, int indent = 0)
Parameters
fragment
IMethodCallCodeFragmentThe method call. If null, no code is generated.
indent
intThe indentation level to use when multiple lines are generated.
Returns
- string
The fragment.
Fragment(IMethodCallCodeFragment, string?, bool)
Generates a method call code fragment.
string Fragment(IMethodCallCodeFragment fragment, string? instanceIdentifier, bool typeQualified)
Parameters
fragment
IMethodCallCodeFragmentThe method call.
instanceIdentifier
stringAn identifier on which the method call will be generated.
typeQualified
booltrue if the method call should be type-qualified, false for instance/extension syntax.
Returns
- string
The fragment.
Fragment(NestedClosureCodeFragment, int)
Generates a lambda code fragment.
string Fragment(NestedClosureCodeFragment fragment, int indent = 0)
Parameters
fragment
NestedClosureCodeFragmentThe lambda.
indent
intThe indentation level to use when multiple lines are generated.
Returns
- string
The fragment.
Fragment(PropertyAccessorCodeFragment)
Generates a property accessor lambda code fragment.
string Fragment(PropertyAccessorCodeFragment fragment)
Parameters
fragment
PropertyAccessorCodeFragmentThe property accessor lambda.
Returns
- string
A code representation of the lambda.
GetRequiredUsings(Type)
Gets the using statements required when referencing a type.
IEnumerable<string> GetRequiredUsings(Type type)
Parameters
type
TypeThe type.
Returns
- IEnumerable<string>
The usings.
Identifier(string, ICollection<string>?, bool?)
Generates a valid C# identifier from the specified string unique to the scope.
string Identifier(string name, ICollection<string>? scope = null, bool? capitalize = null)
Parameters
name
stringThe base identifier name.
scope
ICollection<string>A list of in-scope identifiers.
capitalize
bool?true if the first letter should be converted to uppercase; false if the first letter should be converted to lowercase;
Returns
- string
The identifier.
Lambda(IEnumerable<IProperty>, string?)
Generates a property accessor lambda.
string Lambda(IEnumerable<IProperty> properties, string? lambdaIdentifier = null)
Parameters
properties
IEnumerable<IProperty>The properties.
lambdaIdentifier
stringThe identifier to use for parameter in the lambda.
Returns
- string
The lambda.
Lambda(IReadOnlyList<string>, string?)
Generates a property accessor lambda.
string Lambda(IReadOnlyList<string> properties, string? lambdaIdentifier = null)
Parameters
properties
IReadOnlyList<string>The property names.
lambdaIdentifier
stringThe identifier to use for parameter in the lambda.
Returns
- string
The lambda.
Literal(bool)
Generates a bool literal.
string Literal(bool value)
Parameters
value
boolThe value.
Returns
- string
The literal.
Literal(byte)
Generates a byte literal.
string Literal(byte value)
Parameters
value
byteThe value.
Returns
- string
The literal.
Literal(char)
Generates a char literal.
string Literal(char value)
Parameters
value
charThe value.
Returns
- string
The literal.
Literal(DateOnly)
Generates a DateOnly literal.
string Literal(DateOnly value)
Parameters
value
DateOnlyThe value.
Returns
- string
The literal.
Literal(DateTime)
Generates a DateTime literal.
string Literal(DateTime value)
Parameters
value
DateTimeThe value.
Returns
- string
The literal.
Literal(DateTimeOffset)
Generates a DateTimeOffset literal.
string Literal(DateTimeOffset value)
Parameters
value
DateTimeOffsetThe value.
Returns
- string
The literal.
Literal(decimal)
Generates a decimal literal.
string Literal(decimal value)
Parameters
value
decimalThe value.
Returns
- string
The literal.
Literal(double)
Generates a double literal.
string Literal(double value)
Parameters
value
doubleThe value.
Returns
- string
The literal.
Literal(Enum, bool)
Generates an enum literal.
string Literal(Enum value, bool fullName = false)
Parameters
Returns
- string
The literal.
Literal(Guid)
Generates a Guid literal.
string Literal(Guid value)
Parameters
value
GuidThe value.
Returns
- string
The literal.
Literal(short)
Generates a short literal.
string Literal(short value)
Parameters
value
shortThe value.
Returns
- string
The literal.
Literal(int)
Generates an int literal.
string Literal(int value)
Parameters
value
intThe value.
Returns
- string
The literal.
Literal(long)
Generates a long literal.
string Literal(long value)
Parameters
value
longThe value.
Returns
- string
The literal.
Literal(BigInteger)
Generates a BigInteger literal.
string Literal(BigInteger value)
Parameters
value
BigIntegerThe value.
Returns
- string
The literal.
Literal(object?[,])
Generates a multidimensional array literal.
string Literal(object?[,] values)
Parameters
values
object[,]The multidimensional array.
Returns
- string
The literal.
Literal(sbyte)
Generates a sbyte literal.
string Literal(sbyte value)
Parameters
value
sbyteThe value.
Returns
- string
The literal.
Literal(float)
Generates a float literal.
string Literal(float value)
Parameters
value
floatThe value.
Returns
- string
The literal.
Literal(string?)
Generates a string literal.
string Literal(string? value)
Parameters
value
stringThe value.
Returns
- string
The literal.
Literal(TimeOnly)
Generates a TimeOnly literal.
string Literal(TimeOnly value)
Parameters
value
TimeOnlyThe value.
Returns
- string
The literal.
Literal(TimeSpan)
Generates a TimeSpan literal.
string Literal(TimeSpan value)
Parameters
value
TimeSpanThe value.
Returns
- string
The literal.
Literal(Type, bool?)
Generates a Type literal.
string Literal(Type value, bool? fullName = null)
Parameters
Returns
- string
The literal.
Literal(ushort)
Generates a ushort literal.
string Literal(ushort value)
Parameters
value
ushortThe value.
Returns
- string
The literal.
Literal(uint)
Generates a uint literal.
string Literal(uint value)
Parameters
value
uintThe value.
Returns
- string
The literal.
Literal(ulong)
Generates a ulong literal.
string Literal(ulong value)
Parameters
value
ulongThe value.
Returns
- string
The literal.
Literal<T>(List<T>, bool)
Generates a list literal.
string Literal<T>(List<T> values, bool vertical = false)
Parameters
Returns
- string
The literal.
Type Parameters
T
Literal<T>(T?)
Generates a nullable literal.
string Literal<T>(T? value) where T : struct
Parameters
value
T?The nullable value.
Returns
- string
The literal.
Type Parameters
T
The underlying type of the nullable type.
Literal<T>(T[], bool)
Generates an object array literal.
string Literal<T>(T[] values, bool vertical = false)
Parameters
values
T[]The object array.
vertical
boolA value indicating whether to layout the literal vertically.
Returns
- string
The literal.
Type Parameters
T
Literal<TKey, TValue>(Dictionary<TKey, TValue>, bool)
Generates a dictionary literal.
string Literal<TKey, TValue>(Dictionary<TKey, TValue> values, bool vertical = false) where TKey : notnull
Parameters
values
Dictionary<TKey, TValue>The dictionary.
vertical
boolA value indicating whether to layout the literal vertically.
Returns
- string
The literal.
Type Parameters
TKey
TValue
Namespace(params string[])
Generates a valid C# namespace from the specified parts.
string Namespace(params string[] name)
Parameters
name
string[]The base parts of the namespace.
Returns
- string
The namespace.
Reference(Type, bool?)
Generates a C# type reference.
string Reference(Type type, bool? fullName = null)
Parameters
Returns
- string
The reference.
Statement(Expression, ISet<string>)
Translates a node representing a statement into source code that would produce it.
[EntityFrameworkInternal]
string Statement(Expression node, ISet<string> collectedNamespaces)
Parameters
node
ExpressionThe node to be translated.
collectedNamespaces
ISet<string>Any namespaces required by the translated code will be added to this set.
Returns
- string
Source code that would produce
node
.
Remarks
This is an internal API that supports the Entity Framework Core infrastructure and not subject to the same compatibility standards as public APIs. It may be changed or removed without notice in any release. You should only use it directly in your code with extreme caution and knowing that doing so can result in application failures when updating to a new Entity Framework Core release.
UnknownLiteral(object?)
Generates a literal for a type not known at compile time.
string UnknownLiteral(object? value)
Parameters
value
objectThe value.
Returns
- string
The literal.
XmlComment(string, int)
Generates an XML documentation comment. Handles escaping and newlines.
string XmlComment(string comment, int indent = 0)
Parameters
comment
stringThe comment.
indent
intThe indentation level to use when multiple lines are generated.
Returns
- string
The comment.