Class CsSourceExtensions
Extensions class that provides common automation tasks rolled up under standard extension methods that support the CsSource model.
Inherited Members
Namespace: CodeFactory.DotNet.CSharp
Assembly: CodeFactory.DotNet.dll
Syntax
public static class CsSourceExtensions
Methods
| Improve this Doc View SourceAddMissingNamespaces(CsSource, IEnumerable<CsMember>, string)
Scans members for types that are accessible at the member definition level. If the namespace is missing will add it to the source code file.
Declaration
public static Task<CsSource> AddMissingNamespaces(this CsSource source, IEnumerable<CsMember> members, string excludeNamespace = null)
Parameters
Type | Name | Description |
---|---|---|
CsSource | source | The source model to be updated. |
IEnumerable<CsMember> | members | The members to be checked for type definitions. |
string | excludeNamespace | A target namespace that should be excluded from adding to the using statement list. This is generally the target namespace of the code file. This is optional |
Returns
Type | Description |
---|---|
Task<CsSource> | Updated Source Model with all the missing namespaces added as using statements. |
AddUsingStatementAsync(CsSource, string, string)
Extension method that will add a using statement to target source code. If the using statement already exists it will simply return the existing source.
Declaration
public static Task<CsSource> AddUsingStatementAsync(this CsSource source, string nameSpace, string alias = null)
Parameters
Type | Name | Description |
---|---|---|
CsSource | source | The source code to update. |
string | nameSpace | The namespace to be added to the using statement. |
string | alias | Optional parameter to set if you want an alias assigned to the namespace. |
Returns
Type | Description |
---|---|
Task<CsSource> | The updated source code or the original source code if no changes were necessary. |
HasUsingStatement(CsSource, string, string)
Extension method that determines if the source code has a target namespace as a using statement.
Declaration
public static bool HasUsingStatement(this CsSource source, string nameSpace, string alias = null)
Parameters
Type | Name | Description |
---|---|---|
CsSource | source | The source code to search through. |
string | nameSpace | The namespace to search for in the using statements. |
string | alias | Optional parameter that captures the alias of the namespace used in the using statement. |
Returns
Type | Description |
---|---|
bool | Flag that determines if it has the using statement. |