CSharpEditor  1.1.2
A C# source code editor with syntax highlighting, intelligent code completion and real-time compilation error checking
CSharpEditor.Editor Class Reference

A C# source code editor for Avalonia. More...

Inheritance diagram for CSharpEditor.Editor:

Public Types

enum  AccessTypes { AccessTypes.ReadWrite, AccessTypes.ReadOnlyWithHistoryAndErrors, AccessTypes.ReadOnly }
 Describes the actions that the user can perform on the code. More...
 

Public Member Functions

 Editor ()
 Public constructor. This is only provided for compatibility with Avalonia (see issue #2593). Please use Editor.Create instead. More...
 
async Task SetText (string text)
 Sets the text of the document. More...
 
async Task SetText (SourceText text)
 Sets the text of the document. More...
 
bool SynchronousBreak (BreakpointInfo info)
 A function to handle breakpoints in synchronous methods. Pass this as an argument to Compile(Func<BreakpointInfo, bool>, Func<BreakpointInfo, Task<bool>>). To prevent deadlocks, this function will have no effect if called from the UI thread. More...
 
async Task< bool > AsynchronousBreak (BreakpointInfo info)
 A function to handle breakpoints in asynchronous methods. Pass this as an argument to Compile(Func<BreakpointInfo, bool>, Func<BreakpointInfo, Task<bool>>). More...
 
async Task<(Assembly Assembly, CSharpCompilation Compilation)> Compile (Func< BreakpointInfo, bool > synchronousBreak=null, Func< BreakpointInfo, Task< bool >> asynchronousBreak=null)
 Compile the source code to an Assembly. More...
 
async Task< CSharpCompilation > CreateCompilation ()
 Compile the source code to a CSharpCompilation. Note that breakpoints will be disabled. More...
 
void Save ()
 Add the current text of the document to the save history (if enabled) and invoke the SaveRequested event. More...
 

Static Public Member Functions

static async Task< EditorCreate (string initialText="", string preSource="", string postSource="", IEnumerable< CachedMetadataReference > references=null, CSharpCompilationOptions compilationOptions=null, string guid=null, Shortcut[] additionalShortcuts=null)
 Create a new Editor instance. More...
 

Public Attributes

SyntaxHighlightingModes SyntaxHighlightingMode => this.EditorControl.SyntaxHighlightingMode
 The current syntax highlighting mode. More...
 
bool ShowLineChanges => this.EditorControl.ShowLineChanges
 A boolean value indicating whether changed lines are highlighted on the left side of the control. More...
 
bool ShowScrollbarOverview => this.EditorControl.ShowScrollbarOverview
 A boolean value indicating whether a summary of the changed lines, errors/warning, search results, breakpoints and the position of the caret should be shown over the vertical scrollbar. More...
 
int AutosaveInterval => this.AutoSaver.MillisecondsInterval
 The timeout between consecutive autosaves, in milliseconds. More...
 
int CompilationTimeout => this.CompilationErrorChecker.MillisecondsInterval
 The timeout for automatic compilation after the user stops typing, in milliseconds. More...
 

Properties

EventHandler< EventArgs > TextChanged
 Event raised when the document text is changed. More...
 
string PreSource [get]
 Source code to be prepended to the text of the document when compiling it. More...
 
string PostSource = "" [get]
 Source code to be appended after the text of the document when compiling it. More...
 
string Text [get]
 The source code of the document as a string. More...
 
SourceText SourceText [get]
 The source code of the document as a SourceText. More...
 
string FullSource [get]
 Full source code, including the PreSource, the Text, and the PostSource. More...
 
AccessTypes AccessType [get, set]
 Determines whether the text of the document can be edited by the user. More...
 
CSharpCompilationOptions CompilationOptions [get]
 Compilation options used to compile the source code. More...
 
string Guid [get]
 A unique identifier for the document being edited. More...
 
string SaveDirectory [get]
 The full path to the directory where the autosave file and the save history for the current document are kept. More...
 
string AutoSaveFile [get]
 The full path to the autosave file. More...
 
bool KeepSaveHistory = true [get]
 A boolean value indicating whether a history of the saved versions of the document is kept. More...
 
bool AutoOpenSuggestions = true [get]
 A boolean value indicating whether the suggestion panel should open automatically while the user is typing. More...
 
bool AutoOpenParameters = true [get]
 A boolean value indicating whether the parameter list tooltip should open automatically while the user is typing. More...
 
bool AutoFormat = true [get]
 A boolean value indicating whether the source text should be formatted automatically while the user is typing. More...
 
ImmutableList< MetadataReference > References [get]
 The list of MetadataReferences for which the compiled assembly will have bindings. More...
 
bool IsReferencesButtonEnabled [get, set]
 A boolean value indicating whether the button allowing the user to add or remove assembly references is enabled or not. More...
 
TextSpan Selection [get, set]
 Gets or sets the selected text span. More...
 

Events

EventHandler< SaveEventArgsSaveRequested
 Event raised when the user uses the keyboard shortcut or pressed the button to save the document. More...
 
EventHandler< SaveEventArgsAutosave
 Event raised when the document is automatically saved. More...
 
EventHandler< CompilationEventArgsCompilationCompleted
 Event raised when a background compilation of the document completes. More...
 

Detailed Description

A C# source code editor for Avalonia.

Definition at line 43 of file Editor.axaml.cs.

Member Enumeration Documentation

◆ AccessTypes

Describes the actions that the user can perform on the code.

Enumerator
ReadWrite 

The code can be edited freely.

ReadOnlyWithHistoryAndErrors 

The code cannot be edited, but the list of errors and warnings is displayed, and the user can load previous versions of the file.

ReadOnly 

The code can only be read. No advanced features are provided beyond syntax highlighting.

Definition at line 138 of file Editor.public.cs.

Constructor & Destructor Documentation

◆ Editor()

CSharpEditor.Editor.Editor ( )

Public constructor. This is only provided for compatibility with Avalonia (see issue #2593). Please use Editor.Create instead.

Definition at line 133 of file Editor.axaml.cs.

Member Function Documentation

◆ AsynchronousBreak()

async Task<bool> CSharpEditor.Editor.AsynchronousBreak ( BreakpointInfo  info)

A function to handle breakpoints in asynchronous methods. Pass this as an argument to Compile(Func<BreakpointInfo, bool>, Func<BreakpointInfo, Task<bool>>).

Parameters
infoA BreakpointInfo object containing information about the location of the breakpoint and the current value of local variables.
Returns
A Task that completes when code execution resumes after the breakpoint.

Definition at line 452 of file Editor.public.cs.

◆ Compile()

async Task<(Assembly Assembly, CSharpCompilation Compilation)> CSharpEditor.Editor.Compile ( Func< BreakpointInfo, bool >  synchronousBreak = null,
Func< BreakpointInfo, Task< bool >>  asynchronousBreak = null 
)

Compile the source code to an Assembly.

Parameters
synchronousBreakThe function to handle synchronous breakpoints. If this is null, these breakpoints will be skipped. If you want to enable the default UI for breakpoints, use SynchronousBreak(BreakpointInfo) (or a function that calls it after performing additional operations).
asynchronousBreakThe function to handle asynchronous breakpoints. If this is null, these breakpoints will be skipped. If you want to enable the default UI for breakpoints, use AsynchronousBreak(BreakpointInfo) (or a function that calls it after performing additional operations).
Returns
An Assembly containing the compiled code, or null if the compilation fails, as well as a CSharpCompilation that also contains information about any compilation errors.

Definition at line 563 of file Editor.public.cs.

◆ Create()

static async Task<Editor> CSharpEditor.Editor.Create ( string  initialText = "",
string  preSource = "",
string  postSource = "",
IEnumerable< CachedMetadataReference references = null,
CSharpCompilationOptions  compilationOptions = null,
string  guid = null,
Shortcut[]  additionalShortcuts = null 
)
static

Create a new Editor instance.

Parameters
initialTextThe initial text of the editor.
preSourceThe source code that should be prepended to the text of the document when compiling it.
postSourceThe source code that should be appended to the text of the document when compiling it.
referencesA list of MetadataReferences for which the compiled assembly will have bindings. Make sure to include an appropriate DocumentationProvider, if you would like documentation comments to appear in code completion windows. If this is null, references to all of the assemblies loaded in the current AppDomain will be added.
compilationOptionsThe compilation options used to compile the code. If this is null, a new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary) will be used.
guidA unique identifier for the document being edited. If this is null, a new System.Guid is generated. If the same identifier is used multiple times, the save history of the document will be available, even if the application has been closed between different sessions.
additionalShortcutsAdditional application-specific shortcuts (for display purposes only - you need to implement your own logic).
Returns
A fully initialised Editor instance.

Definition at line 328 of file Editor.public.cs.

◆ CreateCompilation()

async Task<CSharpCompilation> CSharpEditor.Editor.CreateCompilation ( )

Compile the source code to a CSharpCompilation. Note that breakpoints will be disabled.

Returns
A CSharpCompilation containing the compiled code, which can be used to Emit an assembly.

Definition at line 701 of file Editor.public.cs.

◆ Save()

void CSharpEditor.Editor.Save ( )

Add the current text of the document to the save history (if enabled) and invoke the SaveRequested event.

Definition at line 729 of file Editor.public.cs.

◆ SetText() [1/2]

async Task CSharpEditor.Editor.SetText ( SourceText  text)

Sets the text of the document.

Parameters
textThe new text of the document.
Returns
A Task that completes when the text has been updated.

Definition at line 394 of file Editor.public.cs.

◆ SetText() [2/2]

async Task CSharpEditor.Editor.SetText ( string  text)

Sets the text of the document.

Parameters
textThe new text of the document.
Returns
A Task that completes when the text has been updated.

Definition at line 384 of file Editor.public.cs.

◆ SynchronousBreak()

bool CSharpEditor.Editor.SynchronousBreak ( BreakpointInfo  info)

A function to handle breakpoints in synchronous methods. Pass this as an argument to Compile(Func<BreakpointInfo, bool>, Func<BreakpointInfo, Task<bool>>). To prevent deadlocks, this function will have no effect if called from the UI thread.

Parameters
infoA BreakpointInfo object containing information about the location of the breakpoint and the current value of local variables.
Returns
true if further occurrences of the same breakpoint should be ignored; false otherwise.

Definition at line 405 of file Editor.public.cs.

Member Data Documentation

◆ AutosaveInterval

int CSharpEditor.Editor.AutosaveInterval => this.AutoSaver.MillisecondsInterval

The timeout between consecutive autosaves, in milliseconds.

Definition at line 260 of file Editor.public.cs.

◆ CompilationTimeout

int CSharpEditor.Editor.CompilationTimeout => this.CompilationErrorChecker.MillisecondsInterval

The timeout for automatic compilation after the user stops typing, in milliseconds.

Definition at line 265 of file Editor.public.cs.

◆ ShowLineChanges

bool CSharpEditor.Editor.ShowLineChanges => this.EditorControl.ShowLineChanges

A boolean value indicating whether changed lines are highlighted on the left side of the control.

Definition at line 250 of file Editor.public.cs.

◆ ShowScrollbarOverview

bool CSharpEditor.Editor.ShowScrollbarOverview => this.EditorControl.ShowScrollbarOverview

A boolean value indicating whether a summary of the changed lines, errors/warning, search results, breakpoints and the position of the caret should be shown over the vertical scrollbar.

Definition at line 255 of file Editor.public.cs.

◆ SyntaxHighlightingMode

SyntaxHighlightingModes CSharpEditor.Editor.SyntaxHighlightingMode => this.EditorControl.SyntaxHighlightingMode

The current syntax highlighting mode.

Definition at line 245 of file Editor.public.cs.

Property Documentation

◆ AccessType

AccessTypes CSharpEditor.Editor.AccessType
getset

Determines whether the text of the document can be edited by the user.

Definition at line 161 of file Editor.public.cs.

◆ AutoFormat

bool CSharpEditor.Editor.AutoFormat = true
get

A boolean value indicating whether the source text should be formatted automatically while the user is typing.

Definition at line 240 of file Editor.public.cs.

◆ AutoOpenParameters

bool CSharpEditor.Editor.AutoOpenParameters = true
get

A boolean value indicating whether the parameter list tooltip should open automatically while the user is typing.

Definition at line 235 of file Editor.public.cs.

◆ AutoOpenSuggestions

bool CSharpEditor.Editor.AutoOpenSuggestions = true
get

A boolean value indicating whether the suggestion panel should open automatically while the user is typing.

Definition at line 230 of file Editor.public.cs.

◆ AutoSaveFile

string CSharpEditor.Editor.AutoSaveFile
get

The full path to the autosave file.

Definition at line 220 of file Editor.public.cs.

◆ CompilationOptions

CSharpCompilationOptions CSharpEditor.Editor.CompilationOptions
get

Compilation options used to compile the source code.

Definition at line 205 of file Editor.public.cs.

◆ FullSource

string CSharpEditor.Editor.FullSource
get

Full source code, including the PreSource, the Text, and the PostSource.

Definition at line 126 of file Editor.public.cs.

◆ Guid

string CSharpEditor.Editor.Guid
get

A unique identifier for the document being edited.

Definition at line 210 of file Editor.public.cs.

◆ IsReferencesButtonEnabled

bool CSharpEditor.Editor.IsReferencesButtonEnabled
getset

A boolean value indicating whether the button allowing the user to add or remove assembly references is enabled or not.

Definition at line 277 of file Editor.public.cs.

◆ KeepSaveHistory

bool CSharpEditor.Editor.KeepSaveHistory = true
get

A boolean value indicating whether a history of the saved versions of the document is kept.

Definition at line 225 of file Editor.public.cs.

◆ PostSource

string CSharpEditor.Editor.PostSource = ""
get

Source code to be appended after the text of the document when compiling it.

Definition at line 97 of file Editor.public.cs.

◆ PreSource

string CSharpEditor.Editor.PreSource
get

Source code to be prepended to the text of the document when compiling it.

Definition at line 80 of file Editor.public.cs.

◆ References

ImmutableList<MetadataReference> CSharpEditor.Editor.References
get

The list of MetadataReferences for which the compiled assembly will have bindings.

Definition at line 270 of file Editor.public.cs.

◆ SaveDirectory

string CSharpEditor.Editor.SaveDirectory
get

The full path to the directory where the autosave file and the save history for the current document are kept.

Definition at line 215 of file Editor.public.cs.

◆ Selection

TextSpan CSharpEditor.Editor.Selection
getset

Gets or sets the selected text span.

Definition at line 304 of file Editor.public.cs.

◆ SourceText

SourceText CSharpEditor.Editor.SourceText
get

The source code of the document as a SourceText.

Definition at line 114 of file Editor.public.cs.

◆ Text

string CSharpEditor.Editor.Text
get

The source code of the document as a string.

Definition at line 102 of file Editor.public.cs.

◆ TextChanged

EventHandler<EventArgs> CSharpEditor.Editor.TextChanged
addremove

Event raised when the document text is changed.

Definition at line 62 of file Editor.public.cs.

Event Documentation

◆ Autosave

EventHandler<SaveEventArgs> CSharpEditor.Editor.Autosave

Event raised when the document is automatically saved.

Definition at line 52 of file Editor.public.cs.

◆ CompilationCompleted

EventHandler<CompilationEventArgs> CSharpEditor.Editor.CompilationCompleted

Event raised when a background compilation of the document completes.

Definition at line 57 of file Editor.public.cs.

◆ SaveRequested

EventHandler<SaveEventArgs> CSharpEditor.Editor.SaveRequested

Event raised when the user uses the keyboard shortcut or pressed the button to save the document.

Definition at line 47 of file Editor.public.cs.


The documentation for this class was generated from the following files: