Table of Contents

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 Expression

The 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 AttributeCodeFragment

The 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 IMethodCallCodeFragment

The method call. If null, no code is generated.

indent int

The 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 IMethodCallCodeFragment

The method call.

instanceIdentifier string

An identifier on which the method call will be generated.

typeQualified bool

true 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 NestedClosureCodeFragment

The lambda.

indent int

The 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 PropertyAccessorCodeFragment

The 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 Type

The 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 string

The 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 string

The 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 string

The identifier to use for parameter in the lambda.

Returns

string

The lambda.

Literal(bool)

Generates a bool literal.

string Literal(bool value)

Parameters

value bool

The value.

Returns

string

The literal.

Literal(byte)

Generates a byte literal.

string Literal(byte value)

Parameters

value byte

The value.

Returns

string

The literal.

Literal(char)

Generates a char literal.

string Literal(char value)

Parameters

value char

The value.

Returns

string

The literal.

Literal(DateOnly)

Generates a DateOnly literal.

string Literal(DateOnly value)

Parameters

value DateOnly

The value.

Returns

string

The literal.

Literal(DateTime)

Generates a DateTime literal.

string Literal(DateTime value)

Parameters

value DateTime

The value.

Returns

string

The literal.

Literal(DateTimeOffset)

Generates a DateTimeOffset literal.

string Literal(DateTimeOffset value)

Parameters

value DateTimeOffset

The value.

Returns

string

The literal.

Literal(decimal)

Generates a decimal literal.

string Literal(decimal value)

Parameters

value decimal

The value.

Returns

string

The literal.

Literal(double)

Generates a double literal.

string Literal(double value)

Parameters

value double

The value.

Returns

string

The literal.

Literal(Enum, bool)

Generates an enum literal.

string Literal(Enum value, bool fullName = false)

Parameters

value Enum

The value.

fullName bool

Whether the type should be namespace-qualified.

Returns

string

The literal.

Literal(Guid)

Generates a Guid literal.

string Literal(Guid value)

Parameters

value Guid

The value.

Returns

string

The literal.

Literal(short)

Generates a short literal.

string Literal(short value)

Parameters

value short

The value.

Returns

string

The literal.

Literal(int)

Generates an int literal.

string Literal(int value)

Parameters

value int

The value.

Returns

string

The literal.

Literal(long)

Generates a long literal.

string Literal(long value)

Parameters

value long

The value.

Returns

string

The literal.

Literal(BigInteger)

Generates a BigInteger literal.

string Literal(BigInteger value)

Parameters

value BigInteger

The 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 sbyte

The value.

Returns

string

The literal.

Literal(float)

Generates a float literal.

string Literal(float value)

Parameters

value float

The value.

Returns

string

The literal.

Literal(string?)

Generates a string literal.

string Literal(string? value)

Parameters

value string

The value.

Returns

string

The literal.

Literal(TimeOnly)

Generates a TimeOnly literal.

string Literal(TimeOnly value)

Parameters

value TimeOnly

The value.

Returns

string

The literal.

Literal(TimeSpan)

Generates a TimeSpan literal.

string Literal(TimeSpan value)

Parameters

value TimeSpan

The value.

Returns

string

The literal.

Literal(Type, bool?)

Generates a Type literal.

string Literal(Type value, bool? fullName = null)

Parameters

value Type

The value.

fullName bool?

Whether the type should be namespace-qualified.

Returns

string

The literal.

Literal(ushort)

Generates a ushort literal.

string Literal(ushort value)

Parameters

value ushort

The value.

Returns

string

The literal.

Literal(uint)

Generates a uint literal.

string Literal(uint value)

Parameters

value uint

The value.

Returns

string

The literal.

Literal(ulong)

Generates a ulong literal.

string Literal(ulong value)

Parameters

value ulong

The value.

Returns

string

The literal.

Literal<T>(List<T>, bool)

Generates a list literal.

string Literal<T>(List<T> values, bool vertical = false)

Parameters

values List<T>

The list.

vertical bool

A value indicating whether to layout the literal vertically.

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 bool

A 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 bool

A 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

type Type

The type to reference.

fullName bool?

Whether the type should be namespace-qualified.

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 Expression

The 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 object

The 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 string

The comment.

indent int

The indentation level to use when multiple lines are generated.

Returns

string

The comment.