diff --git a/Scintilla.NET/AutoCSelectionChangeEventArgs.cs b/Scintilla.NET/AutoCSelectionChangeEventArgs.cs index 459ce87..99fce0d 100644 --- a/Scintilla.NET/AutoCSelectionChangeEventArgs.cs +++ b/Scintilla.NET/AutoCSelectionChangeEventArgs.cs @@ -1,7 +1,4 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; namespace ScintillaNET { @@ -30,10 +27,9 @@ public int Position { get { - if (position == null) - position = scintilla.Lines.ByteToCharPosition(bytePosition); + this.position ??= this.scintilla.Lines.ByteToCharPosition(this.bytePosition); - return (int)position; + return (int)this.position; } } @@ -45,16 +41,16 @@ public unsafe string Text { get { - if (text == null) + if (this.text == null) { - var len = 0; - while (((byte*)textPtr)[len] != 0) + int len = 0; + while (((byte*)this.textPtr)[len] != 0) len++; - text = Helpers.GetString(textPtr, len, scintilla.Encoding); + this.text = Helpers.GetString(this.textPtr, len, this.scintilla.Encoding); } - return text; + return this.text; } } diff --git a/Scintilla.NET/AutoCSelectionEventArgs.cs b/Scintilla.NET/AutoCSelectionEventArgs.cs index 20e229e..136712a 100644 --- a/Scintilla.NET/AutoCSelectionEventArgs.cs +++ b/Scintilla.NET/AutoCSelectionEventArgs.cs @@ -35,10 +35,9 @@ public int Position { get { - if (position == null) - position = scintilla.Lines.ByteToCharPosition(bytePosition); + this.position ??= this.scintilla.Lines.ByteToCharPosition(this.bytePosition); - return (int)position; + return (int)this.position; } } @@ -50,16 +49,16 @@ public unsafe string Text { get { - if (text == null) + if (this.text == null) { - var len = 0; - while (((byte*)textPtr)[len] != 0) + int len = 0; + while (((byte*)this.textPtr)[len] != 0) len++; - text = Helpers.GetString(textPtr, len, scintilla.Encoding); + this.text = Helpers.GetString(this.textPtr, len, this.scintilla.Encoding); } - return text; + return this.text; } } diff --git a/Scintilla.NET/BeforeModificationEventArgs.cs b/Scintilla.NET/BeforeModificationEventArgs.cs index 0ddeabb..ff5ff62 100644 --- a/Scintilla.NET/BeforeModificationEventArgs.cs +++ b/Scintilla.NET/BeforeModificationEventArgs.cs @@ -23,8 +23,7 @@ public int Position { get { - if (CachedPosition == null) - CachedPosition = scintilla.Lines.ByteToCharPosition(bytePosition); + CachedPosition ??= this.scintilla.Lines.ByteToCharPosition(this.bytePosition); return (int)CachedPosition; } @@ -42,7 +41,7 @@ public int Position /// /// The text about to be inserted or deleted. /// - public unsafe virtual string Text + public virtual unsafe string Text { get { @@ -50,14 +49,14 @@ public unsafe virtual string Text { // For some reason the Scintilla overlords don't provide text in // SC_MOD_BEFOREDELETE... but we can get it from the document. - if (textPtr == IntPtr.Zero) + if (this.textPtr == IntPtr.Zero) { - var ptr = scintilla.DirectMessage(NativeMethods.SCI_GETRANGEPOINTER, new IntPtr(bytePosition), new IntPtr(byteLength)); - CachedText = new string((sbyte*)ptr, 0, byteLength, scintilla.Encoding); + IntPtr ptr = this.scintilla.DirectMessage(NativeMethods.SCI_GETRANGEPOINTER, new IntPtr(this.bytePosition), new IntPtr(this.byteLength)); + CachedText = new string((sbyte*)ptr, 0, this.byteLength, this.scintilla.Encoding); } else { - CachedText = Helpers.GetString(textPtr, byteLength, scintilla.Encoding); + CachedText = Helpers.GetString(this.textPtr, this.byteLength, this.scintilla.Encoding); } } diff --git a/Scintilla.NET/CallTipClickEventArgs.cs b/Scintilla.NET/CallTipClickEventArgs.cs index a2cdca8..26668ae 100644 --- a/Scintilla.NET/CallTipClickEventArgs.cs +++ b/Scintilla.NET/CallTipClickEventArgs.cs @@ -5,7 +5,7 @@ namespace ScintillaNET; /// /// Provides data for the event. /// -public class CallTipClickEventArgs: EventArgs +public class CallTipClickEventArgs : EventArgs { private readonly Scintilla scintilla; diff --git a/Scintilla.NET/CaretStyle.cs b/Scintilla.NET/CaretStyle.cs index 7ed94e0..137c227 100644 --- a/Scintilla.NET/CaretStyle.cs +++ b/Scintilla.NET/CaretStyle.cs @@ -1,23 +1,22 @@ namespace ScintillaNET; +/// +/// The caret visual style. +/// +public enum CaretStyle +{ /// - /// The caret visual style. + /// The caret is not displayed. /// - public enum CaretStyle - { - /// - /// The caret is not displayed. - /// - Invisible = NativeMethods.CARETSTYLE_INVISIBLE, + Invisible = NativeMethods.CARETSTYLE_INVISIBLE, - /// - /// The caret is drawn as a vertical line. - /// - Line = NativeMethods.CARETSTYLE_LINE, - - /// - /// The caret is drawn as a block. - /// - Block = NativeMethods.CARETSTYLE_BLOCK - } + /// + /// The caret is drawn as a vertical line. + /// + Line = NativeMethods.CARETSTYLE_LINE, + /// + /// The caret is drawn as a block. + /// + Block = NativeMethods.CARETSTYLE_BLOCK +} diff --git a/Scintilla.NET/ChangeHistory.cs b/Scintilla.NET/ChangeHistory.cs index e7f9cfa..41c1824 100644 --- a/Scintilla.NET/ChangeHistory.cs +++ b/Scintilla.NET/ChangeHistory.cs @@ -1,8 +1,4 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace ScintillaNET; diff --git a/Scintilla.NET/Document.cs b/Scintilla.NET/Document.cs index e56b706..82e309b 100644 --- a/Scintilla.NET/Document.cs +++ b/Scintilla.NET/Document.cs @@ -25,7 +25,7 @@ public struct Document /// true if is an instance of and equals the value of this instance; otherwise, false. public override bool Equals(object obj) { - return (obj is IntPtr) && Value == ((Document)obj).Value; + return obj is IntPtr && this.Value == ((Document)obj).Value; } /// @@ -34,7 +34,7 @@ public override bool Equals(object obj) /// A 32-bit signed integer hash code. public override int GetHashCode() { - return Value.GetHashCode(); + return this.Value.GetHashCode(); } /// diff --git a/Scintilla.NET/DoubleClickEventArgs.cs b/Scintilla.NET/DoubleClickEventArgs.cs index 02a9367..960fa3a 100644 --- a/Scintilla.NET/DoubleClickEventArgs.cs +++ b/Scintilla.NET/DoubleClickEventArgs.cs @@ -35,10 +35,9 @@ public int Position { get { - if (position == null) - position = scintilla.Lines.ByteToCharPosition(bytePosition); + this.position ??= this.scintilla.Lines.ByteToCharPosition(this.bytePosition); - return (int)position; + return (int)this.position; } } @@ -57,6 +56,6 @@ public DoubleClickEventArgs(Scintilla scintilla, Keys modifiers, int bytePositio Line = line; if (bytePosition == -1) - position = -1; + this.position = -1; } } \ No newline at end of file diff --git a/Scintilla.NET/DwellEventArgs.cs b/Scintilla.NET/DwellEventArgs.cs index 2212509..2896657 100644 --- a/Scintilla.NET/DwellEventArgs.cs +++ b/Scintilla.NET/DwellEventArgs.cs @@ -19,10 +19,9 @@ public int Position { get { - if (position == null) - position = scintilla.Lines.ByteToCharPosition(bytePosition); + this.position ??= this.scintilla.Lines.ByteToCharPosition(this.bytePosition); - return (int)position; + return (int)this.position; } } @@ -54,6 +53,6 @@ public DwellEventArgs(Scintilla scintilla, int bytePosition, int x, int y) // The position is not over text if (bytePosition < 0) - position = bytePosition; + this.position = bytePosition; } } \ No newline at end of file diff --git a/Scintilla.NET/FlagsConverter.cs b/Scintilla.NET/FlagsConverter.cs index 7fc2201..57b818c 100644 --- a/Scintilla.NET/FlagsConverter.cs +++ b/Scintilla.NET/FlagsConverter.cs @@ -28,6 +28,7 @@ public override object ConvertTo(ITypeDescriptorContext context, CultureInfo cul { return Enum.ToObject(enumType, 0).ToString(); } + ulong bits = 0; List enums = []; var items = Enum.GetValues(enumType).Cast() @@ -46,7 +47,7 @@ public override object ConvertTo(ITypeDescriptorContext context, CultureInfo cul (x.item.bits < y.item.bits) ? -1 : (x.item.bits > y.item.bits ? 1 : 0) // With the highest integer value ); - var item = items[maxIndex]; + (Enum @enum, ulong bits, byte bitCount) item = items[maxIndex]; if ((valueBits & item.bits) == item.bits && (bits & item.bits) != item.bits) { @@ -55,9 +56,11 @@ public override object ConvertTo(ITypeDescriptorContext context, CultureInfo cul enums.Add(item.@enum); } } + enums.Sort(); return string.Join(" | ", enums); } + return base.ConvertTo(context, culture, value, destinationType); } @@ -67,13 +70,15 @@ public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo c { Type t = context.PropertyDescriptor.PropertyType; ulong bits = 0; - var nameList = str.Split('|').Select(x => x.Trim()); - foreach (var name in nameList) + IEnumerable nameList = str.Split('|').Select(x => x.Trim()); + foreach (string name in nameList) { bits |= Convert.ToUInt64(Enum.Parse(t, name)); } + return Enum.ToObject(t, bits); } + return base.ConvertFrom(context, culture, value); } } diff --git a/Scintilla.NET/FlagsEditor.cs b/Scintilla.NET/FlagsEditor.cs index 2ff613e..939e949 100644 --- a/Scintilla.NET/FlagsEditor.cs +++ b/Scintilla.NET/FlagsEditor.cs @@ -16,13 +16,15 @@ public override object EditValue(ITypeDescriptorContext context, IServiceProvide { if (value is Enum e && context.PropertyDescriptor.Attributes.OfType().Any()) { - IWindowsFormsEditorService svc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService)); + var svc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService)); var control = new FlagsEditorControl(svc, e); svc.DropDownControl(control); return control.Value; } else + { return base.EditValue(context, provider, value); + } } } diff --git a/Scintilla.NET/FlagsEditorControl.cs b/Scintilla.NET/FlagsEditorControl.cs index 649c50f..9610a29 100644 --- a/Scintilla.NET/FlagsEditorControl.cs +++ b/Scintilla.NET/FlagsEditorControl.cs @@ -11,15 +11,15 @@ internal partial class FlagsEditorControl : UserControl public FlagsEditorControl() { InitializeComponent(); - button_Ok.Text = NativeMethods.GetMessageBoxString(0); - button_Cancel.Text = NativeMethods.GetMessageBoxString(1); + this.button_Ok.Text = NativeMethods.GetMessageBoxString(0); + this.button_Cancel.Text = NativeMethods.GetMessageBoxString(1); } private readonly Type enumType; private readonly Enum initialValue; public Enum Value { get; protected set; } - private IWindowsFormsEditorService editorService; + private readonly IWindowsFormsEditorService editorService; private int inCheck; @@ -27,18 +27,18 @@ public FlagsEditorControl(IWindowsFormsEditorService editorService, Enum value) { this.editorService = editorService; - enumType = value.GetType(); - Value = initialValue = value; + this.enumType = value.GetType(); + Value = this.initialValue = value; - inCheck++; + this.inCheck++; try { - ulong allBits = CalculateEnumAllValue(enumType); + ulong allBits = CalculateEnumAllValue(this.enumType); bool hasAll = false; ulong valueBits = Convert.ToUInt64(Value); - foreach (string itemName in Enum.GetNames(enumType)) + foreach (string itemName in Enum.GetNames(this.enumType)) { - Enum item = (Enum)Enum.Parse(enumType, itemName); + var item = (Enum)Enum.Parse(this.enumType, itemName); ulong itemBits = Convert.ToUInt64(item); if (itemBits == allBits) hasAll = true; @@ -54,28 +54,30 @@ public FlagsEditorControl(IWindowsFormsEditorService editorService, Enum value) UseVisualStyleBackColor = true, }; checkBox.CheckStateChanged += checkBox_CheckStateChanged; - flowLayoutPanel_CheckBoxList.Controls.Add(checkBox); + this.flowLayoutPanel_CheckBoxList.Controls.Add(checkBox); } } + if (!hasAll) { var checkBox = new CheckBox() { Text = "All", CheckState = CheckStateFromBits(allBits, valueBits), AutoSize = true, - Tag = (Enum)Enum.ToObject(enumType, allBits), + Tag = (Enum)Enum.ToObject(this.enumType, allBits), Margin = new Padding(3, 0, 3, 0), Padding = Padding.Empty, UseVisualStyleBackColor = true, }; checkBox.CheckStateChanged += checkBox_CheckStateChanged; - flowLayoutPanel_CheckBoxList.Controls.Add(checkBox); + this.flowLayoutPanel_CheckBoxList.Controls.Add(checkBox); } - this.AutoSize = true; + + AutoSize = true; } finally { - inCheck--; + this.inCheck--; } } @@ -86,6 +88,7 @@ private static ulong CalculateEnumAllValue(Type enumType) { all |= Convert.ToUInt64(bits); } + return all; } @@ -96,34 +99,35 @@ private static ulong CombineEnumBits(IEnumerable checkBoxList) { bits |= Convert.ToUInt64(checkBox.Tag); } + return bits; } private void checkBox_CheckStateChanged(object sender, EventArgs e) { - if (inCheck > 0) + if (this.inCheck > 0) return; - inCheck++; + this.inCheck++; try { var checkTarget = (CheckBox)sender; - var checkBoxList = flowLayoutPanel_CheckBoxList.Controls.OfType(); + IEnumerable checkBoxList = this.flowLayoutPanel_CheckBoxList.Controls.OfType(); ulong valueBits = CombineEnumBits(checkBoxList); ulong changedBits = Convert.ToUInt64(checkTarget.Tag); if (checkTarget.CheckState == CheckState.Checked) valueBits |= changedBits; else if (checkTarget.CheckState == CheckState.Unchecked) valueBits &= ~changedBits; - Value = (Enum)Enum.ToObject(enumType, valueBits); + Value = (Enum)Enum.ToObject(this.enumType, valueBits); foreach (CheckBox checkBox in checkBoxList) { - var itemBits = Convert.ToUInt64(checkBox.Tag); + ulong itemBits = Convert.ToUInt64(checkBox.Tag); checkBox.CheckState = CheckStateFromBits(itemBits, valueBits); } } finally { - inCheck--; + this.inCheck--; } } @@ -136,25 +140,27 @@ protected override bool ProcessDialogKey(Keys keyData) { if (keyData == Keys.Return) { - button_Ok_Click(button_Ok, EventArgs.Empty); + button_Ok_Click(this.button_Ok, EventArgs.Empty); return true; } + if (keyData == Keys.Escape) { - button_Cancel_Click(button_Cancel, EventArgs.Empty); + button_Cancel_Click(this.button_Cancel, EventArgs.Empty); return true; } + return base.ProcessDialogKey(keyData); } private void button_Ok_Click(object sender, EventArgs e) { - editorService.CloseDropDown(); + this.editorService.CloseDropDown(); } private void button_Cancel_Click(object sender, EventArgs e) { - Value = initialValue; - editorService.CloseDropDown(); + Value = this.initialValue; + this.editorService.CloseDropDown(); } } diff --git a/Scintilla.NET/FlagsEnumConverter.cs b/Scintilla.NET/FlagsEnumConverter.cs index 83dbafa..e1d80bb 100644 --- a/Scintilla.NET/FlagsEnumConverter.cs +++ b/Scintilla.NET/FlagsEnumConverter.cs @@ -10,18 +10,18 @@ namespace FlagsEnumTypeConverter; /// /// Flags enumeration type converter. /// -internal class FlagsEnumConverter: EnumConverter +internal class FlagsEnumConverter : EnumConverter { /// /// This class represents an enumeration field in the property grid. /// - protected class EnumFieldDescriptor: SimplePropertyDescriptor + protected class EnumFieldDescriptor : SimplePropertyDescriptor { #region Fields /// /// Stores the context which the enumeration field descriptor was created in. /// - ITypeDescriptorContext fContext; + private readonly ITypeDescriptorContext fContext; #endregion #region Methods @@ -31,9 +31,9 @@ protected class EnumFieldDescriptor: SimplePropertyDescriptor /// The type of the enumeration. /// The name of the enumeration field. /// The current context. - public EnumFieldDescriptor(Type componentType, string name, ITypeDescriptorContext context): base(componentType, name, typeof(bool)) + public EnumFieldDescriptor(Type componentType, string name, ITypeDescriptorContext context) : base(componentType, name, typeof(bool)) { - fContext = context; + this.fContext = context; } /// @@ -48,7 +48,7 @@ public EnumFieldDescriptor(Type componentType, string name, ITypeDescriptorConte /// public override object GetValue(object component) { - var bits = Convert.ToUInt64(Enum.Parse(ComponentType, Name)); + ulong bits = Convert.ToUInt64(Enum.Parse(ComponentType, Name)); return (Convert.ToUInt64(component) & bits) == bits; } @@ -66,14 +66,14 @@ public override void SetValue(object component, object value) { bool myValue = (bool)value; ulong myNewValue; - if(myValue) + if (myValue) myNewValue = Convert.ToUInt64(component) | Convert.ToUInt64(Enum.Parse(ComponentType, Name)); else myNewValue = Convert.ToUInt64(component) & ~Convert.ToUInt64(Enum.Parse(ComponentType, Name)); - + FieldInfo myField = component.GetType().GetField("value__", BindingFlags.Instance | BindingFlags.Public); myField.SetValue(component, Convert.ChangeType(myNewValue, Enum.GetUnderlyingType(ComponentType))); - fContext.PropertyDescriptor.SetValue(fContext.Instance, component); + this.fContext.PropertyDescriptor.SetValue(this.fContext.Instance, component); } /// @@ -108,17 +108,17 @@ public override bool CanResetValue(object component) private bool GetDefaultValue() { object myDefaultValue = null; - string myPropertyName = fContext.PropertyDescriptor.Name; - Type myComponentType = fContext.PropertyDescriptor.ComponentType; + string myPropertyName = this.fContext.PropertyDescriptor.Name; + Type myComponentType = this.fContext.PropertyDescriptor.ComponentType; // Get DefaultValueAttribute - DefaultValueAttribute myDefaultValueAttribute = (DefaultValueAttribute)Attribute.GetCustomAttribute( - myComponentType.GetProperty(myPropertyName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic), + var myDefaultValueAttribute = (DefaultValueAttribute)Attribute.GetCustomAttribute( + myComponentType.GetProperty(myPropertyName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic), typeof(DefaultValueAttribute)); - if(myDefaultValueAttribute != null) + if (myDefaultValueAttribute != null) myDefaultValue = myDefaultValueAttribute.Value; - if(myDefaultValue != null) + if (myDefaultValue != null) return (Convert.ToUInt64(myDefaultValue) & Convert.ToUInt64(Enum.Parse(ComponentType, Name))) != 0; return false; } @@ -129,7 +129,7 @@ public override AttributeCollection Attributes { get { - return new AttributeCollection(new Attribute[]{RefreshPropertiesAttribute.Repaint}); + return new AttributeCollection(new Attribute[] { RefreshPropertiesAttribute.Repaint }); } } #endregion @@ -140,7 +140,7 @@ public override AttributeCollection Attributes /// Creates an instance of the FlagsEnumConverter class. /// /// The type of the enumeration. - public FlagsEnumConverter(Type type): base(type){} + public FlagsEnumConverter(Type type) : base(type) { } /// /// Retrieves the property descriptors for the enumeration fields. @@ -151,31 +151,34 @@ public FlagsEnumConverter(Type type): base(type){} /// A value of an enumeration type. public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object value, Attribute[] attributes) { - if(context != null) + if (context != null) { Type myType = value.GetType(); string[] myNames = Enum.GetNames(myType); Array myValues = Enum.GetValues(myType); - if(myNames != null) + if (myNames != null) { - PropertyDescriptorCollection myCollection = new PropertyDescriptorCollection(null); - for(int i = 0; i < myNames.Length; i++) + var myCollection = new PropertyDescriptorCollection(null); + for (int i = 0; i < myNames.Length; i++) { if (Convert.ToUInt64(myValues.GetValue(i)) != 0) myCollection.Add(new EnumFieldDescriptor(myType, myNames[i], context)); } + return myCollection; } } + return base.GetProperties(context, value, attributes); } public override bool GetPropertiesSupported(ITypeDescriptorContext context) { - if(context != null) + if (context != null) { return true; } + return base.GetPropertiesSupported(context); } diff --git a/Scintilla.NET/GapBuffer.cs b/Scintilla.NET/GapBuffer.cs index f691bf6..9cc25d9 100644 --- a/Scintilla.NET/GapBuffer.cs +++ b/Scintilla.NET/GapBuffer.cs @@ -26,22 +26,22 @@ public void AddRange(ICollection collection) private void EnsureGapCapacity(int length) { - if (length > (gapEnd - gapStart)) + if (length > this.gapEnd - this.gapStart) { // How much to grow the buffer is a tricky question. // Our current algo will double the capacity unless that's not enough. - var minCapacity = Count + length; - var newCapacity = (buffer.Length * 2); + int minCapacity = Count + length; + int newCapacity = this.buffer.Length * 2; if (newCapacity < minCapacity) { newCapacity = minCapacity; } var newBuffer = new T[newCapacity]; - var newGapEnd = newBuffer.Length - (buffer.Length - gapEnd); + int newGapEnd = newBuffer.Length - (this.buffer.Length - this.gapEnd); - Array.Copy(buffer, 0, newBuffer, 0, gapStart); - Array.Copy(buffer, gapEnd, newBuffer, newGapEnd, newBuffer.Length - newGapEnd); + Array.Copy(this.buffer, 0, newBuffer, 0, this.gapStart); + Array.Copy(this.buffer, this.gapEnd, newBuffer, newGapEnd, newBuffer.Length - newGapEnd); this.buffer = newBuffer; this.gapEnd = newGapEnd; } @@ -49,7 +49,7 @@ private void EnsureGapCapacity(int length) public IEnumerator GetEnumerator() { - var count = Count; + int count = Count; for (int i = 0; i < count; i++) yield return this[i]; @@ -58,7 +58,7 @@ public IEnumerator GetEnumerator() IEnumerator IEnumerable.GetEnumerator() { - return this.GetEnumerator(); + return GetEnumerator(); } public void Insert(int index, T item) @@ -66,54 +66,54 @@ public void Insert(int index, T item) PlaceGapStart(index); EnsureGapCapacity(1); - buffer[index] = item; - gapStart++; + this.buffer[index] = item; + this.gapStart++; } public void InsertRange(int index, ICollection collection) { - var count = collection.Count; + int count = collection.Count; if (count > 0) { PlaceGapStart(index); EnsureGapCapacity(count); - collection.CopyTo(buffer, gapStart); - gapStart += count; + collection.CopyTo(this.buffer, this.gapStart); + this.gapStart += count; } } private void PlaceGapStart(int index) { - if (index != gapStart) + if (index != this.gapStart) { - if ((gapEnd - gapStart) == 0) + if (this.gapEnd - this.gapStart == 0) { // There is no gap - gapStart = index; - gapEnd = index; + this.gapStart = index; + this.gapEnd = index; } - else if (index < gapStart) + else if (index < this.gapStart) { // Move gap left (copy contents right) - var length = (gapStart - index); - var deltaLength = (gapEnd - gapStart < length ? gapEnd - gapStart : length); - Array.Copy(buffer, index, buffer, gapEnd - length, length); - gapStart -= length; - gapEnd -= length; + int length = this.gapStart - index; + int deltaLength = this.gapEnd - this.gapStart < length ? this.gapEnd - this.gapStart : length; + Array.Copy(this.buffer, index, this.buffer, this.gapEnd - length, length); + this.gapStart -= length; + this.gapEnd -= length; - Array.Clear(buffer, index, deltaLength); + Array.Clear(this.buffer, index, deltaLength); } else { // Move gap right (copy contents left) - var length = (index - gapStart); - var deltaIndex = (index > gapEnd ? index : gapEnd); - Array.Copy(buffer, gapEnd, buffer, gapStart, length); - gapStart += length; - gapEnd += length; + int length = index - this.gapStart; + int deltaIndex = index > this.gapEnd ? index : this.gapEnd; + Array.Copy(this.buffer, this.gapEnd, this.buffer, this.gapStart, length); + this.gapStart += length; + this.gapEnd += length; - Array.Clear(buffer, deltaIndex, gapEnd - deltaIndex); + Array.Clear(this.buffer, deltaIndex, this.gapEnd - deltaIndex); } } } @@ -121,8 +121,8 @@ private void PlaceGapStart(int index) public void RemoveAt(int index) { PlaceGapStart(index); - buffer[gapEnd] = default(T); - gapEnd++; + this.buffer[this.gapEnd] = default; + this.gapEnd++; } public void RemoveRange(int index, int count) @@ -130,8 +130,8 @@ public void RemoveRange(int index, int count) if (count > 0) { PlaceGapStart(index); - Array.Clear(buffer, gapEnd, count); - gapEnd += count; + Array.Clear(this.buffer, this.gapEnd, count); + this.gapEnd += count; } } @@ -139,7 +139,7 @@ public int Count { get { - return buffer.Length - (gapEnd - gapStart); + return this.buffer.Length - (this.gapEnd - this.gapStart); } } @@ -159,23 +159,23 @@ public T this[int index] { get { - if (index < gapStart) - return buffer[index]; + if (index < this.gapStart) + return this.buffer[index]; - return buffer[index + (gapEnd - gapStart)]; + return this.buffer[index + (this.gapEnd - this.gapStart)]; } set { - if (index >= gapStart) - index += (gapEnd - gapStart); + if (index >= this.gapStart) + index += this.gapEnd - this.gapStart; - buffer[index] = value; + this.buffer[index] = value; } } public GapBuffer(int capacity = 0) { this.buffer = new T[capacity]; - this.gapEnd = buffer.Length; + this.gapEnd = this.buffer.Length; } } \ No newline at end of file diff --git a/Scintilla.NET/HelperMethods.cs b/Scintilla.NET/HelperMethods.cs index 0f4ce79..3433d7c 100644 --- a/Scintilla.NET/HelperMethods.cs +++ b/Scintilla.NET/HelperMethods.cs @@ -10,13 +10,13 @@ namespace ScintillaNET; /// public static class HelperMethods { - static readonly Dictionary knownColorMap = []; + private static readonly Dictionary knownColorMap = []; static HelperMethods() { - foreach (var knownColor in Enum.GetValues(typeof(KnownColor)).Cast().Where(k => k >= KnownColor.Transparent && k < KnownColor.ButtonFace)) + foreach (KnownColor knownColor in Enum.GetValues(typeof(KnownColor)).Cast().Where(k => k is >= KnownColor.Transparent and < KnownColor.ButtonFace)) { - Color color = Color.FromKnownColor(knownColor); + var color = Color.FromKnownColor(knownColor); knownColorMap[ToWin32Color(color)] = color; } } @@ -71,12 +71,13 @@ public static int ToWin32Color(Color color) public static void SetFoldingState(this Scintilla scintilla, string foldingState, string separator = ";") { scintilla.FoldAll(FoldAction.Expand); - foreach (var index in foldingState.Split(new[] { separator }, System.StringSplitOptions.None).Select(int.Parse)) + foreach (int index in foldingState.Split(new[] { separator }, System.StringSplitOptions.None).Select(int.Parse)) { if (index < 0 || index >= scintilla.Lines.Count) { continue; } + scintilla.Lines[index].ToggleFold(); } } diff --git a/Scintilla.NET/Helpers.cs b/Scintilla.NET/Helpers.cs index 4c00a10..e558ff3 100644 --- a/Scintilla.NET/Helpers.cs +++ b/Scintilla.NET/Helpers.cs @@ -33,6 +33,7 @@ public static long CopyTo(this Stream source, Stream destination) destination.Write(buffer, 0, bytesRead); totalBytes += bytesRead; } + return totalBytes; } @@ -42,14 +43,14 @@ public static unsafe byte[] BitmapToArgb(Bitmap image) // of the image formats was making my brain hurt. For now I'm going to use the slow but simple // GetPixel approach. - var bytes = new byte[4 * image.Width * image.Height]; + byte[] bytes = new byte[4 * image.Width * image.Height]; - var i = 0; + int i = 0; for (int y = 0; y < image.Height; y++) { for (int x = 0; x < image.Width; x++) { - var color = image.GetPixel(x, y); + Color color = image.GetPixel(x, y); bytes[i++] = color.R; bytes[i++] = color.G; bytes[i++] = color.B; @@ -66,10 +67,10 @@ public static unsafe byte[] ByteToCharStyles(byte* styles, byte* text, int lengt // It converts an array of styles where each element corresponds to a BYTE // to an array of styles where each element corresponds to a CHARACTER. - var bytePos = 0; // Position within text BYTES and style BYTES (should be the same) - var charPos = 0; // Position within style CHARACTERS - var decoder = encoding.GetDecoder(); - var result = new byte[encoding.GetCharCount(text, length)]; + int bytePos = 0; // Position within text BYTES and style BYTES (should be the same) + int charPos = 0; // Position within style CHARACTERS + Decoder decoder = encoding.GetDecoder(); + byte[] result = new byte[encoding.GetCharCount(text, length)]; while (bytePos < length) { @@ -88,10 +89,10 @@ public static unsafe byte[] CharToByteStyles(byte[] styles, byte* text, int leng // It converts an array of styles where each element corresponds to a CHARACTER // to an array of styles where each element corresponds to a BYTE. - var bytePos = 0; // Position within text BYTES and style BYTES (should be the same) - var charPos = 0; // Position within style CHARACTERS - var decoder = encoding.GetDecoder(); - var result = new byte[length]; + int bytePos = 0; // Position within text BYTES and style BYTES (should be the same) + int charPos = 0; // Position within style CHARACTERS + Decoder decoder = encoding.GetDecoder(); + byte[] result = new byte[length]; while (bytePos < length && charPos < styles.Length) { @@ -162,13 +163,13 @@ public static void Copy(Scintilla scintilla, CopyFormat format, bool useSelectio registeredFormats = true; } - var lineCopy = false; + bool lineCopy = false; StyleData[] styles = null; List> styledSegments = null; if (useSelection) { - var selIsEmpty = scintilla.DirectMessage(NativeMethods.SCI_GETSELECTIONEMPTY) != IntPtr.Zero; + bool selIsEmpty = scintilla.DirectMessage(NativeMethods.SCI_GETSELECTIONEMPTY) != IntPtr.Zero; if (selIsEmpty) { if (allowLine) @@ -233,214 +234,212 @@ private static unsafe void CopyHtml(Scintilla scintilla, StyleData[] styles, Lis byte[] bytes; // Write HTML - using (var ms = new NativeMemoryStream(styledSegments.Sum(s => s.Count))) - using (var tw = new StreamWriter(ms, new UTF8Encoding(false))) + using var ms = new NativeMemoryStream(styledSegments.Sum(s => s.Count)); + using var tw = new StreamWriter(ms, new UTF8Encoding(false)); + const int INDEX_START_HTML = 23; + const int INDEX_START_FRAGMENT = 65; + const int INDEX_END_FRAGMENT = 87; + const int INDEX_END_HTML = 41; + + tw.WriteLine("Version:0.9"); + tw.WriteLine("StartHTML:00000000"); + tw.WriteLine("EndHTML:00000000"); + tw.WriteLine("StartFragment:00000000"); + tw.WriteLine("EndFragment:00000000"); + tw.Flush(); + + // Patch header + pos = ms.Position; + ms.Seek(INDEX_START_HTML, SeekOrigin.Begin); + ms.Write(bytes = Encoding.ASCII.GetBytes(ms.Length.ToString("D8")), 0, bytes.Length); + ms.Seek(pos, SeekOrigin.Begin); + + tw.WriteLine(""); + tw.WriteLine(""); + tw.WriteLine(@""); + tw.WriteLine(@"ScintillaNET v{0}", scintilla.GetType().Assembly.GetName().Version.ToString(3)); + tw.WriteLine(""); + tw.WriteLine(""); + tw.Flush(); + + // Patch header + pos = ms.Position; + ms.Seek(INDEX_START_FRAGMENT, SeekOrigin.Begin); + ms.Write(bytes = Encoding.ASCII.GetBytes(ms.Length.ToString("D8")), 0, bytes.Length); + ms.Seek(pos, SeekOrigin.Begin); + tw.WriteLine(""); + + // Write the styles. + // We're doing the style tag in the body to include it in the "fragment". + tw.WriteLine(@""); - tw.Write(@"
", Style.Default); - tw.Flush(); + if (styles[i].Visible == 0) + tw.Write(" visibility: hidden;"); + tw.WriteLine(" }"); + } + + tw.WriteLine(""); + tw.Write(@"
", Style.Default); + tw.Flush(); - var tabSize = scintilla.DirectMessage(NativeMethods.SCI_GETTABWIDTH).ToInt32(); - var tab = new string(' ', tabSize); + int tabSize = scintilla.DirectMessage(NativeMethods.SCI_GETTABWIDTH).ToInt32(); + string tab = new(' ', tabSize); - tw.AutoFlush = true; - var lastStyle = Style.Default; - var unicodeLineEndings = ((scintilla.DirectMessage(NativeMethods.SCI_GETLINEENDTYPESACTIVE).ToInt32() & NativeMethods.SC_LINE_END_TYPE_UNICODE) > 0); - foreach (var seg in styledSegments) + tw.AutoFlush = true; + int lastStyle = Style.Default; + bool unicodeLineEndings = (scintilla.DirectMessage(NativeMethods.SCI_GETLINEENDTYPESACTIVE).ToInt32() & NativeMethods.SC_LINE_END_TYPE_UNICODE) > 0; + foreach (ArraySegment seg in styledSegments) + { + int endOffset = seg.Offset + seg.Count; + for (int i = seg.Offset; i < endOffset; i += 2) { - var endOffset = seg.Offset + seg.Count; - for (int i = seg.Offset; i < endOffset; i += 2) + byte ch = seg.Array[i]; + byte style = seg.Array[i + 1]; + + if (lastStyle != style) { - var ch = seg.Array[i]; - var style = seg.Array[i + 1]; + tw.Write(@"", style); + lastStyle = style; + } - if (lastStyle != style) - { - tw.Write(@"", style); - lastStyle = style; - } + switch (ch) + { + case (byte)'<': + tw.Write("<"); + break; - switch (ch) - { - case (byte)'<': - tw.Write("<"); - break; + case (byte)'>': + tw.Write(">"); + break; - case (byte)'>': - tw.Write(">"); - break; + case (byte)'&': + tw.Write("&"); + break; - case (byte)'&': - tw.Write("&"); - break; + case (byte)'\t': + tw.Write(tab); + break; - case (byte)'\t': - tw.Write(tab); - break; + case (byte)'\r': + if (i + 2 < endOffset) + { + if (seg.Array[i + 2] == (byte)'\n') + i += 2; + } - case (byte)'\r': - if (i + 2 < endOffset) + // Either way, this is a line break + goto case (byte)'\n'; + + case 0xC2: + if (unicodeLineEndings && i + 2 < endOffset) + { + if (seg.Array[i + 2] == 0x85) // NEL \u0085 { - if (seg.Array[i + 2] == (byte)'\n') - i += 2; + i += 2; + goto case (byte)'\n'; } + } - // Either way, this is a line break - goto case (byte)'\n'; + // Not a Unicode line break + goto default; - case 0xC2: - if (unicodeLineEndings && i + 2 < endOffset) + case 0xE2: + if (unicodeLineEndings && i + 4 < endOffset) + { + if (seg.Array[i + 2] == 0x80 && seg.Array[i + 4] == 0xA8) // LS \u2028 { - if (seg.Array[i + 2] == 0x85) // NEL \u0085 - { - i += 2; - goto case (byte)'\n'; - } + i += 4; + goto case (byte)'\n'; } - - // Not a Unicode line break - goto default; - - case 0xE2: - if (unicodeLineEndings && i + 4 < endOffset) + else if (seg.Array[i + 2] == 0x80 && seg.Array[i + 4] == 0xA9) // PS \u2029 { - if (seg.Array[i + 2] == 0x80 && seg.Array[i + 4] == 0xA8) // LS \u2028 - { - i += 4; - goto case (byte)'\n'; - } - else if (seg.Array[i + 2] == 0x80 && seg.Array[i + 4] == 0xA9) // PS \u2029 - { - i += 4; - goto case (byte)'\n'; - } + i += 4; + goto case (byte)'\n'; } + } - // Not a Unicode line break - goto default; - - case (byte)'\n': - // All your line breaks are belong to us - tw.Write("\r\n"); - break; + // Not a Unicode line break + goto default; - default: + case (byte)'\n': + // All your line breaks are belong to us + tw.Write("\r\n"); + break; - if (ch == 0) - { - // Scintilla behavior is to allow control characters except for - // NULL which will cause the Clipboard to truncate the string. - tw.Write(" "); // Replace with space - break; - } + default: - ms.WriteByte(ch); + if (ch == 0) + { + // Scintilla behavior is to allow control characters except for + // NULL which will cause the Clipboard to truncate the string. + tw.Write(" "); // Replace with space break; - } + } + + ms.WriteByte(ch); + break; } } - - tw.AutoFlush = false; - tw.WriteLine("
"); - tw.Flush(); - - // Patch header - pos = ms.Position; - ms.Seek(INDEX_END_FRAGMENT, SeekOrigin.Begin); - ms.Write((bytes = Encoding.ASCII.GetBytes(ms.Length.ToString("D8"))), 0, bytes.Length); - ms.Seek(pos, SeekOrigin.Begin); - tw.WriteLine(""); - - tw.WriteLine(""); - tw.WriteLine(""); - tw.Flush(); - - // Patch header - pos = ms.Position; - ms.Seek(INDEX_END_HTML, SeekOrigin.Begin); - ms.Write((bytes = Encoding.ASCII.GetBytes(ms.Length.ToString("D8"))), 0, bytes.Length); - ms.Seek(pos, SeekOrigin.Begin); - - // Terminator - ms.WriteByte(0); - - var str = GetString(ms.Pointer, (int)ms.Length, Encoding.UTF8); - if (NativeMethods.SetClipboardData(CF_HTML, ms.Pointer) != IntPtr.Zero) - ms.FreeOnDispose = false; // Clipboard will free memory } + + tw.AutoFlush = false; + tw.WriteLine("
"); + tw.Flush(); + + // Patch header + pos = ms.Position; + ms.Seek(INDEX_END_FRAGMENT, SeekOrigin.Begin); + ms.Write(bytes = Encoding.ASCII.GetBytes(ms.Length.ToString("D8")), 0, bytes.Length); + ms.Seek(pos, SeekOrigin.Begin); + tw.WriteLine(""); + + tw.WriteLine(""); + tw.WriteLine(""); + tw.Flush(); + + // Patch header + pos = ms.Position; + ms.Seek(INDEX_END_HTML, SeekOrigin.Begin); + ms.Write(bytes = Encoding.ASCII.GetBytes(ms.Length.ToString("D8")), 0, bytes.Length); + ms.Seek(pos, SeekOrigin.Begin); + + // Terminator + ms.WriteByte(0); + + string str = GetString(ms.Pointer, (int)ms.Length, Encoding.UTF8); + if (NativeMethods.SetClipboardData(CF_HTML, ms.Pointer) != IntPtr.Zero) + ms.FreeOnDispose = false; // Clipboard will free memory } catch (Exception ex) { @@ -463,7 +462,7 @@ private static unsafe void CopyRtf(Scintilla scintilla, StyleData[] styles, List { // Calculate twips per space int twips; - var fontStyle = FontStyle.Regular; + FontStyle fontStyle = FontStyle.Regular; if (styles[Style.Default].Weight >= 700) fontStyle |= FontStyle.Bold; if (styles[Style.Default].Italic != 0) @@ -471,259 +470,259 @@ private static unsafe void CopyRtf(Scintilla scintilla, StyleData[] styles, List if (styles[Style.Default].Underline != 0) fontStyle |= FontStyle.Underline; - using (var graphics = scintilla.CreateGraphics()) + using (Graphics graphics = scintilla.CreateGraphics()) using (var font = new Font(styles[Style.Default].FontName, styles[Style.Default].SizeF, fontStyle)) { - var width = graphics.MeasureString(" ", font).Width; - twips = (int)((width / graphics.DpiX) * 1440); + float width = graphics.MeasureString(" ", font).Width; + twips = (int)(width / graphics.DpiX * 1440); // TODO The twips value calculated seems too small on my computer } // Write RTF - using (var ms = new NativeMemoryStream(styledSegments.Sum(s => s.Count))) - using (var tw = new StreamWriter(ms, Encoding.ASCII)) + using var ms = new NativeMemoryStream(styledSegments.Sum(s => s.Count)); + using var tw = new StreamWriter(ms, Encoding.ASCII); + int tabWidth = scintilla.DirectMessage(NativeMethods.SCI_GETTABWIDTH).ToInt32(); + int deftab = tabWidth * twips; + + tw.WriteLine(@"{{\rtf1\ansi\deff0\deftab{0}", deftab); + tw.Flush(); + + // Build the font table + tw.Write(@"{\fonttbl"); + tw.Write(@"{{\f0 {0};}}", styles[Style.Default].FontName); + int fontIndex = 1; + for (int i = 0; i < styles.Length; i++) { - var tabWidth = scintilla.DirectMessage(NativeMethods.SCI_GETTABWIDTH).ToInt32(); - var deftab = tabWidth * twips; + if (!styles[i].Used) + continue; - tw.WriteLine(@"{{\rtf1\ansi\deff0\deftab{0}", deftab); - tw.Flush(); + if (i == Style.Default) + continue; - // Build the font table - tw.Write(@"{\fonttbl"); - tw.Write(@"{{\f0 {0};}}", styles[Style.Default].FontName); - var fontIndex = 1; - for (int i = 0; i < styles.Length; i++) + // Not a completely unique list, but close enough + if (styles[i].FontName != styles[Style.Default].FontName) { - if (!styles[i].Used) - continue; + styles[i].FontIndex = fontIndex++; + tw.Write(@"{{\f{0} {1};}}", styles[i].FontIndex, styles[i].FontName); + } + } - if (i == Style.Default) - continue; + tw.WriteLine("}"); // fonttbl + tw.Flush(); - // Not a completely unique list, but close enough - if (styles[i].FontName != styles[Style.Default].FontName) - { - styles[i].FontIndex = fontIndex++; - tw.Write(@"{{\f{0} {1};}}", styles[i].FontIndex, styles[i].FontName); - } + // Build the color table + tw.Write(@"{\colortbl"); + tw.Write(@"\red{0}\green{1}\blue{2};", (styles[Style.Default].ForeColor >> 0) & 0xFF, (styles[Style.Default].ForeColor >> 8) & 0xFF, (styles[Style.Default].ForeColor >> 16) & 0xFF); + tw.Write(@"\red{0}\green{1}\blue{2};", (styles[Style.Default].BackColor >> 0) & 0xFF, (styles[Style.Default].BackColor >> 8) & 0xFF, (styles[Style.Default].BackColor >> 16) & 0xFF); + styles[Style.Default].ForeColorIndex = 0; + styles[Style.Default].BackColorIndex = 1; + int colorIndex = 2; + for (int i = 0; i < styles.Length; i++) + { + if (!styles[i].Used) + continue; + + if (i == Style.Default) + continue; + + // Not a completely unique list, but close enough + if (styles[i].ForeColor != styles[Style.Default].ForeColor) + { + styles[i].ForeColorIndex = colorIndex++; + tw.Write(@"\red{0}\green{1}\blue{2};", (styles[i].ForeColor >> 0) & 0xFF, (styles[i].ForeColor >> 8) & 0xFF, (styles[i].ForeColor >> 16) & 0xFF); + } + else + { + styles[i].ForeColorIndex = styles[Style.Default].ForeColorIndex; } - tw.WriteLine("}"); // fonttbl - tw.Flush(); - - // Build the color table - tw.Write(@"{\colortbl"); - tw.Write(@"\red{0}\green{1}\blue{2};", (styles[Style.Default].ForeColor >> 0) & 0xFF, (styles[Style.Default].ForeColor >> 8) & 0xFF, (styles[Style.Default].ForeColor >> 16) & 0xFF); - tw.Write(@"\red{0}\green{1}\blue{2};", (styles[Style.Default].BackColor >> 0) & 0xFF, (styles[Style.Default].BackColor >> 8) & 0xFF, (styles[Style.Default].BackColor >> 16) & 0xFF); - styles[Style.Default].ForeColorIndex = 0; - styles[Style.Default].BackColorIndex = 1; - var colorIndex = 2; - for (int i = 0; i < styles.Length; i++) + + if (styles[i].BackColor != styles[Style.Default].BackColor) { - if (!styles[i].Used) - continue; + styles[i].BackColorIndex = colorIndex++; + tw.Write(@"\red{0}\green{1}\blue{2};", (styles[i].BackColor >> 0) & 0xFF, (styles[i].BackColor >> 8) & 0xFF, (styles[i].BackColor >> 16) & 0xFF); + } + else + { + styles[i].BackColorIndex = styles[Style.Default].BackColorIndex; + } + } - if (i == Style.Default) - continue; + tw.WriteLine("}"); // colortbl + tw.Flush(); - // Not a completely unique list, but close enough - if (styles[i].ForeColor != styles[Style.Default].ForeColor) - { - styles[i].ForeColorIndex = colorIndex++; - tw.Write(@"\red{0}\green{1}\blue{2};", (styles[i].ForeColor >> 0) & 0xFF, (styles[i].ForeColor >> 8) & 0xFF, (styles[i].ForeColor >> 16) & 0xFF); - } - else - { - styles[i].ForeColorIndex = styles[Style.Default].ForeColorIndex; - } + // Start with the default style + tw.Write(@"\f{0}\fs{1}\cf{2}\chshdng0\chcbpat{3}\cb{3} ", styles[Style.Default].FontIndex, (int)(styles[Style.Default].SizeF * 2), styles[Style.Default].ForeColorIndex, styles[Style.Default].BackColorIndex); + if (styles[Style.Default].Italic != 0) + tw.Write(@"\i"); + if (styles[Style.Default].Underline != 0) + tw.Write(@"\ul"); + if (styles[Style.Default].Weight >= 700) + tw.Write(@"\b"); - if (styles[i].BackColor != styles[Style.Default].BackColor) - { - styles[i].BackColorIndex = colorIndex++; - tw.Write(@"\red{0}\green{1}\blue{2};", (styles[i].BackColor >> 0) & 0xFF, (styles[i].BackColor >> 8) & 0xFF, (styles[i].BackColor >> 16) & 0xFF); - } - else - { - styles[i].BackColorIndex = styles[Style.Default].BackColorIndex; - } - } - tw.WriteLine("}"); // colortbl - tw.Flush(); - - // Start with the default style - tw.Write(@"\f{0}\fs{1}\cf{2}\chshdng0\chcbpat{3}\cb{3} ", styles[Style.Default].FontIndex, (int)(styles[Style.Default].SizeF * 2), styles[Style.Default].ForeColorIndex, styles[Style.Default].BackColorIndex); - if (styles[Style.Default].Italic != 0) - tw.Write(@"\i"); - if (styles[Style.Default].Underline != 0) - tw.Write(@"\ul"); - if (styles[Style.Default].Weight >= 700) - tw.Write(@"\b"); - - tw.AutoFlush = true; - var lastStyle = Style.Default; - var unicodeLineEndings = ((scintilla.DirectMessage(NativeMethods.SCI_GETLINEENDTYPESACTIVE).ToInt32() & NativeMethods.SC_LINE_END_TYPE_UNICODE) > 0); - foreach (var seg in styledSegments) + tw.AutoFlush = true; + int lastStyle = Style.Default; + bool unicodeLineEndings = (scintilla.DirectMessage(NativeMethods.SCI_GETLINEENDTYPESACTIVE).ToInt32() & NativeMethods.SC_LINE_END_TYPE_UNICODE) > 0; + foreach (ArraySegment seg in styledSegments) + { + int endOffset = seg.Offset + seg.Count; + for (int i = seg.Offset; i < endOffset; i += 2) { - var endOffset = seg.Offset + seg.Count; - for (int i = seg.Offset; i < endOffset; i += 2) - { - var ch = seg.Array[i]; - var style = seg.Array[i + 1]; + byte ch = seg.Array[i]; + byte style = seg.Array[i + 1]; - if (lastStyle != style) + if (lastStyle != style) + { + // Change the style + if (styles[lastStyle].FontIndex != styles[style].FontIndex) + tw.Write(@"\f{0}", styles[style].FontIndex); + if (styles[lastStyle].SizeF != styles[style].SizeF) + tw.Write(@"\fs{0}", (int)(styles[style].SizeF * 2)); + if (styles[lastStyle].ForeColorIndex != styles[style].ForeColorIndex) + tw.Write(@"\cf{0}", styles[style].ForeColorIndex); + if (styles[lastStyle].BackColorIndex != styles[style].BackColorIndex) + tw.Write(@"\chshdng0\chcbpat{0}\cb{0}", styles[style].BackColorIndex); + if (styles[lastStyle].Italic != styles[style].Italic) + tw.Write(@"\i{0}", styles[style].Italic != 0 ? "" : "0"); + if (styles[lastStyle].Underline != styles[style].Underline) + tw.Write(@"\ul{0}", styles[style].Underline != 0 ? "" : "0"); + if (styles[lastStyle].Weight != styles[style].Weight) { - // Change the style - if (styles[lastStyle].FontIndex != styles[style].FontIndex) - tw.Write(@"\f{0}", styles[style].FontIndex); - if (styles[lastStyle].SizeF != styles[style].SizeF) - tw.Write(@"\fs{0}", (int)(styles[style].SizeF * 2)); - if (styles[lastStyle].ForeColorIndex != styles[style].ForeColorIndex) - tw.Write(@"\cf{0}", styles[style].ForeColorIndex); - if (styles[lastStyle].BackColorIndex != styles[style].BackColorIndex) - tw.Write(@"\chshdng0\chcbpat{0}\cb{0}", styles[style].BackColorIndex); - if (styles[lastStyle].Italic != styles[style].Italic) - tw.Write(@"\i{0}", styles[style].Italic != 0 ? "" : "0"); - if (styles[lastStyle].Underline != styles[style].Underline) - tw.Write(@"\ul{0}", styles[style].Underline != 0 ? "" : "0"); - if (styles[lastStyle].Weight != styles[style].Weight) - { - if (styles[style].Weight >= 700 && styles[lastStyle].Weight < 700) - tw.Write(@"\b"); - else if (styles[style].Weight < 700 && styles[lastStyle].Weight >= 700) - tw.Write(@"\b0"); - } + if (styles[style].Weight >= 700 && styles[lastStyle].Weight < 700) + tw.Write(@"\b"); + else if (styles[style].Weight < 700 && styles[lastStyle].Weight >= 700) + tw.Write(@"\b0"); + } - // NOTE: We don't support StyleData.Visible and StyleData.Case in RTF + // NOTE: We don't support StyleData.Visible and StyleData.Case in RTF - lastStyle = style; - tw.Write("\n"); // Delimiter - } + lastStyle = style; + tw.Write("\n"); // Delimiter + } - switch (ch) - { - case (byte)'{': - tw.Write(@"\{"); - break; + switch (ch) + { + case (byte)'{': + tw.Write(@"\{"); + break; - case (byte)'}': - tw.Write(@"\}"); - break; + case (byte)'}': + tw.Write(@"\}"); + break; - case (byte)'\\': - tw.Write(@"\\"); - break; + case (byte)'\\': + tw.Write(@"\\"); + break; - case (byte)'\t': - tw.Write(@"\tab "); - break; + case (byte)'\t': + tw.Write(@"\tab "); + break; - case (byte)'\r': - if (i + 2 < endOffset) - { - if (seg.Array[i + 2] == (byte)'\n') - i += 2; - } + case (byte)'\r': + if (i + 2 < endOffset) + { + if (seg.Array[i + 2] == (byte)'\n') + i += 2; + } - // Either way, this is a line break - goto case (byte)'\n'; + // Either way, this is a line break + goto case (byte)'\n'; - case 0xC2: - if (unicodeLineEndings && i + 2 < endOffset) + case 0xC2: + if (unicodeLineEndings && i + 2 < endOffset) + { + if (seg.Array[i + 2] == 0x85) // NEL \u0085 { - if (seg.Array[i + 2] == 0x85) // NEL \u0085 - { - i += 2; - goto case (byte)'\n'; - } + i += 2; + goto case (byte)'\n'; } + } - // Not a Unicode line break - goto default; + // Not a Unicode line break + goto default; - case 0xE2: - if (unicodeLineEndings && i + 4 < endOffset) + case 0xE2: + if (unicodeLineEndings && i + 4 < endOffset) + { + if (seg.Array[i + 2] == 0x80 && seg.Array[i + 4] == 0xA8) // LS \u2028 { - if (seg.Array[i + 2] == 0x80 && seg.Array[i + 4] == 0xA8) // LS \u2028 - { - i += 4; - goto case (byte)'\n'; - } - else if (seg.Array[i + 2] == 0x80 && seg.Array[i + 4] == 0xA9) // PS \u2029 - { - i += 4; - goto case (byte)'\n'; - } + i += 4; + goto case (byte)'\n'; + } + else if (seg.Array[i + 2] == 0x80 && seg.Array[i + 4] == 0xA9) // PS \u2029 + { + i += 4; + goto case (byte)'\n'; } + } + + // Not a Unicode line break + goto default; - // Not a Unicode line break - goto default; + case (byte)'\n': + // All your line breaks are belong to us + tw.WriteLine(@"\par"); + break; - case (byte)'\n': - // All your line breaks are belong to us - tw.WriteLine(@"\par"); - break; + default: - default: + if (ch == 0) + { + // Scintilla behavior is to allow control characters except for + // NULL which will cause the Clipboard to truncate the string. + tw.Write(" "); // Replace with space + break; + } - if (ch == 0) + if (ch > 0x7F) + { + // Treat as UTF-8 code point + int unicode = 0; + if (ch < 0xE0 && i + 2 < endOffset) { - // Scintilla behavior is to allow control characters except for - // NULL which will cause the Clipboard to truncate the string. - tw.Write(" "); // Replace with space + unicode |= (0x1F & ch) << 6; + unicode |= 0x3F & seg.Array[i + 2]; + tw.Write(@"\u{0}?", unicode); + i += 2; break; } - - if (ch > 0x7F) + else if (ch < 0xF0 && i + 4 < endOffset) + { + unicode |= (0xF & ch) << 12; + unicode |= (0x3F & seg.Array[i + 2]) << 6; + unicode |= 0x3F & seg.Array[i + 4]; + tw.Write(@"\u{0}?", unicode); + i += 4; + break; + } + else if (ch < 0xF8 && i + 6 < endOffset) { - // Treat as UTF-8 code point - int unicode = 0; - if (ch < 0xE0 && i + 2 < endOffset) - { - unicode |= ((0x1F & ch) << 6); - unicode |= (0x3F & seg.Array[i + 2]); - tw.Write(@"\u{0}?", unicode); - i += 2; - break; - } - else if (ch < 0xF0 && i + 4 < endOffset) - { - unicode |= ((0xF & ch) << 12); - unicode |= ((0x3F & seg.Array[i + 2]) << 6); - unicode |= (0x3F & seg.Array[i + 4]); - tw.Write(@"\u{0}?", unicode); - i += 4; - break; - } - else if (ch < 0xF8 && i + 6 < endOffset) - { - unicode |= ((0x7 & ch) << 18); - unicode |= ((0x3F & seg.Array[i + 2]) << 12); - unicode |= ((0x3F & seg.Array[i + 4]) << 6); - unicode |= (0x3F & seg.Array[i + 6]); - tw.Write(@"\u{0}?", unicode); - i += 6; - break; - } + unicode |= (0x7 & ch) << 18; + unicode |= (0x3F & seg.Array[i + 2]) << 12; + unicode |= (0x3F & seg.Array[i + 4]) << 6; + unicode |= 0x3F & seg.Array[i + 6]; + tw.Write(@"\u{0}?", unicode); + i += 6; + break; } + } - // Regular ANSI char - ms.WriteByte(ch); - break; - } + // Regular ANSI char + ms.WriteByte(ch); + break; } } + } - tw.AutoFlush = false; - tw.WriteLine("}"); // rtf1 - tw.Flush(); + tw.AutoFlush = false; + tw.WriteLine("}"); // rtf1 + tw.Flush(); - // Terminator - ms.WriteByte(0); + // Terminator + ms.WriteByte(0); - // var str = GetString(ms.Pointer, (int)ms.Length, Encoding.ASCII); - if (NativeMethods.SetClipboardData(CF_RTF, ms.Pointer) != IntPtr.Zero) - ms.FreeOnDispose = false; // Clipboard will free memory - } + // var str = GetString(ms.Pointer, (int)ms.Length, Encoding.ASCII); + if (NativeMethods.SetClipboardData(CF_RTF, ms.Pointer) != IntPtr.Zero) + ms.FreeOnDispose = false; // Clipboard will free memory } catch (Exception ex) { @@ -736,7 +735,7 @@ private static unsafe void CopyRtf(Scintilla scintilla, StyleData[] styles, List public static unsafe byte[] GetBytes(string text, Encoding encoding, bool zeroTerminated) { if (string.IsNullOrEmpty(text)) - return (zeroTerminated ? new byte[] { 0 } : new byte[0]); + return zeroTerminated ? new byte[] { 0 } : new byte[0]; int count = encoding.GetByteCount(text); byte[] buffer = new byte[count + (zeroTerminated ? 1 : 0)]; @@ -757,8 +756,8 @@ public static unsafe byte[] GetBytes(char[] text, int length, Encoding encoding, { fixed (char* cp = text) { - var count = encoding.GetByteCount(cp, length); - var buffer = new byte[count + (zeroTerminated ? 1 : 0)]; + int count = encoding.GetByteCount(cp, length); + byte[] buffer = new byte[count + (zeroTerminated ? 1 : 0)]; fixed (byte* bp = buffer) encoding.GetBytes(cp, length, bp, buffer.Length); @@ -777,169 +776,166 @@ public static string GetHtml(Scintilla scintilla, int startBytePos, int endByteP if (startBytePos == endBytePos) return string.Empty; - StyleData[] styles = null; - List> styledSegments = GetStyledSegments(scintilla, false, false, startBytePos, endBytePos, out styles); + List> styledSegments = GetStyledSegments(scintilla, false, false, startBytePos, endBytePos, out StyleData[] styles); - using (var ms = new NativeMemoryStream(styledSegments.Sum(s => s.Count))) // Hint - using (var sw = new StreamWriter(ms, new UTF8Encoding(false))) - { - // Write the styles - sw.WriteLine(@""); + sw.WriteLine(""); - var unicodeLineEndings = ((scintilla.DirectMessage(NativeMethods.SCI_GETLINEENDTYPESACTIVE).ToInt32() & NativeMethods.SC_LINE_END_TYPE_UNICODE) > 0); - var tabSize = scintilla.DirectMessage(NativeMethods.SCI_GETTABWIDTH).ToInt32(); - var tab = new string(' ', tabSize); - var lastStyle = Style.Default; + bool unicodeLineEndings = (scintilla.DirectMessage(NativeMethods.SCI_GETLINEENDTYPESACTIVE).ToInt32() & NativeMethods.SC_LINE_END_TYPE_UNICODE) > 0; + int tabSize = scintilla.DirectMessage(NativeMethods.SCI_GETTABWIDTH).ToInt32(); + string tab = new(' ', tabSize); + int lastStyle = Style.Default; - // Write the styled text - sw.Write(@"
", Style.Default); - sw.Flush(); - sw.AutoFlush = true; + // Write the styled text + sw.Write(@"
", Style.Default); + sw.Flush(); + sw.AutoFlush = true; - foreach (var seg in styledSegments) + foreach (ArraySegment seg in styledSegments) + { + int endOffset = seg.Offset + seg.Count; + for (int i = seg.Offset; i < endOffset; i += 2) { - var endOffset = seg.Offset + seg.Count; - for (int i = seg.Offset; i < endOffset; i += 2) + byte ch = seg.Array[i]; + byte style = seg.Array[i + 1]; + + if (lastStyle != style) + { + sw.Write(@"", style); + lastStyle = style; + } + + switch (ch) { - var ch = seg.Array[i]; - var style = seg.Array[i + 1]; + case (byte)'<': + sw.Write("<"); + break; - if (lastStyle != style) - { - sw.Write(@"", style); - lastStyle = style; - } + case (byte)'>': + sw.Write(">"); + break; - switch (ch) - { - case (byte)'<': - sw.Write("<"); - break; + case (byte)'&': + sw.Write("&"); + break; - case (byte)'>': - sw.Write(">"); - break; + case (byte)'\t': + sw.Write(tab); + break; - case (byte)'&': - sw.Write("&"); - break; + case (byte)'\r': + if (i + 2 < endOffset) + { + if (seg.Array[i + 2] == (byte)'\n') + i += 2; + } - case (byte)'\t': - sw.Write(tab); - break; + // Either way, this is a line break + goto case (byte)'\n'; - case (byte)'\r': - if (i + 2 < endOffset) + case 0xC2: + if (unicodeLineEndings && i + 2 < endOffset) + { + if (seg.Array[i + 2] == 0x85) // NEL \u0085 { - if (seg.Array[i + 2] == (byte)'\n') - i += 2; + i += 2; + goto case (byte)'\n'; } + } - // Either way, this is a line break - goto case (byte)'\n'; + // Not a Unicode line break + goto default; - case 0xC2: - if (unicodeLineEndings && i + 2 < endOffset) + case 0xE2: + if (unicodeLineEndings && i + 4 < endOffset) + { + if (seg.Array[i + 2] == 0x80 && seg.Array[i + 4] == 0xA8) // LS \u2028 { - if (seg.Array[i + 2] == 0x85) // NEL \u0085 - { - i += 2; - goto case (byte)'\n'; - } + i += 4; + goto case (byte)'\n'; } - - // Not a Unicode line break - goto default; - - case 0xE2: - if (unicodeLineEndings && i + 4 < endOffset) + else if (seg.Array[i + 2] == 0x80 && seg.Array[i + 4] == 0xA9) // PS \u2029 { - if (seg.Array[i + 2] == 0x80 && seg.Array[i + 4] == 0xA8) // LS \u2028 - { - i += 4; - goto case (byte)'\n'; - } - else if (seg.Array[i + 2] == 0x80 && seg.Array[i + 4] == 0xA9) // PS \u2029 - { - i += 4; - goto case (byte)'\n'; - } + i += 4; + goto case (byte)'\n'; } + } - // Not a Unicode line break - goto default; - - case (byte)'\n': - // All your line breaks are belong to us - sw.Write("\r\n"); - break; + // Not a Unicode line break + goto default; - default: + case (byte)'\n': + // All your line breaks are belong to us + sw.Write("\r\n"); + break; - if (ch == 0) - { - // Replace NUL with space - sw.Write(" "); - break; - } + default: - ms.WriteByte(ch); + if (ch == 0) + { + // Replace NUL with space + sw.Write(" "); break; - } + } + + ms.WriteByte(ch); + break; } } + } - sw.AutoFlush = false; - sw.WriteLine("
"); - sw.Flush(); + sw.AutoFlush = false; + sw.WriteLine("
"); + sw.Flush(); - return GetString(ms.Pointer, (int)ms.Length, Encoding.UTF8); - } + return GetString(ms.Pointer, (int)ms.Length, Encoding.UTF8); } public static unsafe string GetString(IntPtr bytes, int length, Encoding encoding) { - var ptr = (sbyte*)bytes; - var str = new string(ptr, 0, length, encoding); + sbyte* ptr = (sbyte*)bytes; + string str = new(ptr, 0, length, encoding); return str; } @@ -952,41 +948,41 @@ private static unsafe List> GetStyledSegments(Scintilla scint // Get each selection as a segment. // Rectangular selections are ordered top to bottom and have line breaks appended. var ranges = new List>(); - var selCount = scintilla.DirectMessage(NativeMethods.SCI_GETSELECTIONS).ToInt32(); + int selCount = scintilla.DirectMessage(NativeMethods.SCI_GETSELECTIONS).ToInt32(); for (int i = 0; i < selCount; i++) { - var selStartBytePos = scintilla.DirectMessage(NativeMethods.SCI_GETSELECTIONNSTART, new IntPtr(i)).ToInt32(); - var selEndBytePos = scintilla.DirectMessage(NativeMethods.SCI_GETSELECTIONNEND, new IntPtr(i)).ToInt32(); + int selStartBytePos = scintilla.DirectMessage(NativeMethods.SCI_GETSELECTIONNSTART, new IntPtr(i)).ToInt32(); + int selEndBytePos = scintilla.DirectMessage(NativeMethods.SCI_GETSELECTIONNEND, new IntPtr(i)).ToInt32(); ranges.Add(Tuple.Create(selStartBytePos, selEndBytePos)); } - var selIsRect = scintilla.DirectMessage(NativeMethods.SCI_SELECTIONISRECTANGLE) != IntPtr.Zero; + bool selIsRect = scintilla.DirectMessage(NativeMethods.SCI_SELECTIONISRECTANGLE) != IntPtr.Zero; if (selIsRect) ranges.OrderBy(r => r.Item1); // Sort top to bottom - foreach (var range in ranges) + foreach (Tuple range in ranges) { - var styledText = GetStyledText(scintilla, range.Item1, range.Item2, selIsRect); + ArraySegment styledText = GetStyledText(scintilla, range.Item1, range.Item2, selIsRect); segments.Add(styledText); } } else if (currentLine) { // Get the current line - var mainSelection = scintilla.DirectMessage(NativeMethods.SCI_GETMAINSELECTION).ToInt32(); - var mainCaretPos = scintilla.DirectMessage(NativeMethods.SCI_GETSELECTIONNCARET, new IntPtr(mainSelection)).ToInt32(); - var lineIndex = scintilla.DirectMessage(NativeMethods.SCI_LINEFROMPOSITION, new IntPtr(mainCaretPos)).ToInt32(); - var lineStartBytePos = scintilla.DirectMessage(NativeMethods.SCI_POSITIONFROMLINE, new IntPtr(lineIndex)).ToInt32(); - var lineLength = scintilla.DirectMessage(NativeMethods.SCI_POSITIONFROMLINE, new IntPtr(lineIndex)).ToInt32(); + int mainSelection = scintilla.DirectMessage(NativeMethods.SCI_GETMAINSELECTION).ToInt32(); + int mainCaretPos = scintilla.DirectMessage(NativeMethods.SCI_GETSELECTIONNCARET, new IntPtr(mainSelection)).ToInt32(); + int lineIndex = scintilla.DirectMessage(NativeMethods.SCI_LINEFROMPOSITION, new IntPtr(mainCaretPos)).ToInt32(); + int lineStartBytePos = scintilla.DirectMessage(NativeMethods.SCI_POSITIONFROMLINE, new IntPtr(lineIndex)).ToInt32(); + int lineLength = scintilla.DirectMessage(NativeMethods.SCI_POSITIONFROMLINE, new IntPtr(lineIndex)).ToInt32(); - var styledText = GetStyledText(scintilla, lineStartBytePos, (lineStartBytePos + lineLength), false); + ArraySegment styledText = GetStyledText(scintilla, lineStartBytePos, lineStartBytePos + lineLength, false); segments.Add(styledText); } else // User-specified range { Debug.Assert(startBytePos != endBytePos); - var styledText = GetStyledText(scintilla, startBytePos, endBytePos, false); + ArraySegment styledText = GetStyledText(scintilla, startBytePos, endBytePos, false); segments.Add(styledText); } @@ -1004,11 +1000,11 @@ private static unsafe List> GetStyledSegments(Scintilla scint styles[Style.Default].Case = scintilla.DirectMessage(NativeMethods.SCI_STYLEGETCASE, new IntPtr(Style.Default), IntPtr.Zero).ToInt32(); styles[Style.Default].Visible = scintilla.DirectMessage(NativeMethods.SCI_STYLEGETVISIBLE, new IntPtr(Style.Default), IntPtr.Zero).ToInt32(); - foreach (var seg in segments) + foreach (ArraySegment seg in segments) { for (int i = 0; i < seg.Count; i += 2) { - var style = seg.Array[i + 1]; + byte style = seg.Array[i + 1]; if (!styles[style].Used) { styles[style].Used = true; @@ -1035,8 +1031,8 @@ private static unsafe ArraySegment GetStyledText(Scintilla scintilla, int // Make sure the range is styled scintilla.DirectMessage(NativeMethods.SCI_COLOURISE, new IntPtr(startBytePos), new IntPtr(endBytePos)); - var byteLength = (endBytePos - startBytePos); - var buffer = new byte[(byteLength * 2) + (addLineBreak ? 4 : 0) + 2]; + int byteLength = endBytePos - startBytePos; + byte[] buffer = new byte[byteLength * 2 + (addLineBreak ? 4 : 0) + 2]; fixed (byte* bp = buffer) { NativeMethods.Sci_TextRange* tr = stackalloc NativeMethods.Sci_TextRange[1]; @@ -1052,7 +1048,7 @@ private static unsafe ArraySegment GetStyledText(Scintilla scintilla, int // We do this when this range is part of a rectangular selection. if (addLineBreak) { - var style = buffer[byteLength - 1]; + byte style = buffer[byteLength - 1]; buffer[byteLength++] = (byte)'\r'; buffer[byteLength++] = style; @@ -1155,14 +1151,14 @@ public static int TranslateKeys(Keys keys) } // No translation necessary for the modifiers. Just add them back in. - var keyDefinition = keyCode | (int)(keys & Keys.Modifiers); + int keyDefinition = keyCode | (int)(keys & Keys.Modifiers); return keyDefinition; } // https://stackoverflow.com/questions/2709430/count-number-of-bits-in-a-64-bit-long-big-integer/2709523#2709523 public static byte PopCount(ulong i) { - i = i - ((i >> 1) & 0x5555555555555555UL); + i -= ((i >> 1) & 0x5555555555555555UL); i = (i & 0x3333333333333333UL) + ((i >> 2) & 0x3333333333333333UL); return (byte)((((i + (i >> 4)) & 0xF0F0F0F0F0F0F0FUL) * 0x101010101010101UL) >> 56); } @@ -1202,6 +1198,7 @@ public static int MaxIndex(this IEnumerable source, Func(this IEnumerable source, Func public int End(int position) { - position = Helpers.Clamp(position, 0, scintilla.TextLength); - position = scintilla.Lines.CharToBytePosition(position); - position = scintilla.DirectMessage(NativeMethods.SCI_INDICATOREND, new IntPtr(Index), new IntPtr(position)).ToInt32(); - return scintilla.Lines.ByteToCharPosition(position); + position = Helpers.Clamp(position, 0, this.scintilla.TextLength); + position = this.scintilla.Lines.CharToBytePosition(position); + position = this.scintilla.DirectMessage(NativeMethods.SCI_INDICATOREND, new IntPtr(Index), new IntPtr(position)).ToInt32(); + return this.scintilla.Lines.ByteToCharPosition(position); } /// @@ -63,10 +63,10 @@ public int End(int position) /// public int Start(int position) { - position = Helpers.Clamp(position, 0, scintilla.TextLength); - position = scintilla.Lines.CharToBytePosition(position); - position = scintilla.DirectMessage(NativeMethods.SCI_INDICATORSTART, new IntPtr(Index), new IntPtr(position)).ToInt32(); - return scintilla.Lines.ByteToCharPosition(position); + position = Helpers.Clamp(position, 0, this.scintilla.TextLength); + position = this.scintilla.Lines.CharToBytePosition(position); + position = this.scintilla.DirectMessage(NativeMethods.SCI_INDICATORSTART, new IntPtr(Index), new IntPtr(position)).ToInt32(); + return this.scintilla.Lines.ByteToCharPosition(position); } /// @@ -76,10 +76,10 @@ public int Start(int position) /// The user-defined value at the specified . public int ValueAt(int position) { - position = Helpers.Clamp(position, 0, scintilla.TextLength); - position = scintilla.Lines.CharToBytePosition(position); + position = Helpers.Clamp(position, 0, this.scintilla.TextLength); + position = this.scintilla.Lines.CharToBytePosition(position); - return scintilla.DirectMessage(NativeMethods.SCI_INDICATORVALUEAT, new IntPtr(Index), new IntPtr(position)).ToInt32(); + return this.scintilla.DirectMessage(NativeMethods.SCI_INDICATORVALUEAT, new IntPtr(Index), new IntPtr(position)).ToInt32(); } #endregion Methods @@ -97,12 +97,12 @@ public int Alpha { get { - return scintilla.DirectMessage(NativeMethods.SCI_INDICGETALPHA, new IntPtr(Index)).ToInt32(); + return this.scintilla.DirectMessage(NativeMethods.SCI_INDICGETALPHA, new IntPtr(Index)).ToInt32(); } set { value = Helpers.Clamp(value, 0, 255); - scintilla.DirectMessage(NativeMethods.SCI_INDICSETALPHA, new IntPtr(Index), new IntPtr(value)); + this.scintilla.DirectMessage(NativeMethods.SCI_INDICSETALPHA, new IntPtr(Index), new IntPtr(value)); } } @@ -117,12 +117,12 @@ public IndicatorFlags Flags { get { - return (IndicatorFlags)scintilla.DirectMessage(NativeMethods.SCI_INDICGETFLAGS, new IntPtr(Index)); + return (IndicatorFlags)this.scintilla.DirectMessage(NativeMethods.SCI_INDICGETFLAGS, new IntPtr(Index)); } set { int flags = (int)value; - scintilla.DirectMessage(NativeMethods.SCI_INDICSETFLAGS, new IntPtr(Index), new IntPtr(flags)); + this.scintilla.DirectMessage(NativeMethods.SCI_INDICSETFLAGS, new IntPtr(Index), new IntPtr(flags)); } } @@ -136,13 +136,13 @@ public Color ForeColor { get { - var color = scintilla.DirectMessage(NativeMethods.SCI_INDICGETFORE, new IntPtr(Index)).ToInt32(); + int color = this.scintilla.DirectMessage(NativeMethods.SCI_INDICGETFORE, new IntPtr(Index)).ToInt32(); return HelperMethods.FromWin32Color(color); } set { - var color = HelperMethods.ToWin32Color(value); - scintilla.DirectMessage(NativeMethods.SCI_INDICSETFORE, new IntPtr(Index), new IntPtr(color)); + int color = HelperMethods.ToWin32Color(value); + this.scintilla.DirectMessage(NativeMethods.SCI_INDICSETFORE, new IntPtr(Index), new IntPtr(color)); } } @@ -159,13 +159,13 @@ public Color HoverForeColor { get { - var color = scintilla.DirectMessage(NativeMethods.SCI_INDICGETHOVERFORE, new IntPtr(Index)).ToInt32(); + int color = this.scintilla.DirectMessage(NativeMethods.SCI_INDICGETHOVERFORE, new IntPtr(Index)).ToInt32(); return HelperMethods.FromWin32Color(color); } set { - var color = HelperMethods.ToWin32Color(value); - scintilla.DirectMessage(NativeMethods.SCI_INDICSETHOVERFORE, new IntPtr(Index), new IntPtr(color)); + int color = HelperMethods.ToWin32Color(value); + this.scintilla.DirectMessage(NativeMethods.SCI_INDICSETHOVERFORE, new IntPtr(Index), new IntPtr(color)); } } @@ -182,12 +182,12 @@ public IndicatorStyle HoverStyle { get { - return (IndicatorStyle)scintilla.DirectMessage(NativeMethods.SCI_INDICGETHOVERSTYLE, new IntPtr(Index)); + return (IndicatorStyle)this.scintilla.DirectMessage(NativeMethods.SCI_INDICGETHOVERSTYLE, new IntPtr(Index)); } set { - var style = (int)value; - scintilla.DirectMessage(NativeMethods.SCI_INDICSETHOVERSTYLE, new IntPtr(Index), new IntPtr(style)); + int style = (int)value; + this.scintilla.DirectMessage(NativeMethods.SCI_INDICSETHOVERSTYLE, new IntPtr(Index), new IntPtr(style)); } } @@ -208,12 +208,12 @@ public int OutlineAlpha { get { - return scintilla.DirectMessage(NativeMethods.SCI_INDICGETOUTLINEALPHA, new IntPtr(Index)).ToInt32(); + return this.scintilla.DirectMessage(NativeMethods.SCI_INDICGETOUTLINEALPHA, new IntPtr(Index)).ToInt32(); } set { value = Helpers.Clamp(value, 0, 255); - scintilla.DirectMessage(NativeMethods.SCI_INDICSETOUTLINEALPHA, new IntPtr(Index), new IntPtr(value)); + this.scintilla.DirectMessage(NativeMethods.SCI_INDICSETOUTLINEALPHA, new IntPtr(Index), new IntPtr(value)); } } @@ -227,12 +227,12 @@ public IndicatorStyle Style { get { - return (IndicatorStyle)scintilla.DirectMessage(NativeMethods.SCI_INDICGETSTYLE, new IntPtr(Index)); + return (IndicatorStyle)this.scintilla.DirectMessage(NativeMethods.SCI_INDICGETSTYLE, new IntPtr(Index)); } set { - var style = (int)value; - scintilla.DirectMessage(NativeMethods.SCI_INDICSETSTYLE, new IntPtr(Index), new IntPtr(style)); + int style = (int)value; + this.scintilla.DirectMessage(NativeMethods.SCI_INDICSETSTYLE, new IntPtr(Index), new IntPtr(style)); } } @@ -245,12 +245,12 @@ public bool Under { get { - return (scintilla.DirectMessage(NativeMethods.SCI_INDICGETUNDER, new IntPtr(Index)) != IntPtr.Zero); + return this.scintilla.DirectMessage(NativeMethods.SCI_INDICGETUNDER, new IntPtr(Index)) != IntPtr.Zero; } set { - var under = (value ? new IntPtr(1) : IntPtr.Zero); - scintilla.DirectMessage(NativeMethods.SCI_INDICSETUNDER, new IntPtr(Index), under); + IntPtr under = value ? new IntPtr(1) : IntPtr.Zero; + this.scintilla.DirectMessage(NativeMethods.SCI_INDICSETUNDER, new IntPtr(Index), under); } } diff --git a/Scintilla.NET/IndicatorCollection.cs b/Scintilla.NET/IndicatorCollection.cs index 7953966..bcb73cb 100644 --- a/Scintilla.NET/IndicatorCollection.cs +++ b/Scintilla.NET/IndicatorCollection.cs @@ -26,7 +26,7 @@ public IEnumerator GetEnumerator() IEnumerator IEnumerable.GetEnumerator() { - return this.GetEnumerator(); + return GetEnumerator(); } /// @@ -59,7 +59,7 @@ public Indicator this[int index] get { index = Helpers.Clamp(index, 0, Count - 1); - return new Indicator(scintilla, index); + return new Indicator(this.scintilla, index); } } diff --git a/Scintilla.NET/IndicatorReleaseEventArgs.cs b/Scintilla.NET/IndicatorReleaseEventArgs.cs index 4538551..7407294 100644 --- a/Scintilla.NET/IndicatorReleaseEventArgs.cs +++ b/Scintilla.NET/IndicatorReleaseEventArgs.cs @@ -19,10 +19,9 @@ public int Position { get { - if (position == null) - position = scintilla.Lines.ByteToCharPosition(bytePosition); + this.position ??= this.scintilla.Lines.ByteToCharPosition(this.bytePosition); - return (int)position; + return (int)this.position; } } diff --git a/Scintilla.NET/InsertCheckEventArgs.cs b/Scintilla.NET/InsertCheckEventArgs.cs index 857172f..bac95da 100644 --- a/Scintilla.NET/InsertCheckEventArgs.cs +++ b/Scintilla.NET/InsertCheckEventArgs.cs @@ -23,8 +23,7 @@ public int Position { get { - if (CachedPosition == null) - CachedPosition = scintilla.Lines.ByteToCharPosition(bytePosition); + CachedPosition ??= this.scintilla.Lines.ByteToCharPosition(this.bytePosition); return (int)CachedPosition; } @@ -38,8 +37,7 @@ public unsafe string Text { get { - if (CachedText == null) - CachedText = Helpers.GetString(textPtr, byteLength, scintilla.Encoding); + CachedText ??= Helpers.GetString(this.textPtr, this.byteLength, this.scintilla.Encoding); return CachedText; } @@ -47,9 +45,9 @@ public unsafe string Text { CachedText = value ?? string.Empty; - var bytes = Helpers.GetBytes(CachedText, scintilla.Encoding, zeroTerminated: false); + byte[] bytes = Helpers.GetBytes(CachedText, this.scintilla.Encoding, zeroTerminated: false); fixed (byte* bp = bytes) - scintilla.DirectMessage(NativeMethods.SCI_CHANGEINSERTION, new IntPtr(bytes.Length), new IntPtr(bp)); + this.scintilla.DirectMessage(NativeMethods.SCI_CHANGEINSERTION, new IntPtr(bytes.Length), new IntPtr(bp)); } } diff --git a/Scintilla.NET/Layer.cs b/Scintilla.NET/Layer.cs index 3abc72b..f2d2c65 100644 --- a/Scintilla.NET/Layer.cs +++ b/Scintilla.NET/Layer.cs @@ -5,19 +5,19 @@ namespace ScintillaNET; /// public enum Layer { - /// - /// Draw the selection background opaquely on the base layer. - /// - Base = NativeMethods.SC_LAYER_BASE, + /// + /// Draw the selection background opaquely on the base layer. + /// + Base = NativeMethods.SC_LAYER_BASE, - /// - /// Draw the selection background translucently under the text. This will not work in single phase drawing mode. - /// () as there is no under-text phase. - /// - UnderText = NativeMethods.SC_LAYER_UNDER_TEXT, + /// + /// Draw the selection background translucently under the text. This will not work in single phase drawing mode. + /// () as there is no under-text phase. + /// + UnderText = NativeMethods.SC_LAYER_UNDER_TEXT, - /// - /// Draw the selection background translucently over the text. - /// - OverText = NativeMethods.SC_LAYER_OVER_TEXT + /// + /// Draw the selection background translucently over the text. + /// + OverText = NativeMethods.SC_LAYER_OVER_TEXT } diff --git a/Scintilla.NET/Lexilla.cs b/Scintilla.NET/Lexilla.cs index cbe36e5..7d8aeaf 100644 --- a/Scintilla.NET/Lexilla.cs +++ b/Scintilla.NET/Lexilla.cs @@ -18,18 +18,18 @@ internal Lexilla(IntPtr lexillaHandle) { const string win32Error = "The Scintilla module has no export for the '{0}' procedure."; - var lpProcName = nameof(NativeMethods.CreateLexer); + string lpProcName = nameof(NativeMethods.CreateLexer); // Get the Lexilla functions needed to define lexers and create managed callbacks... - var functionPointer = NativeMethods.GetProcAddress(new HandleRef(this, lexillaHandle), lpProcName); + IntPtr functionPointer = NativeMethods.GetProcAddress(new HandleRef(this, lexillaHandle), lpProcName); if (functionPointer == IntPtr.Zero) { throw new Win32Exception(string.Format(win32Error, lpProcName), new Win32Exception()); // Calls GetLastError } - createLexer = (NativeMethods.CreateLexer) Marshal.GetDelegateForFunctionPointer( + createLexer = (NativeMethods.CreateLexer)Marshal.GetDelegateForFunctionPointer( functionPointer, typeof(NativeMethods.CreateLexer)); lpProcName = nameof(NativeMethods.GetLexerName); @@ -41,7 +41,7 @@ internal Lexilla(IntPtr lexillaHandle) new Win32Exception()); // Calls GetLastError } - getLexerName = (NativeMethods.GetLexerName) Marshal.GetDelegateForFunctionPointer( + getLexerName = (NativeMethods.GetLexerName)Marshal.GetDelegateForFunctionPointer( functionPointer, typeof(NativeMethods.GetLexerName)); lpProcName = nameof(NativeMethods.GetLexerCount); @@ -53,10 +53,9 @@ internal Lexilla(IntPtr lexillaHandle) new Win32Exception()); // Calls GetLastError } - getLexerCount = (NativeMethods.GetLexerCount) Marshal.GetDelegateForFunctionPointer( + getLexerCount = (NativeMethods.GetLexerCount)Marshal.GetDelegateForFunctionPointer( functionPointer, typeof(NativeMethods.GetLexerCount)); - lpProcName = nameof(NativeMethods.LexerNameFromID); functionPointer = NativeMethods.GetProcAddress(new HandleRef(this, lexillaHandle), lpProcName); @@ -66,7 +65,7 @@ internal Lexilla(IntPtr lexillaHandle) new Win32Exception()); // Calls GetLastError } - lexerNameFromId = (NativeMethods.LexerNameFromID) Marshal.GetDelegateForFunctionPointer( + lexerNameFromId = (NativeMethods.LexerNameFromID)Marshal.GetDelegateForFunctionPointer( functionPointer, typeof(NativeMethods.LexerNameFromID)); //initialized = true; @@ -75,7 +74,7 @@ internal Lexilla(IntPtr lexillaHandle) #region Fields //private static bool initialized; - + #endregion #region DllCalls @@ -96,7 +95,7 @@ internal Lexilla(IntPtr lexillaHandle) /// Amount of lexers defined in the Lexilla library. public static int GetLexerCount() { - return (int) getLexerCount(); + return (int)getLexerCount(); } /// @@ -116,10 +115,10 @@ public static IntPtr CreateLexer(string lexerName) /// The name of the lexer if one was found with the specified index; null otherwise. public static string GetLexerName(int index) { - var pointer = Marshal.AllocHGlobal(1024); + IntPtr pointer = Marshal.AllocHGlobal(1024); try { - getLexerName((UIntPtr) index, pointer, new IntPtr(1024)); + getLexerName((UIntPtr)index, pointer, new IntPtr(1024)); return Marshal.PtrToStringAnsi(pointer); } finally @@ -144,7 +143,7 @@ public static string LexerNameFromId(int identifier) /// An IEnumerable<System.String> value with the lexer names. public static IEnumerable GetLexerNames() { - var count = GetLexerCount(); + int count = GetLexerCount(); for (int i = 0; i < count; i++) { yield return GetLexerName(i); diff --git a/Scintilla.NET/Line.cs b/Scintilla.NET/Line.cs index c27ce70..3169ca1 100644 --- a/Scintilla.NET/Line.cs +++ b/Scintilla.NET/Line.cs @@ -20,7 +20,7 @@ public class Line /// public void EnsureVisible() { - scintilla.DirectMessage(NativeMethods.SCI_ENSUREVISIBLE, new IntPtr(Index)); + this.scintilla.DirectMessage(NativeMethods.SCI_ENSUREVISIBLE, new IntPtr(Index)); } //public void ExpandChildren(int level) @@ -33,7 +33,7 @@ public void EnsureVisible() /// One of the enumeration values. public void FoldChildren(FoldAction action) { - scintilla.DirectMessage(NativeMethods.SCI_FOLDCHILDREN, new IntPtr(Index), new IntPtr((int)action)); + this.scintilla.DirectMessage(NativeMethods.SCI_FOLDCHILDREN, new IntPtr(Index), new IntPtr((int)action)); } /// @@ -42,7 +42,7 @@ public void FoldChildren(FoldAction action) /// One of the enumeration values. public void FoldLine(FoldAction action) { - scintilla.DirectMessage(NativeMethods.SCI_FOLDLINE, new IntPtr(Index), new IntPtr((int)action)); + this.scintilla.DirectMessage(NativeMethods.SCI_FOLDLINE, new IntPtr(Index), new IntPtr((int)action)); } /// @@ -57,7 +57,7 @@ public void FoldLine(FoldAction action) /// public int GetLastChild(int level) { - return scintilla.DirectMessage(NativeMethods.SCI_GETLASTCHILD, new IntPtr(Index), new IntPtr(level)).ToInt32(); + return this.scintilla.DirectMessage(NativeMethods.SCI_GETLASTCHILD, new IntPtr(Index), new IntPtr(level)).ToInt32(); } /// @@ -66,7 +66,7 @@ public int GetLastChild(int level) /// Any selection is discarded. public void Goto() { - scintilla.DirectMessage(NativeMethods.SCI_GOTOLINE, new IntPtr(Index)); + this.scintilla.DirectMessage(NativeMethods.SCI_GOTOLINE, new IntPtr(Index)); } /// @@ -77,8 +77,8 @@ public void Goto() /// This method does not check if the line already contains the . public MarkerHandle MarkerAdd(int marker) { - marker = Helpers.Clamp(marker, 0, scintilla.Markers.Count - 1); - var handle = scintilla.DirectMessage(NativeMethods.SCI_MARKERADD, new IntPtr(Index), new IntPtr(marker)); + marker = Helpers.Clamp(marker, 0, this.scintilla.Markers.Count - 1); + IntPtr handle = this.scintilla.DirectMessage(NativeMethods.SCI_MARKERADD, new IntPtr(Index), new IntPtr(marker)); return new MarkerHandle { Value = handle }; } @@ -88,8 +88,8 @@ public MarkerHandle MarkerAdd(int marker) /// An unsigned 32-bit value with each bit cooresponding to one of the 32 zero-based indexes to add. public void MarkerAddSet(uint markerMask) { - var mask = unchecked((int)markerMask); - scintilla.DirectMessage(NativeMethods.SCI_MARKERADDSET, new IntPtr(Index), new IntPtr(mask)); + int mask = unchecked((int)markerMask); + this.scintilla.DirectMessage(NativeMethods.SCI_MARKERADDSET, new IntPtr(Index), new IntPtr(mask)); } /// @@ -99,8 +99,8 @@ public void MarkerAddSet(uint markerMask) /// If the same marker has been added to the line more than once, this will delete one copy each time it is used. public void MarkerDelete(int marker) { - marker = Helpers.Clamp(marker, -1, scintilla.Markers.Count - 1); - scintilla.DirectMessage(NativeMethods.SCI_MARKERDELETE, new IntPtr(Index), new IntPtr(marker)); + marker = Helpers.Clamp(marker, -1, this.scintilla.Markers.Count - 1); + this.scintilla.DirectMessage(NativeMethods.SCI_MARKERDELETE, new IntPtr(Index), new IntPtr(marker)); } /// @@ -109,7 +109,7 @@ public void MarkerDelete(int marker) /// An unsigned 32-bit value with each bit cooresponding to one of the 32 zero-based indexes. public uint MarkerGet() { - var mask = scintilla.DirectMessage(NativeMethods.SCI_MARKERGET, new IntPtr(Index)).ToInt32(); + int mask = this.scintilla.DirectMessage(NativeMethods.SCI_MARKERGET, new IntPtr(Index)).ToInt32(); return unchecked((uint)mask); } @@ -121,8 +121,8 @@ public uint MarkerGet() /// For example, the mask for marker index 10 is 1 shifted left 10 times (1 << 10). public int MarkerNext(uint markerMask) { - var mask = unchecked((int)markerMask); - return scintilla.DirectMessage(NativeMethods.SCI_MARKERNEXT, new IntPtr(Index), new IntPtr(mask)).ToInt32(); + int mask = unchecked((int)markerMask); + return this.scintilla.DirectMessage(NativeMethods.SCI_MARKERNEXT, new IntPtr(Index), new IntPtr(mask)).ToInt32(); } /// @@ -133,8 +133,8 @@ public int MarkerNext(uint markerMask) /// For example, the mask for marker index 10 is 1 shifted left 10 times (1 << 10). public int MarkerPrevious(uint markerMask) { - var mask = unchecked((int)markerMask); - return scintilla.DirectMessage(NativeMethods.SCI_MARKERPREVIOUS, new IntPtr(Index), new IntPtr(mask)).ToInt32(); + int mask = unchecked((int)markerMask); + return this.scintilla.DirectMessage(NativeMethods.SCI_MARKERPREVIOUS, new IntPtr(Index), new IntPtr(mask)).ToInt32(); } /// @@ -144,7 +144,7 @@ public int MarkerPrevious(uint markerMask) /// public void ToggleFold() { - scintilla.DirectMessage(NativeMethods.SCI_TOGGLEFOLD, new IntPtr(Index)); + this.scintilla.DirectMessage(NativeMethods.SCI_TOGGLEFOLD, new IntPtr(Index)); } /// @@ -157,13 +157,13 @@ public unsafe void ToggleFoldShowText(string text) { if (string.IsNullOrEmpty(text)) { - scintilla.DirectMessage(NativeMethods.SCI_TOGGLEFOLDSHOWTEXT, new IntPtr(Index), IntPtr.Zero); + this.scintilla.DirectMessage(NativeMethods.SCI_TOGGLEFOLDSHOWTEXT, new IntPtr(Index), IntPtr.Zero); } else { - var bytes = Helpers.GetBytes(text, scintilla.Encoding, zeroTerminated: true); + byte[] bytes = Helpers.GetBytes(text, this.scintilla.Encoding, zeroTerminated: true); fixed (byte* bp = bytes) - scintilla.DirectMessage(NativeMethods.SCI_TOGGLEFOLDSHOWTEXT, new IntPtr(Index), new IntPtr(bp)); + this.scintilla.DirectMessage(NativeMethods.SCI_TOGGLEFOLDSHOWTEXT, new IntPtr(Index), new IntPtr(bp)); } } @@ -179,7 +179,7 @@ public int AnnotationLines { get { - return scintilla.DirectMessage(NativeMethods.SCI_ANNOTATIONGETLINES, new IntPtr(Index)).ToInt32(); + return this.scintilla.DirectMessage(NativeMethods.SCI_ANNOTATIONGETLINES, new IntPtr(Index)).ToInt32(); } } @@ -195,12 +195,12 @@ public int AnnotationStyle { get { - return scintilla.DirectMessage(NativeMethods.SCI_ANNOTATIONGETSTYLE, new IntPtr(Index)).ToInt32(); + return this.scintilla.DirectMessage(NativeMethods.SCI_ANNOTATIONGETSTYLE, new IntPtr(Index)).ToInt32(); } set { - value = Helpers.Clamp(value, 0, scintilla.Styles.Count - 1); - scintilla.DirectMessage(NativeMethods.SCI_ANNOTATIONSETSTYLE, new IntPtr(Index), new IntPtr(value)); + value = Helpers.Clamp(value, 0, this.scintilla.Styles.Count - 1); + this.scintilla.DirectMessage(NativeMethods.SCI_ANNOTATIONSETSTYLE, new IntPtr(Index), new IntPtr(value)); } } @@ -221,36 +221,36 @@ public unsafe byte[] AnnotationStyles { get { - var length = scintilla.DirectMessage(NativeMethods.SCI_ANNOTATIONGETTEXT, new IntPtr(Index)).ToInt32(); + int length = this.scintilla.DirectMessage(NativeMethods.SCI_ANNOTATIONGETTEXT, new IntPtr(Index)).ToInt32(); if (length == 0) return new byte[0]; - var text = new byte[length + 1]; - var styles = new byte[length + 1]; + byte[] text = new byte[length + 1]; + byte[] styles = new byte[length + 1]; fixed (byte* textPtr = text) fixed (byte* stylePtr = styles) { - scintilla.DirectMessage(NativeMethods.SCI_ANNOTATIONGETTEXT, new IntPtr(Index), new IntPtr(textPtr)); - scintilla.DirectMessage(NativeMethods.SCI_ANNOTATIONGETSTYLES, new IntPtr(Index), new IntPtr(stylePtr)); + this.scintilla.DirectMessage(NativeMethods.SCI_ANNOTATIONGETTEXT, new IntPtr(Index), new IntPtr(textPtr)); + this.scintilla.DirectMessage(NativeMethods.SCI_ANNOTATIONGETSTYLES, new IntPtr(Index), new IntPtr(stylePtr)); - return Helpers.ByteToCharStyles(stylePtr, textPtr, length, scintilla.Encoding); + return Helpers.ByteToCharStyles(stylePtr, textPtr, length, this.scintilla.Encoding); } } set { - var length = scintilla.DirectMessage(NativeMethods.SCI_ANNOTATIONGETTEXT, new IntPtr(Index)).ToInt32(); + int length = this.scintilla.DirectMessage(NativeMethods.SCI_ANNOTATIONGETTEXT, new IntPtr(Index)).ToInt32(); if (length == 0) return; - var text = new byte[length + 1]; + byte[] text = new byte[length + 1]; fixed (byte* textPtr = text) { - scintilla.DirectMessage(NativeMethods.SCI_ANNOTATIONGETTEXT, new IntPtr(Index), new IntPtr(textPtr)); + this.scintilla.DirectMessage(NativeMethods.SCI_ANNOTATIONGETTEXT, new IntPtr(Index), new IntPtr(textPtr)); - var styles = Helpers.CharToByteStyles(value ?? new byte[0], textPtr, length, scintilla.Encoding); + byte[] styles = Helpers.CharToByteStyles(value ?? new byte[0], textPtr, length, this.scintilla.Encoding); fixed (byte* stylePtr = styles) - scintilla.DirectMessage(NativeMethods.SCI_ANNOTATIONSETSTYLES, new IntPtr(Index), new IntPtr(stylePtr)); + this.scintilla.DirectMessage(NativeMethods.SCI_ANNOTATIONSETSTYLES, new IntPtr(Index), new IntPtr(stylePtr)); } } } @@ -263,15 +263,15 @@ public unsafe string AnnotationText { get { - var length = scintilla.DirectMessage(NativeMethods.SCI_ANNOTATIONGETTEXT, new IntPtr(Index)).ToInt32(); + int length = this.scintilla.DirectMessage(NativeMethods.SCI_ANNOTATIONGETTEXT, new IntPtr(Index)).ToInt32(); if (length == 0) return string.Empty; - var bytes = new byte[length + 1]; + byte[] bytes = new byte[length + 1]; fixed (byte* bp = bytes) { - scintilla.DirectMessage(NativeMethods.SCI_ANNOTATIONGETTEXT, new IntPtr(Index), new IntPtr(bp)); - return Helpers.GetString(new IntPtr(bp), length, scintilla.Encoding); + this.scintilla.DirectMessage(NativeMethods.SCI_ANNOTATIONGETTEXT, new IntPtr(Index), new IntPtr(bp)); + return Helpers.GetString(new IntPtr(bp), length, this.scintilla.Encoding); } } set @@ -280,13 +280,13 @@ public unsafe string AnnotationText if (value == null) { // Scintilla docs suggest that setting to NULL rather than an empty string will free memory - scintilla.DirectMessage(NativeMethods.SCI_ANNOTATIONSETTEXT, new IntPtr(Index), IntPtr.Zero); + this.scintilla.DirectMessage(NativeMethods.SCI_ANNOTATIONSETTEXT, new IntPtr(Index), IntPtr.Zero); } else { - var bytes = Helpers.GetBytes(value, scintilla.Encoding, zeroTerminated: true); + byte[] bytes = Helpers.GetBytes(value, this.scintilla.Encoding, zeroTerminated: true); fixed (byte* bp = bytes) - scintilla.DirectMessage(NativeMethods.SCI_ANNOTATIONSETTEXT, new IntPtr(Index), new IntPtr(bp)); + this.scintilla.DirectMessage(NativeMethods.SCI_ANNOTATIONSETTEXT, new IntPtr(Index), new IntPtr(bp)); } } } @@ -300,7 +300,7 @@ public int ContractedFoldNext { get { - return scintilla.DirectMessage(NativeMethods.SCI_CONTRACTEDFOLDNEXT, new IntPtr(Index)).ToInt32(); + return this.scintilla.DirectMessage(NativeMethods.SCI_CONTRACTEDFOLDNEXT, new IntPtr(Index)).ToInt32(); } } @@ -314,7 +314,7 @@ public int DisplayIndex { get { - return scintilla.DirectMessage(NativeMethods.SCI_VISIBLEFROMDOCLINE, new IntPtr(Index)).ToInt32(); + return this.scintilla.DirectMessage(NativeMethods.SCI_VISIBLEFROMDOCLINE, new IntPtr(Index)).ToInt32(); } } @@ -342,12 +342,12 @@ public bool Expanded { get { - return (scintilla.DirectMessage(NativeMethods.SCI_GETFOLDEXPANDED, new IntPtr(Index)) != IntPtr.Zero); + return this.scintilla.DirectMessage(NativeMethods.SCI_GETFOLDEXPANDED, new IntPtr(Index)) != IntPtr.Zero; } set { - var expanded = (value ? new IntPtr(1) : IntPtr.Zero); - scintilla.DirectMessage(NativeMethods.SCI_SETFOLDEXPANDED, new IntPtr(Index), expanded); + IntPtr expanded = value ? new IntPtr(1) : IntPtr.Zero; + this.scintilla.DirectMessage(NativeMethods.SCI_SETFOLDEXPANDED, new IntPtr(Index), expanded); } } @@ -359,15 +359,15 @@ public int FoldLevel { get { - var level = scintilla.DirectMessage(NativeMethods.SCI_GETFOLDLEVEL, new IntPtr(Index)).ToInt32(); - return (level & NativeMethods.SC_FOLDLEVELNUMBERMASK); + int level = this.scintilla.DirectMessage(NativeMethods.SCI_GETFOLDLEVEL, new IntPtr(Index)).ToInt32(); + return level & NativeMethods.SC_FOLDLEVELNUMBERMASK; } set { - var bits = (int)FoldLevelFlags; + int bits = (int)FoldLevelFlags; bits |= value; - scintilla.DirectMessage(NativeMethods.SCI_SETFOLDLEVEL, new IntPtr(Index), new IntPtr(bits)); + this.scintilla.DirectMessage(NativeMethods.SCI_SETFOLDLEVEL, new IntPtr(Index), new IntPtr(bits)); } } @@ -379,15 +379,15 @@ public FoldLevelFlags FoldLevelFlags { get { - var flags = scintilla.DirectMessage(NativeMethods.SCI_GETFOLDLEVEL, new IntPtr(Index)).ToInt32(); + int flags = this.scintilla.DirectMessage(NativeMethods.SCI_GETFOLDLEVEL, new IntPtr(Index)).ToInt32(); return (FoldLevelFlags)(flags & ~NativeMethods.SC_FOLDLEVELNUMBERMASK); } set { - var bits = FoldLevel; + int bits = FoldLevel; bits |= (int)value; - scintilla.DirectMessage(NativeMethods.SCI_SETFOLDLEVEL, new IntPtr(Index), new IntPtr(bits)); + this.scintilla.DirectMessage(NativeMethods.SCI_SETFOLDLEVEL, new IntPtr(Index), new IntPtr(bits)); } } @@ -400,7 +400,7 @@ public int FoldParent { get { - return scintilla.DirectMessage(NativeMethods.SCI_GETFOLDPARENT, new IntPtr(Index)).ToInt32(); + return this.scintilla.DirectMessage(NativeMethods.SCI_GETFOLDPARENT, new IntPtr(Index)).ToInt32(); } } @@ -413,7 +413,7 @@ public int Height { get { - return scintilla.DirectMessage(NativeMethods.SCI_TEXTHEIGHT, new IntPtr(Index)).ToInt32(); + return this.scintilla.DirectMessage(NativeMethods.SCI_TEXTHEIGHT, new IntPtr(Index)).ToInt32(); } } @@ -431,7 +431,7 @@ public int Length { get { - return scintilla.Lines.CharLineLength(Index); + return this.scintilla.Lines.CharLineLength(Index); } } @@ -447,12 +447,12 @@ public int MarginStyle { get { - return scintilla.DirectMessage(NativeMethods.SCI_MARGINGETSTYLE, new IntPtr(Index)).ToInt32(); + return this.scintilla.DirectMessage(NativeMethods.SCI_MARGINGETSTYLE, new IntPtr(Index)).ToInt32(); } set { - value = Helpers.Clamp(value, 0, scintilla.Styles.Count - 1); - scintilla.DirectMessage(NativeMethods.SCI_MARGINSETSTYLE, new IntPtr(Index), new IntPtr(value)); + value = Helpers.Clamp(value, 0, this.scintilla.Styles.Count - 1); + this.scintilla.DirectMessage(NativeMethods.SCI_MARGINSETSTYLE, new IntPtr(Index), new IntPtr(value)); } } @@ -473,36 +473,36 @@ public unsafe byte[] MarginStyles { get { - var length = scintilla.DirectMessage(NativeMethods.SCI_MARGINGETTEXT, new IntPtr(Index)).ToInt32(); + int length = this.scintilla.DirectMessage(NativeMethods.SCI_MARGINGETTEXT, new IntPtr(Index)).ToInt32(); if (length == 0) return new byte[0]; - var text = new byte[length + 1]; - var styles = new byte[length + 1]; + byte[] text = new byte[length + 1]; + byte[] styles = new byte[length + 1]; fixed (byte* textPtr = text) fixed (byte* stylePtr = styles) { - scintilla.DirectMessage(NativeMethods.SCI_MARGINGETTEXT, new IntPtr(Index), new IntPtr(textPtr)); - scintilla.DirectMessage(NativeMethods.SCI_MARGINGETSTYLES, new IntPtr(Index), new IntPtr(stylePtr)); + this.scintilla.DirectMessage(NativeMethods.SCI_MARGINGETTEXT, new IntPtr(Index), new IntPtr(textPtr)); + this.scintilla.DirectMessage(NativeMethods.SCI_MARGINGETSTYLES, new IntPtr(Index), new IntPtr(stylePtr)); - return Helpers.ByteToCharStyles(stylePtr, textPtr, length, scintilla.Encoding); + return Helpers.ByteToCharStyles(stylePtr, textPtr, length, this.scintilla.Encoding); } } set { - var length = scintilla.DirectMessage(NativeMethods.SCI_MARGINGETTEXT, new IntPtr(Index)).ToInt32(); + int length = this.scintilla.DirectMessage(NativeMethods.SCI_MARGINGETTEXT, new IntPtr(Index)).ToInt32(); if (length == 0) return; - var text = new byte[length + 1]; + byte[] text = new byte[length + 1]; fixed (byte* textPtr = text) { - scintilla.DirectMessage(NativeMethods.SCI_MARGINGETTEXT, new IntPtr(Index), new IntPtr(textPtr)); + this.scintilla.DirectMessage(NativeMethods.SCI_MARGINGETTEXT, new IntPtr(Index), new IntPtr(textPtr)); - var styles = Helpers.CharToByteStyles(value ?? new byte[0], textPtr, length, scintilla.Encoding); + byte[] styles = Helpers.CharToByteStyles(value ?? new byte[0], textPtr, length, this.scintilla.Encoding); fixed (byte* stylePtr = styles) - scintilla.DirectMessage(NativeMethods.SCI_MARGINSETSTYLES, new IntPtr(Index), new IntPtr(stylePtr)); + this.scintilla.DirectMessage(NativeMethods.SCI_MARGINSETSTYLES, new IntPtr(Index), new IntPtr(stylePtr)); } } } @@ -516,15 +516,15 @@ public unsafe string MarginText { get { - var length = scintilla.DirectMessage(NativeMethods.SCI_MARGINGETTEXT, new IntPtr(Index)).ToInt32(); + int length = this.scintilla.DirectMessage(NativeMethods.SCI_MARGINGETTEXT, new IntPtr(Index)).ToInt32(); if (length == 0) return string.Empty; - var bytes = new byte[length + 1]; + byte[] bytes = new byte[length + 1]; fixed (byte* bp = bytes) { - scintilla.DirectMessage(NativeMethods.SCI_MARGINGETTEXT, new IntPtr(Index), new IntPtr(bp)); - return Helpers.GetString(new IntPtr(bp), length, scintilla.Encoding); + this.scintilla.DirectMessage(NativeMethods.SCI_MARGINGETTEXT, new IntPtr(Index), new IntPtr(bp)); + return Helpers.GetString(new IntPtr(bp), length, this.scintilla.Encoding); } } set @@ -532,13 +532,13 @@ public unsafe string MarginText if (string.IsNullOrEmpty(value)) { // Scintilla docs suggest that setting to NULL rather than an empty string will free memory - scintilla.DirectMessage(NativeMethods.SCI_MARGINSETTEXT, new IntPtr(Index), IntPtr.Zero); + this.scintilla.DirectMessage(NativeMethods.SCI_MARGINSETTEXT, new IntPtr(Index), IntPtr.Zero); } else { - var bytes = Helpers.GetBytes(value, scintilla.Encoding, zeroTerminated: true); + byte[] bytes = Helpers.GetBytes(value, this.scintilla.Encoding, zeroTerminated: true); fixed (byte* bp = bytes) - scintilla.DirectMessage(NativeMethods.SCI_MARGINSETTEXT, new IntPtr(Index), new IntPtr(bp)); + this.scintilla.DirectMessage(NativeMethods.SCI_MARGINSETTEXT, new IntPtr(Index), new IntPtr(bp)); } } } @@ -551,7 +551,7 @@ public int Position { get { - return scintilla.Lines.CharPositionFromLine(Index); + return this.scintilla.Lines.CharPositionFromLine(Index); } } @@ -564,13 +564,13 @@ public unsafe string Text { get { - var start = scintilla.DirectMessage(NativeMethods.SCI_POSITIONFROMLINE, new IntPtr(Index)); - var length = scintilla.DirectMessage(NativeMethods.SCI_LINELENGTH, new IntPtr(Index)); - var ptr = scintilla.DirectMessage(NativeMethods.SCI_GETRANGEPOINTER, start, length); + IntPtr start = this.scintilla.DirectMessage(NativeMethods.SCI_POSITIONFROMLINE, new IntPtr(Index)); + IntPtr length = this.scintilla.DirectMessage(NativeMethods.SCI_LINELENGTH, new IntPtr(Index)); + IntPtr ptr = this.scintilla.DirectMessage(NativeMethods.SCI_GETRANGEPOINTER, start, length); if (ptr == IntPtr.Zero) return string.Empty; - var text = new string((sbyte*)ptr, 0, length.ToInt32(), scintilla.Encoding); + string text = new((sbyte*)ptr, 0, length.ToInt32(), this.scintilla.Encoding); return text; } } @@ -583,11 +583,11 @@ public int Indentation { get { - return (scintilla.DirectMessage(NativeMethods.SCI_GETLINEINDENTATION, new IntPtr(Index)).ToInt32()); + return this.scintilla.DirectMessage(NativeMethods.SCI_GETLINEINDENTATION, new IntPtr(Index)).ToInt32(); } set { - scintilla.DirectMessage(NativeMethods.SCI_SETLINEINDENTATION, new IntPtr(Index), new IntPtr(value)); + this.scintilla.DirectMessage(NativeMethods.SCI_SETLINEINDENTATION, new IntPtr(Index), new IntPtr(value)); } } @@ -598,8 +598,8 @@ public int IndentPosition { get { - var pos = scintilla.DirectMessage(NativeMethods.SCI_GETLINEINDENTPOSITION, new IntPtr(Index)); - return scintilla.Lines.ByteToCharPosition(pos.ToInt32()); + IntPtr pos = this.scintilla.DirectMessage(NativeMethods.SCI_GETLINEINDENTPOSITION, new IntPtr(Index)); + return this.scintilla.Lines.ByteToCharPosition(pos.ToInt32()); } } @@ -613,7 +613,7 @@ public bool Visible { get { - return (scintilla.DirectMessage(NativeMethods.SCI_GETLINEVISIBLE, new IntPtr(Index)) != IntPtr.Zero); + return this.scintilla.DirectMessage(NativeMethods.SCI_GETLINEVISIBLE, new IntPtr(Index)) != IntPtr.Zero; } } @@ -625,7 +625,7 @@ public int WrapCount { get { - return scintilla.DirectMessage(NativeMethods.SCI_WRAPCOUNT, new IntPtr(Index)).ToInt32(); + return this.scintilla.DirectMessage(NativeMethods.SCI_WRAPCOUNT, new IntPtr(Index)).ToInt32(); } } diff --git a/Scintilla.NET/LineCollection.cs b/Scintilla.NET/LineCollection.cs index 9fbe173..f22a1ed 100644 --- a/Scintilla.NET/LineCollection.cs +++ b/Scintilla.NET/LineCollection.cs @@ -33,12 +33,12 @@ public class LineCollection : IEnumerable private void AdjustLineLength(int index, int delta) { MoveStep(index); - stepLength += delta; + this.stepLength += delta; // Invalidate multibyte flag - var perLine = perLineData[index]; + PerLine perLine = this.perLineData[index]; perLine.ContainsMultibyte = ContainsMultibyte.Unkown; - perLineData[index] = perLine; + this.perLineData[index] = perLine; } /// @@ -47,11 +47,11 @@ private void AdjustLineLength(int index, int delta) internal int ByteToCharPosition(int pos) { Debug.Assert(pos >= 0); - Debug.Assert(pos <= scintilla.DirectMessage(NativeMethods.SCI_GETLENGTH).ToInt32()); + Debug.Assert(pos <= this.scintilla.DirectMessage(NativeMethods.SCI_GETLENGTH).ToInt32()); - var line = scintilla.DirectMessage(NativeMethods.SCI_LINEFROMPOSITION, new IntPtr(pos)).ToInt32(); - var byteStart = scintilla.DirectMessage(NativeMethods.SCI_POSITIONFROMLINE, new IntPtr(line)).ToInt32(); - var count = CharPositionFromLine(line) + GetCharCount(byteStart, pos - byteStart); + int line = this.scintilla.DirectMessage(NativeMethods.SCI_LINEFROMPOSITION, new IntPtr(pos)).ToInt32(); + int byteStart = this.scintilla.DirectMessage(NativeMethods.SCI_POSITIONFROMLINE, new IntPtr(line)).ToInt32(); + int count = CharPositionFromLine(line) + GetCharCount(byteStart, pos - byteStart); return count; } @@ -68,12 +68,12 @@ internal int CharLineLength(int index) // the start of the line following. We keep a terminal (faux) line at // the end of the list so we can calculate the length of the last line. - if (index + 1 <= stepLine) - return perLineData[index + 1].Start - perLineData[index].Start; - else if (index <= stepLine) - return (perLineData[index + 1].Start + stepLength) - perLineData[index].Start; + if (index + 1 <= this.stepLine) + return this.perLineData[index + 1].Start - this.perLineData[index].Start; + else if (index <= this.stepLine) + return this.perLineData[index + 1].Start + this.stepLength - this.perLineData[index].Start; else - return (perLineData[index + 1].Start + stepLength) - (perLineData[index].Start + stepLength); + return this.perLineData[index + 1].Start + this.stepLength - (this.perLineData[index].Start + this.stepLength); } /// @@ -82,11 +82,11 @@ internal int CharLineLength(int index) internal int CharPositionFromLine(int index) { Debug.Assert(index >= 0); - Debug.Assert(index < perLineData.Count); // Allow query of terminal line start + Debug.Assert(index < this.perLineData.Count); // Allow query of terminal line start - var start = perLineData[index].Start; - if (index > stepLine) - start += stepLength; + int start = this.perLineData[index].Start; + if (index > this.stepLine) + start += this.stepLength; return start; } @@ -97,22 +97,22 @@ internal int CharToWideBytePosition(int pos) Debug.Assert(pos <= TextLength); // Adjust to the nearest line start - var line = LineFromCharPosition(pos); - var bytePos = scintilla.DirectMessage(NativeMethods.SCI_POSITIONFROMLINE, new IntPtr(line)).ToInt32(); + int line = LineFromCharPosition(pos); + int bytePos = this.scintilla.DirectMessage(NativeMethods.SCI_POSITIONFROMLINE, new IntPtr(line)).ToInt32(); pos -= CharPositionFromLine(line); // Optimization when the line contains NO multibyte characters if (!LineContainsMultibyteChar(line)) - return (bytePos + pos); + return bytePos + pos; int prevBytePos; while (pos > 0) { // hang onto the prev byte position so we can determine if we are single or multi byte prevBytePos = bytePos; - bytePos = scintilla.DirectMessage(NativeMethods.SCI_POSITIONRELATIVE, new IntPtr(bytePos), new IntPtr(1)).ToInt32(); + bytePos = this.scintilla.DirectMessage(NativeMethods.SCI_POSITIONRELATIVE, new IntPtr(bytePos), new IntPtr(1)).ToInt32(); - if ((bytePos - prevBytePos) == 1) + if (bytePos - prevBytePos == 1) { // if the byte position is 1, we are single byte pos--; @@ -133,18 +133,18 @@ internal int CharToBytePosition(int pos) Debug.Assert(pos <= TextLength); // Adjust to the nearest line start - var line = LineFromCharPosition(pos); - var bytePos = scintilla.DirectMessage(NativeMethods.SCI_POSITIONFROMLINE, new IntPtr(line)).ToInt32(); + int line = LineFromCharPosition(pos); + int bytePos = this.scintilla.DirectMessage(NativeMethods.SCI_POSITIONFROMLINE, new IntPtr(line)).ToInt32(); pos -= CharPositionFromLine(line); // Optimization when the line contains NO multibyte characters if (!LineContainsMultibyteChar(line)) - return (bytePos + pos); + return bytePos + pos; while (pos > 0) { // Move char-by-char - bytePos = scintilla.DirectMessage(NativeMethods.SCI_POSITIONRELATIVE, new IntPtr(bytePos), + bytePos = this.scintilla.DirectMessage(NativeMethods.SCI_POSITIONRELATIVE, new IntPtr(bytePos), new IntPtr(1)).ToInt32(); pos--; } @@ -159,13 +159,13 @@ private void DeletePerLine(int index) MoveStep(index); // Subtract the line length - stepLength -= CharLineLength(index); + this.stepLength -= CharLineLength(index); // Remove the line - perLineData.RemoveAt(index); + this.perLineData.RemoveAt(index); // Move the step to the line before the one removed - stepLine--; + this.stepLine--; } #if DEBUG @@ -176,11 +176,9 @@ private void DeletePerLine(int index) /// A string representing the line buffer. public string Dump() { - using (var writer = new StringWriter()) - { - scintilla.Lines.Dump(writer); - return writer.ToString(); - } + using var writer = new StringWriter(); + this.scintilla.Lines.Dump(writer); + return writer.ToString(); } /// @@ -189,28 +187,28 @@ public string Dump() /// The writer to use for dumping the line buffer. public unsafe void Dump(TextWriter writer) { - var totalChars = 0; + int totalChars = 0; - for (int i = 0; i < perLineData.Count; i++) + for (int i = 0; i < this.perLineData.Count; i++) { - var error = totalChars == CharPositionFromLine(i) ? null : "*"; - if (i == perLineData.Count - 1) + string error = totalChars == CharPositionFromLine(i) ? null : "*"; + if (i == this.perLineData.Count - 1) { writer.WriteLine("{0}[{1}] {2} (terminal)", error, i, CharPositionFromLine(i)); } else { - var len = scintilla.DirectMessage(NativeMethods.SCI_GETLINE, new IntPtr(i)).ToInt32(); - var bytes = new byte[len]; + int len = this.scintilla.DirectMessage(NativeMethods.SCI_GETLINE, new IntPtr(i)).ToInt32(); + byte[] bytes = new byte[len]; fixed (byte* ptr = bytes) - scintilla.DirectMessage(NativeMethods.SCI_GETLINE, new IntPtr(i), new IntPtr(ptr)); + this.scintilla.DirectMessage(NativeMethods.SCI_GETLINE, new IntPtr(i), new IntPtr(ptr)); - var str = scintilla.Encoding.GetString(bytes); - var containsMultibyte = "U"; - if (perLineData[i].ContainsMultibyte == ContainsMultibyte.Yes) + string str = this.scintilla.Encoding.GetString(bytes); + string containsMultibyte = "U"; + if (this.perLineData[i].ContainsMultibyte == ContainsMultibyte.Yes) containsMultibyte = "Y"; - else if (perLineData[i].ContainsMultibyte == ContainsMultibyte.No) + else if (this.perLineData[i].ContainsMultibyte == ContainsMultibyte.No) containsMultibyte = "N"; writer.WriteLine("{0}[{1}] {2}:{3}:{4} {5}", error, i, CharPositionFromLine(i), str.Length, containsMultibyte, str.Replace("\r", "\\r").Replace("\n", "\\n")); @@ -226,8 +224,8 @@ public unsafe void Dump(TextWriter writer) /// private int GetCharCount(int pos, int length) { - var ptr = scintilla.DirectMessage(NativeMethods.SCI_GETRANGEPOINTER, new IntPtr(pos), new IntPtr(length)); - return GetCharCount(ptr, length, scintilla.Encoding); + IntPtr ptr = this.scintilla.DirectMessage(NativeMethods.SCI_GETRANGEPOINTER, new IntPtr(pos), new IntPtr(length)); + return GetCharCount(ptr, length, this.scintilla.Encoding); } /// @@ -239,7 +237,7 @@ private static unsafe int GetCharCount(IntPtr text, int length, Encoding encodin return 0; // Never use SCI_COUNTCHARACTERS. It counts CRLF as 1 char! - var count = encoding.GetCharCount((byte*)text, length); + int count = encoding.GetCharCount((byte*)text, length); return count; } @@ -258,23 +256,23 @@ public IEnumerator GetEnumerator() IEnumerator IEnumerable.GetEnumerator() { - return this.GetEnumerator(); + return GetEnumerator(); } private bool LineContainsMultibyteChar(int index) { - var perLine = perLineData[index]; + PerLine perLine = this.perLineData[index]; if (perLine.ContainsMultibyte == ContainsMultibyte.Unkown) { perLine.ContainsMultibyte = - (scintilla.DirectMessage(NativeMethods.SCI_LINELENGTH, new IntPtr(index)).ToInt32() == CharLineLength(index)) + (this.scintilla.DirectMessage(NativeMethods.SCI_LINELENGTH, new IntPtr(index)).ToInt32() == CharLineLength(index)) ? ContainsMultibyte.No : ContainsMultibyte.Yes; - perLineData[index] = perLine; + this.perLineData[index] = perLine; } - return (perLine.ContainsMultibyte == ContainsMultibyte.Yes); + return perLine.ContainsMultibyte == ContainsMultibyte.Yes; } /// @@ -288,13 +286,13 @@ internal int LineFromCharPosition(int pos) // http://en.wikipedia.org/wiki/Binary_search_algorithm // System.Collections.Generic.ArraySortHelper.InternalBinarySearch - var low = 0; - var high = Count - 1; + int low = 0; + int high = Count - 1; while (low <= high) { - var mid = low + ((high - low) / 2); - var start = CharPositionFromLine(mid); + int mid = low + (high - low) / 2; + int start = CharPositionFromLine(mid); if (pos == start) return mid; @@ -318,75 +316,77 @@ private void InsertPerLine(int index, int length = 0) MoveStep(index); PerLine data; - var lineStart = 0; + int lineStart = 0; // Add the new line length to the existing line start - data = perLineData[index]; + data = this.perLineData[index]; lineStart = data.Start; data.Start += length; - perLineData[index] = data; + this.perLineData[index] = data; // Insert the new line data = new PerLine { Start = lineStart }; - perLineData.Insert(index, data); + this.perLineData.Insert(index, data); // Move the step - stepLength += length; - stepLine++; + this.stepLength += length; + this.stepLine++; } private void MoveStep(int line) { - if (stepLength == 0) + if (this.stepLength == 0) { - stepLine = line; + this.stepLine = line; } - else if (stepLine < line) + else if (this.stepLine < line) { PerLine data; - while (stepLine < line) + while (this.stepLine < line) { - stepLine++; - data = perLineData[stepLine]; - data.Start += stepLength; - perLineData[stepLine] = data; + this.stepLine++; + data = this.perLineData[this.stepLine]; + data.Start += this.stepLength; + this.perLineData[this.stepLine] = data; } } - else if (stepLine > line) + else if (this.stepLine > line) { PerLine data; - while (stepLine > line) + while (this.stepLine > line) { - data = perLineData[stepLine]; - data.Start -= stepLength; - perLineData[stepLine] = data; - stepLine--; + data = this.perLineData[this.stepLine]; + data.Start -= this.stepLength; + this.perLineData[this.stepLine] = data; + this.stepLine--; } } } internal void RebuildLineData() { - stepLine = 0; - stepLength = 0; + this.stepLine = 0; + this.stepLength = 0; - perLineData = new GapBuffer(); - perLineData.Add(new PerLine { Start = 0 }); - perLineData.Add(new PerLine { Start = 0 }); // Terminal + this.perLineData = + [ + new PerLine { Start = 0 }, + new PerLine { Start = 0 }, // Terminal + ]; // Fake an insert notification var scn = new NativeMethods.SCNotification(); - var adjustedLines = scintilla.DirectMessage(NativeMethods.SCI_GETLINECOUNT).ToInt32() - 1; + int adjustedLines = this.scintilla.DirectMessage(NativeMethods.SCI_GETLINECOUNT).ToInt32() - 1; scn.linesAdded = new IntPtr(adjustedLines); scn.position = IntPtr.Zero; - scn.length = scintilla.DirectMessage(NativeMethods.SCI_GETLENGTH); - scn.text = scintilla.DirectMessage(NativeMethods.SCI_GETRANGEPOINTER, scn.position, scn.length); + scn.length = this.scintilla.DirectMessage(NativeMethods.SCI_GETLENGTH); + scn.text = this.scintilla.DirectMessage(NativeMethods.SCI_GETRANGEPOINTER, scn.position, scn.length); TrackInsertText(scn); } private void scintilla_SCNotification(object sender, SCNotificationEventArgs e) { - var scn = e.SCNotification; + NativeMethods.SCNotification scn = e.SCNotification; switch (scn.nmhdr.code) { case NativeMethods.SCN_MODIFIED: @@ -410,21 +410,21 @@ private void ScnModified(NativeMethods.SCNotification scn) private void TrackDeleteText(NativeMethods.SCNotification scn) { - var startLine = scintilla.DirectMessage(NativeMethods.SCI_LINEFROMPOSITION, scn.position).ToInt32(); + int startLine = this.scintilla.DirectMessage(NativeMethods.SCI_LINEFROMPOSITION, scn.position).ToInt32(); if (scn.linesAdded == IntPtr.Zero) { // That was easy - var delta = GetCharCount(scn.text, scn.length.ToInt32(), scintilla.Encoding); + int delta = GetCharCount(scn.text, scn.length.ToInt32(), this.scintilla.Encoding); AdjustLineLength(startLine, delta * -1); } else { // Adjust the existing line - var lineByteStart = scintilla.DirectMessage(NativeMethods.SCI_POSITIONFROMLINE, new IntPtr(startLine)).ToInt32(); - var lineByteLength = scintilla.DirectMessage(NativeMethods.SCI_LINELENGTH, new IntPtr(startLine)).ToInt32(); + int lineByteStart = this.scintilla.DirectMessage(NativeMethods.SCI_POSITIONFROMLINE, new IntPtr(startLine)).ToInt32(); + int lineByteLength = this.scintilla.DirectMessage(NativeMethods.SCI_LINELENGTH, new IntPtr(startLine)).ToInt32(); AdjustLineLength(startLine, GetCharCount(lineByteStart, lineByteLength) - CharLineLength(startLine)); - var linesRemoved = scn.linesAdded.ToInt32() * -1; + int linesRemoved = scn.linesAdded.ToInt32() * -1; for (int i = 0; i < linesRemoved; i++) { // Deleted line @@ -435,30 +435,30 @@ private void TrackDeleteText(NativeMethods.SCNotification scn) private void TrackInsertText(NativeMethods.SCNotification scn) { - var startLine = scintilla.DirectMessage(NativeMethods.SCI_LINEFROMPOSITION, scn.position).ToInt32(); + int startLine = this.scintilla.DirectMessage(NativeMethods.SCI_LINEFROMPOSITION, scn.position).ToInt32(); if (scn.linesAdded == IntPtr.Zero) { // That was easy - var delta = GetCharCount(scn.position.ToInt32(), scn.length.ToInt32()); + int delta = GetCharCount(scn.position.ToInt32(), scn.length.ToInt32()); AdjustLineLength(startLine, delta); } else { - var lineByteStart = 0; - var lineByteLength = 0; + int lineByteStart = 0; + int lineByteLength = 0; // Adjust existing line - lineByteStart = scintilla.DirectMessage(NativeMethods.SCI_POSITIONFROMLINE, new IntPtr(startLine)).ToInt32(); - lineByteLength = scintilla.DirectMessage(NativeMethods.SCI_LINELENGTH, new IntPtr(startLine)).ToInt32(); + lineByteStart = this.scintilla.DirectMessage(NativeMethods.SCI_POSITIONFROMLINE, new IntPtr(startLine)).ToInt32(); + lineByteLength = this.scintilla.DirectMessage(NativeMethods.SCI_LINELENGTH, new IntPtr(startLine)).ToInt32(); AdjustLineLength(startLine, GetCharCount(lineByteStart, lineByteLength) - CharLineLength(startLine)); for (int i = 1; i <= scn.linesAdded.ToInt32(); i++) { - var line = startLine + i; + int line = startLine + i; // Insert new line lineByteStart += lineByteLength; - lineByteLength = scintilla.DirectMessage(NativeMethods.SCI_LINELENGTH, new IntPtr(line)).ToInt32(); + lineByteLength = this.scintilla.DirectMessage(NativeMethods.SCI_LINELENGTH, new IntPtr(line)).ToInt32(); InsertPerLine(line, GetCharCount(lineByteStart, lineByteLength)); } } @@ -476,7 +476,7 @@ public bool AllLinesVisible { get { - return (scintilla.DirectMessage(NativeMethods.SCI_GETALLLINESVISIBLE) != IntPtr.Zero); + return this.scintilla.DirectMessage(NativeMethods.SCI_GETALLLINESVISIBLE) != IntPtr.Zero; } } @@ -489,7 +489,7 @@ public int Count get { // Subtract the terminal line - return (perLineData.Count - 1); + return this.perLineData.Count - 1; } } @@ -501,7 +501,7 @@ internal int TextLength get { // Where the terminal line begins - return CharPositionFromLine(perLineData.Count - 1); + return CharPositionFromLine(this.perLineData.Count - 1); } } @@ -515,7 +515,7 @@ public Line this[int index] get { index = Helpers.Clamp(index, 0, Count - 1); - return new Line(scintilla, index); + return new Line(this.scintilla, index); } } @@ -532,9 +532,11 @@ public LineCollection(Scintilla scintilla) this.scintilla = scintilla; this.scintilla.SCNotification += scintilla_SCNotification; - this.perLineData = new GapBuffer(); - this.perLineData.Add(new PerLine { Start = 0 }); - this.perLineData.Add(new PerLine { Start = 0 }); // Terminal + this.perLineData = + [ + new PerLine { Start = 0 }, + new PerLine { Start = 0 }, // Terminal + ]; } #endregion Constructors diff --git a/Scintilla.NET/Loader.cs b/Scintilla.NET/Loader.cs index 6e32e40..fa733ea 100644 --- a/Scintilla.NET/Loader.cs +++ b/Scintilla.NET/Loader.cs @@ -16,10 +16,10 @@ public unsafe bool AddData(char[] data, int length) if (data != null) { length = Helpers.Clamp(length, 0, data.Length); - var bytes = Helpers.GetBytes(data, length, encoding, zeroTerminated: false); + byte[] bytes = Helpers.GetBytes(data, length, this.encoding, zeroTerminated: false); fixed (byte* bp = bytes) { - var status = (IntPtr.Size == 4 ? loader32.AddData(self, bp, bytes.Length) : loader64.AddData(self, bp, bytes.Length)); + int status = IntPtr.Size == 4 ? this.loader32.AddData(this.self, bp, bytes.Length) : this.loader64.AddData(this.self, bp, bytes.Length); if (status != NativeMethods.SC_STATUS_OK) return false; } @@ -30,14 +30,14 @@ public unsafe bool AddData(char[] data, int length) public Document ConvertToDocument() { - var ptr = (IntPtr.Size == 4 ? loader32.ConvertToDocument(self) : loader64.ConvertToDocument(self)); + IntPtr ptr = IntPtr.Size == 4 ? this.loader32.ConvertToDocument(this.self) : this.loader64.ConvertToDocument(this.self); var document = new Document { Value = ptr }; return document; } public int Release() { - var count = (IntPtr.Size == 4 ? loader32.Release(self) : loader64.Release(self)); + int count = IntPtr.Size == 4 ? this.loader32.Release(this.self) : this.loader64.Release(this.self); return count; } @@ -59,9 +59,9 @@ public unsafe Loader(IntPtr ptr, Encoding encoding) // architecture, the function calling conventions can be different. IntPtr vfptr = *(IntPtr*)ptr; - if(IntPtr.Size == 4) - loader32 = (NativeMethods.ILoaderVTable32)Marshal.PtrToStructure(vfptr, typeof(NativeMethods.ILoaderVTable32)); + if (IntPtr.Size == 4) + this.loader32 = (NativeMethods.ILoaderVTable32)Marshal.PtrToStructure(vfptr, typeof(NativeMethods.ILoaderVTable32)); else - loader64 = (NativeMethods.ILoaderVTable64)Marshal.PtrToStructure(vfptr, typeof(NativeMethods.ILoaderVTable64)); + this.loader64 = (NativeMethods.ILoaderVTable64)Marshal.PtrToStructure(vfptr, typeof(NativeMethods.ILoaderVTable64)); } } \ No newline at end of file diff --git a/Scintilla.NET/Margin.cs b/Scintilla.NET/Margin.cs index f82b3c9..261b985 100644 --- a/Scintilla.NET/Margin.cs +++ b/Scintilla.NET/Margin.cs @@ -25,7 +25,7 @@ public Color BackColor { get { - var color = scintilla.DirectMessage(NativeMethods.SCI_GETMARGINBACKN, new IntPtr(Index)).ToInt32(); + int color = this.scintilla.DirectMessage(NativeMethods.SCI_GETMARGINBACKN, new IntPtr(Index)).ToInt32(); return HelperMethods.FromWin32Color(color); } set @@ -33,8 +33,8 @@ public Color BackColor if (value.IsEmpty) value = Color.Black; - var color = HelperMethods.ToWin32Color(value); - scintilla.DirectMessage(NativeMethods.SCI_SETMARGINBACKN, new IntPtr(Index), new IntPtr(color)); + int color = HelperMethods.ToWin32Color(value); + this.scintilla.DirectMessage(NativeMethods.SCI_SETMARGINBACKN, new IntPtr(Index), new IntPtr(color)); } } @@ -46,12 +46,12 @@ public MarginCursor Cursor { get { - return (MarginCursor)scintilla.DirectMessage(NativeMethods.SCI_GETMARGINCURSORN, new IntPtr(Index)); + return (MarginCursor)this.scintilla.DirectMessage(NativeMethods.SCI_GETMARGINCURSORN, new IntPtr(Index)); } set { - var cursor = (int)value; - scintilla.DirectMessage(NativeMethods.SCI_SETMARGINCURSORN, new IntPtr(Index), new IntPtr(cursor)); + int cursor = (int)value; + this.scintilla.DirectMessage(NativeMethods.SCI_SETMARGINCURSORN, new IntPtr(Index), new IntPtr(cursor)); } } @@ -70,12 +70,12 @@ public bool Sensitive { get { - return (scintilla.DirectMessage(NativeMethods.SCI_GETMARGINSENSITIVEN, new IntPtr(Index)) != IntPtr.Zero); + return this.scintilla.DirectMessage(NativeMethods.SCI_GETMARGINSENSITIVEN, new IntPtr(Index)) != IntPtr.Zero; } set { - var sensitive = (value ? new IntPtr(1) : IntPtr.Zero); - scintilla.DirectMessage(NativeMethods.SCI_SETMARGINSENSITIVEN, new IntPtr(Index), sensitive); + IntPtr sensitive = value ? new IntPtr(1) : IntPtr.Zero; + this.scintilla.DirectMessage(NativeMethods.SCI_SETMARGINSENSITIVEN, new IntPtr(Index), sensitive); } } @@ -87,12 +87,12 @@ public MarginType Type { get { - return (MarginType)(scintilla.DirectMessage(NativeMethods.SCI_GETMARGINTYPEN, new IntPtr(Index))); + return (MarginType)this.scintilla.DirectMessage(NativeMethods.SCI_GETMARGINTYPEN, new IntPtr(Index)); } set { - var type = (int)value; - scintilla.DirectMessage(NativeMethods.SCI_SETMARGINTYPEN, new IntPtr(Index), new IntPtr(type)); + int type = (int)value; + this.scintilla.DirectMessage(NativeMethods.SCI_SETMARGINTYPEN, new IntPtr(Index), new IntPtr(type)); } } @@ -105,12 +105,12 @@ public int Width { get { - return scintilla.DirectMessage(NativeMethods.SCI_GETMARGINWIDTHN, new IntPtr(Index)).ToInt32(); + return this.scintilla.DirectMessage(NativeMethods.SCI_GETMARGINWIDTHN, new IntPtr(Index)).ToInt32(); } set { value = Helpers.ClampMin(value, 0); - scintilla.DirectMessage(NativeMethods.SCI_SETMARGINWIDTHN, new IntPtr(Index), new IntPtr(value)); + this.scintilla.DirectMessage(NativeMethods.SCI_SETMARGINWIDTHN, new IntPtr(Index), new IntPtr(value)); } } @@ -129,12 +129,12 @@ public uint Mask { get { - return unchecked((uint)scintilla.DirectMessage(NativeMethods.SCI_GETMARGINMASKN, new IntPtr(Index)).ToInt32()); + return unchecked((uint)this.scintilla.DirectMessage(NativeMethods.SCI_GETMARGINMASKN, new IntPtr(Index)).ToInt32()); } set { - var mask = unchecked((int)value); - scintilla.DirectMessage(NativeMethods.SCI_SETMARGINMASKN, new IntPtr(Index), new IntPtr(mask)); + int mask = unchecked((int)value); + this.scintilla.DirectMessage(NativeMethods.SCI_SETMARGINMASKN, new IntPtr(Index), new IntPtr(mask)); } } diff --git a/Scintilla.NET/MarginClickEventArgs.cs b/Scintilla.NET/MarginClickEventArgs.cs index 9e0c061..49f5dd6 100644 --- a/Scintilla.NET/MarginClickEventArgs.cs +++ b/Scintilla.NET/MarginClickEventArgs.cs @@ -32,10 +32,9 @@ public int Position { get { - if (position == null) - position = scintilla.Lines.ByteToCharPosition(bytePosition); + this.position ??= this.scintilla.Lines.ByteToCharPosition(this.bytePosition); - return (int)position; + return (int)this.position; } } diff --git a/Scintilla.NET/MarginCollection.cs b/Scintilla.NET/MarginCollection.cs index 5423672..1c562ab 100644 --- a/Scintilla.NET/MarginCollection.cs +++ b/Scintilla.NET/MarginCollection.cs @@ -17,7 +17,7 @@ public class MarginCollection : IEnumerable /// public void ClearAllText() { - scintilla.DirectMessage(NativeMethods.SCI_MARGINTEXTCLEARALL); + this.scintilla.DirectMessage(NativeMethods.SCI_MARGINTEXTCLEARALL); } /// @@ -35,7 +35,7 @@ public IEnumerator GetEnumerator() IEnumerator IEnumerable.GetEnumerator() { - return this.GetEnumerator(); + return GetEnumerator(); } /// @@ -48,12 +48,12 @@ public int Capacity { get { - return scintilla.DirectMessage(NativeMethods.SCI_GETMARGINS).ToInt32(); + return this.scintilla.DirectMessage(NativeMethods.SCI_GETMARGINS).ToInt32(); } set { value = Helpers.ClampMin(value, 0); - scintilla.DirectMessage(NativeMethods.SCI_SETMARGINS, new IntPtr(value)); + this.scintilla.DirectMessage(NativeMethods.SCI_SETMARGINS, new IntPtr(value)); } } @@ -83,12 +83,12 @@ public int Left { get { - return scintilla.DirectMessage(NativeMethods.SCI_GETMARGINLEFT).ToInt32(); + return this.scintilla.DirectMessage(NativeMethods.SCI_GETMARGINLEFT).ToInt32(); } set { value = Helpers.ClampMin(value, 0); - scintilla.DirectMessage(NativeMethods.SCI_SETMARGINLEFT, IntPtr.Zero, new IntPtr(value)); + this.scintilla.DirectMessage(NativeMethods.SCI_SETMARGINLEFT, IntPtr.Zero, new IntPtr(value)); } } @@ -128,12 +128,12 @@ public int Right { get { - return scintilla.DirectMessage(NativeMethods.SCI_GETMARGINRIGHT).ToInt32(); + return this.scintilla.DirectMessage(NativeMethods.SCI_GETMARGINRIGHT).ToInt32(); } set { value = Helpers.ClampMin(value, 0); - scintilla.DirectMessage(NativeMethods.SCI_SETMARGINRIGHT, IntPtr.Zero, new IntPtr(value)); + this.scintilla.DirectMessage(NativeMethods.SCI_SETMARGINRIGHT, IntPtr.Zero, new IntPtr(value)); } } @@ -150,7 +150,7 @@ public Margin this[int index] get { index = Helpers.Clamp(index, 0, Count - 1); - return new Margin(scintilla, index); + return new Margin(this.scintilla, index); } } diff --git a/Scintilla.NET/Marker.cs b/Scintilla.NET/Marker.cs index f365d2b..2a7b0f3 100644 --- a/Scintilla.NET/Marker.cs +++ b/Scintilla.NET/Marker.cs @@ -92,12 +92,12 @@ public unsafe void DefineRgbaImage(Bitmap image) if (image == null) return; - scintilla.DirectMessage(NativeMethods.SCI_RGBAIMAGESETWIDTH, new IntPtr(image.Width)); - scintilla.DirectMessage(NativeMethods.SCI_RGBAIMAGESETHEIGHT, new IntPtr(image.Height)); + this.scintilla.DirectMessage(NativeMethods.SCI_RGBAIMAGESETWIDTH, new IntPtr(image.Width)); + this.scintilla.DirectMessage(NativeMethods.SCI_RGBAIMAGESETHEIGHT, new IntPtr(image.Height)); - var bytes = Helpers.BitmapToArgb(image); + byte[] bytes = Helpers.BitmapToArgb(image); fixed (byte* bp = bytes) - scintilla.DirectMessage(NativeMethods.SCI_MARKERDEFINERGBAIMAGE, new IntPtr(Index), new IntPtr(bp)); + this.scintilla.DirectMessage(NativeMethods.SCI_MARKERDEFINERGBAIMAGE, new IntPtr(Index), new IntPtr(bp)); } /// @@ -105,7 +105,7 @@ public unsafe void DefineRgbaImage(Bitmap image) /// public void DeleteAll() { - scintilla.MarkerDeleteAll(Index); + this.scintilla.MarkerDeleteAll(Index); } /// @@ -117,7 +117,7 @@ public void DeleteAll() public void SetAlpha(int alpha) { alpha = Helpers.Clamp(alpha, 0, 255); - scintilla.DirectMessage(NativeMethods.SCI_MARKERSETALPHA, new IntPtr(Index), new IntPtr(alpha)); + this.scintilla.DirectMessage(NativeMethods.SCI_MARKERSETALPHA, new IntPtr(Index), new IntPtr(alpha)); } /// @@ -131,8 +131,8 @@ public void SetAlpha(int alpha) /// public void SetBackColor(Color color) { - var colour = HelperMethods.ToWin32Color(color); - scintilla.DirectMessage(NativeMethods.SCI_MARKERSETBACKTRANSLUCENT, new IntPtr(Index), new IntPtr(colour)); + int colour = HelperMethods.ToWin32Color(color); + this.scintilla.DirectMessage(NativeMethods.SCI_MARKERSETBACKTRANSLUCENT, new IntPtr(Index), new IntPtr(colour)); } /// @@ -141,8 +141,8 @@ public void SetBackColor(Color color) /// The foreground Color. The default is Black. public void SetForeColor(Color color) { - var colour = HelperMethods.ToWin32Color(color); - scintilla.DirectMessage(NativeMethods.SCI_MARKERSETFORETRANSLUCENT, new IntPtr(Index), new IntPtr(colour)); + int colour = HelperMethods.ToWin32Color(color); + this.scintilla.DirectMessage(NativeMethods.SCI_MARKERSETFORETRANSLUCENT, new IntPtr(Index), new IntPtr(colour)); } /// @@ -162,12 +162,12 @@ public MarkerSymbol Symbol { get { - return (MarkerSymbol)scintilla.DirectMessage(NativeMethods.SCI_MARKERSYMBOLDEFINED, new IntPtr(Index)); + return (MarkerSymbol)this.scintilla.DirectMessage(NativeMethods.SCI_MARKERSYMBOLDEFINED, new IntPtr(Index)); } set { - var markerSymbol = (int)value; - scintilla.DirectMessage(NativeMethods.SCI_MARKERDEFINE, new IntPtr(Index), new IntPtr(markerSymbol)); + int markerSymbol = (int)value; + this.scintilla.DirectMessage(NativeMethods.SCI_MARKERDEFINE, new IntPtr(Index), new IntPtr(markerSymbol)); } } diff --git a/Scintilla.NET/MarkerCollection.cs b/Scintilla.NET/MarkerCollection.cs index 07f9f1b..f44e359 100644 --- a/Scintilla.NET/MarkerCollection.cs +++ b/Scintilla.NET/MarkerCollection.cs @@ -25,7 +25,7 @@ public IEnumerator GetEnumerator() IEnumerator IEnumerable.GetEnumerator() { - return this.GetEnumerator(); + return GetEnumerator(); } /// @@ -36,7 +36,7 @@ public int Count { get { - return (NativeMethods.MARKER_MAX + 1); + return NativeMethods.MARKER_MAX + 1; } } @@ -51,7 +51,7 @@ public Marker this[int index] get { index = Helpers.Clamp(index, 0, Count - 1); - return new Marker(scintilla, index); + return new Marker(this.scintilla, index); } } diff --git a/Scintilla.NET/MarkerHandle.cs b/Scintilla.NET/MarkerHandle.cs index aa5759f..9858984 100644 --- a/Scintilla.NET/MarkerHandle.cs +++ b/Scintilla.NET/MarkerHandle.cs @@ -25,7 +25,7 @@ public struct MarkerHandle /// true if is an instance of and equals the value of this instance; otherwise, false. public override bool Equals(object obj) { - return (obj is IntPtr) && Value == ((MarkerHandle)obj).Value; + return obj is IntPtr && this.Value == ((MarkerHandle)obj).Value; } /// @@ -34,7 +34,7 @@ public override bool Equals(object obj) /// A 32-bit signed integer hash code. public override int GetHashCode() { - return Value.GetHashCode(); + return this.Value.GetHashCode(); } /// diff --git a/Scintilla.NET/ModificationEventArgs.cs b/Scintilla.NET/ModificationEventArgs.cs index 1629c66..ef2359e 100644 --- a/Scintilla.NET/ModificationEventArgs.cs +++ b/Scintilla.NET/ModificationEventArgs.cs @@ -27,8 +27,7 @@ public override unsafe string Text { get { - if (CachedText == null) - CachedText = Helpers.GetString(textPtr, byteLength, scintilla.Encoding); + CachedText ??= Helpers.GetString(this.textPtr, this.byteLength, this.scintilla.Encoding); return CachedText; } diff --git a/Scintilla.NET/NativeMemoryStream.cs b/Scintilla.NET/NativeMemoryStream.cs index 2623493..aad0f81 100644 --- a/Scintilla.NET/NativeMemoryStream.cs +++ b/Scintilla.NET/NativeMemoryStream.cs @@ -11,7 +11,6 @@ internal sealed unsafe class NativeMemoryStream : Stream { #region Fields - private IntPtr ptr; private int capacity; private int position; private int length; @@ -22,10 +21,10 @@ internal sealed unsafe class NativeMemoryStream : Stream protected override void Dispose(bool disposing) { - if (FreeOnDispose && ptr != IntPtr.Zero) + if (FreeOnDispose && Pointer != IntPtr.Zero) { - Marshal.FreeHGlobal(ptr); - ptr = IntPtr.Zero; + Marshal.FreeHGlobal(Pointer); + Pointer = IntPtr.Zero; } base.Dispose(disposing); @@ -46,14 +45,14 @@ public override long Seek(long offset, SeekOrigin origin) switch (origin) { case SeekOrigin.Begin: - position = (int)offset; + this.position = (int)offset; break; default: throw new NotImplementedException(); } - return position; + return this.position; } public override void SetLength(long value) @@ -63,25 +62,25 @@ public override void SetLength(long value) public override void Write(byte[] buffer, int offset, int count) { - if ((position + count) > capacity) + if (this.position + count > this.capacity) { // Realloc buffer - var minCapacity = (position + count); - var newCapacity = (capacity * 2); + int minCapacity = this.position + count; + int newCapacity = this.capacity * 2; if (newCapacity < minCapacity) newCapacity = minCapacity; - var newPtr = Marshal.AllocHGlobal(newCapacity); - NativeMethods.MoveMemory(newPtr, ptr, length); - Marshal.FreeHGlobal(ptr); + IntPtr newPtr = Marshal.AllocHGlobal(newCapacity); + NativeMethods.MoveMemory(newPtr, Pointer, this.length); + Marshal.FreeHGlobal(Pointer); - ptr = newPtr; - capacity = newCapacity; + Pointer = newPtr; + this.capacity = newCapacity; } - Marshal.Copy(buffer, offset, (IntPtr)((long)ptr + position), count); - position += count; - length = Math.Max(length, position); + Marshal.Copy(buffer, offset, (IntPtr)((long)Pointer + this.position), count); + this.position += count; + this.length = Math.Max(this.length, this.position); } #endregion Methods @@ -115,23 +114,17 @@ public override long Length { get { - return length; + return this.length; } } - public IntPtr Pointer - { - get - { - return ptr; - } - } + public IntPtr Pointer { get; private set; } public override long Position { get { - return position; + return this.position; } set { @@ -149,7 +142,7 @@ public NativeMemoryStream(int capacity) capacity = 4; this.capacity = capacity; - this.ptr = Marshal.AllocHGlobal(capacity); + Pointer = Marshal.AllocHGlobal(capacity); FreeOnDispose = true; } diff --git a/Scintilla.NET/NativeMethods.cs b/Scintilla.NET/NativeMethods.cs index 028df1a..d2de567 100644 --- a/Scintilla.NET/NativeMethods.cs +++ b/Scintilla.NET/NativeMethods.cs @@ -58,8 +58,8 @@ public static class NativeMethods public const int SCI_CTRL = SCMOD_CTRL; public const int SCI_ALT = SCMOD_ALT; public const int SCI_META = SCMOD_META; - public const int SCI_CSHIFT = (SCI_CTRL | SCI_SHIFT); - public const int SCI_ASHIFT = (SCI_ALT | SCI_SHIFT); + public const int SCI_CSHIFT = SCI_CTRL | SCI_SHIFT; + public const int SCI_ASHIFT = SCI_ALT | SCI_SHIFT; // Caret policy flags public const int CARET_SLOP = 0x01; @@ -79,7 +79,7 @@ public static class NativeMethods public const int EDGE_MULTILINE = 3; // Message-only window - public const int HWND_MESSAGE = (-3); + public const int HWND_MESSAGE = -3; // Indicator styles public const int INDIC_PLAIN = 0; @@ -204,7 +204,7 @@ public static class NativeMethods // Line end type public const int SC_LINE_END_TYPE_DEFAULT = 0; public const int SC_LINE_END_TYPE_UNICODE = 1; - + //Line layers public const int SC_LAYER_BASE = 0; public const int SC_LAYER_UNDER_TEXT = 1; @@ -405,7 +405,7 @@ public static class NativeMethods public const int SCI_MARKERSETFORE = 2041; public const int SCI_MARKERSETBACK = 2042; public const int SCI_MARKERSETFORETRANSLUCENT = 2294; - public const int SCI_MARKERSETBACKTRANSLUCENT = 2295; + public const int SCI_MARKERSETBACKTRANSLUCENT = 2295; public const int SCI_MARKERSETBACKSELECTED = 2292; public const int SCI_MARKERENABLEHIGHLIGHT = 2293; public const int SCI_MARKERADD = 2043; @@ -1221,7 +1221,7 @@ public static class NativeMethods #region Lexer Constants // Map the constant language names - public static readonly Dictionary NameConstantMap = new Dictionary() { + public static readonly Dictionary NameConstantMap = new() { { SCLEX_CONTAINER, "" }, { SCLEX_NULL, "null" }, { SCLEX_PYTHON, "python" }, @@ -1488,7 +1488,7 @@ public static class NativeMethods public const int SCLEX_HOLLYWOOD = 130; public const int SCLEX_RAKU = 131; public const int SCLEX_FSHARP = 132; - public const int SCLEX_JULIA = 133; + public const int SCLEX_JULIA = 133; public const int SCLEX_AUTOMATIC = 1000; // Ada @@ -1531,7 +1531,7 @@ public static class NativeMethods public const int SCE_BAT_HIDE = 4; public const int SCE_BAT_COMMAND = 5; public const int SCE_BAT_IDENTIFIER = 6; - public const int SCE_BAT_OPERATOR = 7; + public const int SCE_BAT_OPERATOR = 7; // CPP public const int SCE_C_DEFAULT = 0; @@ -1563,7 +1563,6 @@ public static class NativeMethods public const int SCE_C_TASKMARKER = 26; public const int SCE_C_ESCAPESEQUENCE = 27; - //CLW public const int SCE_CLW_DEFAULT = 0; public const int SCE_CLW_LABEL = 1; @@ -1650,19 +1649,19 @@ public static class NativeMethods public const int SCE_H_XCCOMMENT = 20; // JavaScript - public const int SCE_HJ_START = 40; - public const int SCE_HJ_DEFAULT = 41; - public const int SCE_HJ_COMMENT = 42; - public const int SCE_HJ_COMMENTLINE = 43; - public const int SCE_HJ_COMMENTDOC = 44; - public const int SCE_HJ_NUMBER = 45; - public const int SCE_HJ_WORD = 46; - public const int SCE_HJ_KEYWORD = 47; + public const int SCE_HJ_START = 40; + public const int SCE_HJ_DEFAULT = 41; + public const int SCE_HJ_COMMENT = 42; + public const int SCE_HJ_COMMENTLINE = 43; + public const int SCE_HJ_COMMENTDOC = 44; + public const int SCE_HJ_NUMBER = 45; + public const int SCE_HJ_WORD = 46; + public const int SCE_HJ_KEYWORD = 47; public const int SCE_HJ_DOUBLESTRING = 48; public const int SCE_HJ_SINGLESTRING = 49; - public const int SCE_HJ_SYMBOLS = 50; - public const int SCE_HJ_STRINGEOL = 51; - public const int SCE_HJ_REGEX = 52; + public const int SCE_HJ_SYMBOLS = 50; + public const int SCE_HJ_STRINGEOL = 51; + public const int SCE_HJ_REGEX = 52; // JSON public const int SCE_JSON_DEFAULT = 0; @@ -1928,7 +1927,7 @@ public static class NativeMethods public const int SCE_ST_ASSIGN = 14; public const int SCE_ST_CHARACTER = 15; public const int SCE_ST_SPEC_SEL = 16; - + // Basic / VB public const int SCE_B_DEFAULT = 0; public const int SCE_B_COMMENT = 1; diff --git a/Scintilla.NET/NeedShownEventArgs.cs b/Scintilla.NET/NeedShownEventArgs.cs index 5d4dae9..ef0a848 100644 --- a/Scintilla.NET/NeedShownEventArgs.cs +++ b/Scintilla.NET/NeedShownEventArgs.cs @@ -21,14 +21,14 @@ public int Length { get { - if (length == null) + if (this.length == null) { - var endBytePosition = (bytePosition + byteLength); - var endPosition = scintilla.Lines.ByteToCharPosition(endBytePosition); - length = (endPosition - Position); + int endBytePosition = this.bytePosition + this.byteLength; + int endPosition = this.scintilla.Lines.ByteToCharPosition(endBytePosition); + this.length = endPosition - Position; } - return (int)length; + return (int)this.length; } } @@ -40,10 +40,9 @@ public int Position { get { - if (position == null) - position = scintilla.Lines.ByteToCharPosition(bytePosition); + this.position ??= this.scintilla.Lines.ByteToCharPosition(this.bytePosition); - return (int)position; + return (int)this.position; } } diff --git a/Scintilla.NET/ProjectionEqualityComparer.cs b/Scintilla.NET/ProjectionEqualityComparer.cs index 5d259ba..e39ae26 100644 --- a/Scintilla.NET/ProjectionEqualityComparer.cs +++ b/Scintilla.NET/ProjectionEqualityComparer.cs @@ -1,10 +1,9 @@ // http://stackoverflow.com/questions/188120/can-i-specify-my-explicit-type-comparator-inline -namespace ScintillaNET; - using System; using System.Collections.Generic; +namespace ScintillaNET; /// /// Non-generic class to produce instances of the generic class, /// optionally using type inference. @@ -42,7 +41,6 @@ public static ProjectionEqualityComparer Create { return new ProjectionEqualityComparer(projection); } - } /// @@ -75,8 +73,8 @@ public static ProjectionEqualityComparer Create(Func internal class ProjectionEqualityComparer : IEqualityComparer { - readonly Func projection; - readonly IEqualityComparer comparer; + private readonly Func projection; + private readonly IEqualityComparer comparer; /// /// Creates a new instance using the specified projection, which must not be null. @@ -96,12 +94,8 @@ public ProjectionEqualityComparer(Func projection) /// which case the default comparer will be used. public ProjectionEqualityComparer(Func projection, IEqualityComparer comparer) { - if (projection == null) - { - throw new ArgumentNullException("projection"); - } this.comparer = comparer ?? EqualityComparer.Default; - this.projection = projection; + this.projection = projection ?? throw new ArgumentNullException("projection"); } /// @@ -115,11 +109,13 @@ public bool Equals(TSource x, TSource y) { return true; } + if (x == null || y == null) { return false; } - return comparer.Equals(projection(x), projection(y)); + + return this.comparer.Equals(this.projection(x), this.projection(y)); } /// @@ -133,6 +129,7 @@ public int GetHashCode(TSource obj) { throw new ArgumentNullException("obj"); } - return comparer.GetHashCode(projection(obj)); + + return this.comparer.GetHashCode(this.projection(obj)); } } \ No newline at end of file diff --git a/Scintilla.NET/SCNotificationEventArgs.cs b/Scintilla.NET/SCNotificationEventArgs.cs index 2e01e5d..84d0a5d 100644 --- a/Scintilla.NET/SCNotificationEventArgs.cs +++ b/Scintilla.NET/SCNotificationEventArgs.cs @@ -9,6 +9,6 @@ internal sealed class SCNotificationEventArgs : EventArgs public SCNotificationEventArgs(NativeMethods.SCNotification scn) { - this.SCNotification = scn; + SCNotification = scn; } } \ No newline at end of file diff --git a/Scintilla.NET/Scintilla.cs b/Scintilla.NET/Scintilla.cs index 1034576..e8abea0 100644 --- a/Scintilla.NET/Scintilla.cs +++ b/Scintilla.NET/Scintilla.cs @@ -8,7 +8,6 @@ using System.IO; using System.Reflection; using System.Runtime.InteropServices; -using System.Runtime.Versioning; using System.Text; using System.Windows.Forms; using System.Windows.Forms.VisualStyles; @@ -23,7 +22,7 @@ public class Scintilla : Control { static Scintilla() { - List searchedPathList = new List(); + List searchedPathList = []; foreach (string path in EnumerateSatelliteLibrarySearchPaths()) { string scintillaDllPath = Path.Combine(path, "Scintilla.dll"); @@ -46,7 +45,9 @@ static Scintilla() } } else + { searchedPathList.Add(path); + } } string searchedPaths = string.Join("\n", searchedPathList); @@ -63,9 +64,9 @@ private static bool InDesignProcess() using var proc = Process.GetCurrentProcess(); string procName = proc.ProcessName; return - procName == "devenv" || procName == "DesignToolsServer" || // WinForms app in VS IDE - procName == "xdesproc" || // WPF app in VS IDE/Blend - procName == "blend"; + procName is "devenv" or "DesignToolsServer" or // WinForms app in VS IDE + "xdesproc" or // WPF app in VS IDE/Blend + "blend"; } /// @@ -114,39 +115,39 @@ public static IEnumerable EnumerateSatelliteLibrarySearchPaths() private static Lexilla lexilla; // Events - private static readonly object scNotificationEventKey = new object(); - private static readonly object insertCheckEventKey = new object(); - private static readonly object beforeInsertEventKey = new object(); - private static readonly object beforeDeleteEventKey = new object(); - private static readonly object insertEventKey = new object(); - private static readonly object deleteEventKey = new object(); - private static readonly object updateUIEventKey = new object(); - private static readonly object modifyAttemptEventKey = new object(); - private static readonly object styleNeededEventKey = new object(); - private static readonly object savePointReachedEventKey = new object(); - private static readonly object savePointLeftEventKey = new object(); - private static readonly object changeAnnotationEventKey = new object(); - private static readonly object marginClickEventKey = new object(); - private static readonly object marginRightClickEventKey = new object(); - private static readonly object charAddedEventKey = new object(); - private static readonly object autoCSelectionEventKey = new object(); - private static readonly object autoCSelectionChangeEventKey = new object(); - private static readonly object autoCCompletedEventKey = new object(); - private static readonly object autoCCancelledEventKey = new object(); - private static readonly object autoCCharDeletedEventKey = new object(); - private static readonly object dwellStartEventKey = new object(); - private static readonly object callTipClickEventKey = new object(); - private static readonly object dwellEndEventKey = new object(); - private static readonly object borderStyleChangedEventKey = new object(); - private static readonly object doubleClickEventKey = new object(); - private static readonly object paintedEventKey = new object(); - private static readonly object needShownEventKey = new object(); - private static readonly object hotspotClickEventKey = new object(); - private static readonly object hotspotDoubleClickEventKey = new object(); - private static readonly object hotspotReleaseClickEventKey = new object(); - private static readonly object indicatorClickEventKey = new object(); - private static readonly object indicatorReleaseEventKey = new object(); - private static readonly object zoomChangedEventKey = new object(); + private static readonly object scNotificationEventKey = new(); + private static readonly object insertCheckEventKey = new(); + private static readonly object beforeInsertEventKey = new(); + private static readonly object beforeDeleteEventKey = new(); + private static readonly object insertEventKey = new(); + private static readonly object deleteEventKey = new(); + private static readonly object updateUIEventKey = new(); + private static readonly object modifyAttemptEventKey = new(); + private static readonly object styleNeededEventKey = new(); + private static readonly object savePointReachedEventKey = new(); + private static readonly object savePointLeftEventKey = new(); + private static readonly object changeAnnotationEventKey = new(); + private static readonly object marginClickEventKey = new(); + private static readonly object marginRightClickEventKey = new(); + private static readonly object charAddedEventKey = new(); + private static readonly object autoCSelectionEventKey = new(); + private static readonly object autoCSelectionChangeEventKey = new(); + private static readonly object autoCCompletedEventKey = new(); + private static readonly object autoCCancelledEventKey = new(); + private static readonly object autoCCharDeletedEventKey = new(); + private static readonly object dwellStartEventKey = new(); + private static readonly object callTipClickEventKey = new(); + private static readonly object dwellEndEventKey = new(); + private static readonly object borderStyleChangedEventKey = new(); + private static readonly object doubleClickEventKey = new(); + private static readonly object paintedEventKey = new(); + private static readonly object needShownEventKey = new(); + private static readonly object hotspotClickEventKey = new(); + private static readonly object hotspotDoubleClickEventKey = new(); + private static readonly object hotspotReleaseClickEventKey = new(); + private static readonly object indicatorClickEventKey = new(); + private static readonly object indicatorReleaseEventKey = new(); + private static readonly object zoomChangedEventKey = new(); // The goods private IntPtr sciPtr; @@ -203,7 +204,7 @@ private bool SetLexerByName(string lexerName) return true; } - var ptr = Lexilla.CreateLexer(lexerName); + IntPtr ptr = Lexilla.CreateLexer(lexerName); if (ptr == IntPtr.Zero) { @@ -221,7 +222,7 @@ private bool SetLexerByName(string lexerName) /// The document reference count to increase. public void AddRefDocument(Document document) { - var ptr = document.Value; + IntPtr ptr = document.Value; DirectMessage(NativeMethods.SCI_ADDREFDOCUMENT, IntPtr.Zero, ptr); } @@ -233,7 +234,7 @@ public void AddRefDocument(Document document) /// A main selection must first have been set by a call to . public void AddSelection(int caret, int anchor) { - var textLength = TextLength; + int textLength = TextLength; caret = Helpers.Clamp(caret, 0, textLength); anchor = Helpers.Clamp(anchor, 0, textLength); @@ -250,7 +251,7 @@ public void AddSelection(int caret, int anchor) /// The caret position is set to the end of the inserted text, but it is not scrolled into view. public unsafe void AddText(string text) { - var bytes = Helpers.GetBytes(text ?? string.Empty, Encoding, zeroTerminated: false); + byte[] bytes = Helpers.GetBytes(text ?? string.Empty, Encoding, zeroTerminated: false); fixed (byte* bp = bytes) DirectMessage(NativeMethods.SCI_ADDTEXT, new IntPtr(bytes.Length), new IntPtr(bp)); } @@ -263,7 +264,7 @@ public unsafe void AddText(string text) /// Returns the first substyle number allocated. public int AllocateSubstyles(int styleBase, int numberStyles) { - return this.DirectMessage(NativeMethods.SCI_ALLOCATESUBSTYLES, new IntPtr(styleBase), new IntPtr(numberStyles)).ToInt32(); + return DirectMessage(NativeMethods.SCI_ALLOCATESUBSTYLES, new IntPtr(styleBase), new IntPtr(numberStyles)).ToInt32(); } /// @@ -281,7 +282,7 @@ public void AnnotationClearAll() /// The current selection is not changed and the new text is not scrolled into view. public unsafe void AppendText(string text) { - var bytes = Helpers.GetBytes(text ?? string.Empty, Encoding, zeroTerminated: false); + byte[] bytes = Helpers.GetBytes(text ?? string.Empty, Encoding, zeroTerminated: false); fixed (byte* bp = bytes) DirectMessage(NativeMethods.SCI_APPENDTEXT, new IntPtr(bytes.Length), new IntPtr(bp)); } @@ -293,7 +294,7 @@ public unsafe void AppendText(string text) /// The command to assign. public void AssignCmdKey(Keys keyDefinition, Command sciCommand) { - var keys = Helpers.TranslateKeys(keyDefinition); + int keys = Helpers.TranslateKeys(keyDefinition); DirectMessage(NativeMethods.SCI_ASSIGNCMDKEY, new IntPtr(keys), new IntPtr((int)sciCommand)); } @@ -331,7 +332,7 @@ public void AutoCComplete() /// public unsafe void AutoCSelect(string select) { - var bytes = Helpers.GetBytes(select, Encoding, zeroTerminated: true); + byte[] bytes = Helpers.GetBytes(select, Encoding, zeroTerminated: true); fixed (byte* bp = bytes) DirectMessage(NativeMethods.SCI_AUTOCSELECT, IntPtr.Zero, new IntPtr(bp)); } @@ -347,26 +348,25 @@ public unsafe void AutoCSetFillUps(string chars) // That means we need to keep a copy of the string around for the life of the control AND put it // in a place where it won't get moved by the GC. - if (chars == null) - chars = string.Empty; + chars ??= string.Empty; - if (fillUpChars != IntPtr.Zero) + if (this.fillUpChars != IntPtr.Zero) { - Marshal.FreeHGlobal(fillUpChars); - fillUpChars = IntPtr.Zero; + Marshal.FreeHGlobal(this.fillUpChars); + this.fillUpChars = IntPtr.Zero; } - var count = (Encoding.GetByteCount(chars) + 1); + int count = Encoding.GetByteCount(chars) + 1; IntPtr newFillUpChars = Marshal.AllocHGlobal(count); fixed (char* ch = chars) Encoding.GetBytes(ch, chars.Length, (byte*)newFillUpChars, count); ((byte*)newFillUpChars)[count - 1] = 0; // Null terminate - fillUpChars = newFillUpChars; + this.fillUpChars = newFillUpChars; // var str = new String((sbyte*)fillUpChars, 0, count, Encoding); - DirectMessage(NativeMethods.SCI_AUTOCSETFILLUPS, IntPtr.Zero, fillUpChars); + DirectMessage(NativeMethods.SCI_AUTOCSETFILLUPS, IntPtr.Zero, this.fillUpChars); } /// @@ -383,15 +383,15 @@ public unsafe void AutoCShow(int lenEntered, string list) if (lenEntered > 0) { // Convert to bytes by counting back the specified number of characters - var endPos = DirectMessage(NativeMethods.SCI_GETCURRENTPOS).ToInt32(); - var startPos = endPos; + int endPos = DirectMessage(NativeMethods.SCI_GETCURRENTPOS).ToInt32(); + int startPos = endPos; for (int i = 0; i < lenEntered; i++) startPos = DirectMessage(NativeMethods.SCI_POSITIONRELATIVE, new IntPtr(startPos), new IntPtr(-1)).ToInt32(); - lenEntered = (endPos - startPos); + lenEntered = endPos - startPos; } - var bytes = Helpers.GetBytes(list, Encoding, zeroTerminated: true); + byte[] bytes = Helpers.GetBytes(list, Encoding, zeroTerminated: true); fixed (byte* bp = bytes) DirectMessage(NativeMethods.SCI_AUTOCSHOW, new IntPtr(lenEntered), new IntPtr(bp)); } @@ -403,7 +403,7 @@ public unsafe void AutoCShow(int lenEntered, string list) /// Characters specified should be limited to printable ASCII characters. public unsafe void AutoCStops(string chars) { - var bytes = Helpers.GetBytes(chars ?? string.Empty, Encoding.ASCII, zeroTerminated: true); + byte[] bytes = Helpers.GetBytes(chars ?? string.Empty, Encoding.ASCII, zeroTerminated: true); fixed (byte* bp = bytes) DirectMessage(NativeMethods.SCI_AUTOCSTOPS, IntPtr.Zero, new IntPtr(bp)); } @@ -440,7 +440,7 @@ public void BraceBadLight(int position) /// public void BraceHighlight(int position1, int position2) { - var textLength = TextLength; + int textLength = TextLength; position1 = Helpers.Clamp(position1, -1, textLength); if (position1 > 0) @@ -465,7 +465,7 @@ public int BraceMatch(int position) position = Helpers.Clamp(position, 0, TextLength); position = Lines.CharToBytePosition(position); - var match = DirectMessage(NativeMethods.SCI_BRACEMATCH, new IntPtr(position), IntPtr.Zero).ToInt32(); + int match = DirectMessage(NativeMethods.SCI_BRACEMATCH, new IntPtr(position), IntPtr.Zero).ToInt32(); if (match > 0) match = Lines.ByteToCharPosition(match); @@ -486,7 +486,7 @@ public void CallTipCancel() /// The new highlight text Color. The default is dark blue. public void CallTipSetForeHlt(Color color) { - var colour = HelperMethods.ToWin32Color(color); + int colour = HelperMethods.ToWin32Color(color); DirectMessage(NativeMethods.SCI_CALLTIPSETFOREHLT, new IntPtr(colour)); } @@ -498,10 +498,10 @@ public void CallTipSetForeHlt(Color color) public unsafe void CallTipSetHlt(int hlStart, int hlEnd) { // To do the char->byte translation we need to use a cached copy of the last call tip - hlStart = Helpers.Clamp(hlStart, 0, lastCallTip.Length); - hlEnd = Helpers.Clamp(hlEnd, 0, lastCallTip.Length); + hlStart = Helpers.Clamp(hlStart, 0, this.lastCallTip.Length); + hlEnd = Helpers.Clamp(hlEnd, 0, this.lastCallTip.Length); - fixed (char* cp = lastCallTip) + fixed (char* cp = this.lastCallTip) { hlEnd = Encoding.GetByteCount(cp + hlStart, hlEnd - hlStart); // The bytes between start and end hlStart = Encoding.GetByteCount(cp, hlStart); // The bytes between 0 and start @@ -517,7 +517,7 @@ public unsafe void CallTipSetHlt(int hlStart, int hlEnd) /// true to display above text; otherwise, false. The default is false. public void CallTipSetPosition(bool above) { - var val = (above ? new IntPtr(1) : IntPtr.Zero); + IntPtr val = above ? new IntPtr(1) : IntPtr.Zero; DirectMessage(NativeMethods.SCI_CALLTIPSETPOSITION, val); } @@ -536,9 +536,9 @@ public unsafe void CallTipShow(int posStart, string definition) if (definition == null) return; - lastCallTip = definition; + this.lastCallTip = definition; posStart = Lines.CharToBytePosition(posStart); - var bytes = Helpers.GetBytes(definition, Encoding, zeroTerminated: true); + byte[] bytes = Helpers.GetBytes(definition, Encoding, zeroTerminated: true); fixed (byte* bp = bytes) DirectMessage(NativeMethods.SCI_CALLTIPSHOW, new IntPtr(posStart), new IntPtr(bp)); } @@ -565,7 +565,7 @@ public void CallTipTabSize(int tabSize) /// The zero-based document position at which the lexer state change ends. public void ChangeLexerState(int startPos, int endPos) { - var textLength = TextLength; + int textLength = TextLength; startPos = Helpers.Clamp(startPos, 0, textLength); endPos = Helpers.Clamp(endPos, 0, textLength); @@ -583,7 +583,7 @@ public void ChangeLexerState(int startPos, int endPos) /// The zero-based document position of the nearest character to the point specified. public int CharPositionFromPoint(int x, int y) { - var pos = DirectMessage(NativeMethods.SCI_CHARPOSITIONFROMPOINT, new IntPtr(x), new IntPtr(y)).ToInt32(); + int pos = DirectMessage(NativeMethods.SCI_CHARPOSITIONFROMPOINT, new IntPtr(x), new IntPtr(y)).ToInt32(); pos = Lines.ByteToCharPosition(pos); return pos; @@ -598,7 +598,7 @@ public int CharPositionFromPoint(int x, int y) /// The zero-based document position of the nearest character to the point specified when near a character; otherwise, -1. public int CharPositionFromPointClose(int x, int y) { - var pos = DirectMessage(NativeMethods.SCI_CHARPOSITIONFROMPOINTCLOSE, new IntPtr(x), new IntPtr(y)).ToInt32(); + int pos = DirectMessage(NativeMethods.SCI_CHARPOSITIONFROMPOINTCLOSE, new IntPtr(x), new IntPtr(y)).ToInt32(); if (pos >= 0) pos = Lines.ByteToCharPosition(pos); @@ -641,7 +641,7 @@ public void ClearAll() /// This is equivalent to binding the keys to . public void ClearCmdKey(Keys keyDefinition) { - var keys = Helpers.TranslateKeys(keyDefinition); + int keys = Helpers.TranslateKeys(keyDefinition); DirectMessage(NativeMethods.SCI_CLEARCMDKEY, new IntPtr(keys)); } @@ -685,7 +685,7 @@ public void ClearSelections() /// This will also cause fold levels in the range specified to be reset. public void Colorize(int startPos, int endPos) { - var textLength = TextLength; + int textLength = TextLength; startPos = Helpers.Clamp(startPos, 0, textLength); endPos = Helpers.Clamp(endPos, 0, textLength); @@ -701,7 +701,7 @@ public void Colorize(int startPos, int endPos) /// One of the enumeration values. public void ConvertEols(Eol eolMode) { - var eol = (int)eolMode; + int eol = (int)eolMode; DirectMessage(NativeMethods.SCI_CONVERTEOLS, new IntPtr(eol)); } @@ -756,7 +756,7 @@ public void CopyAllowLine(CopyFormat format) /// The zero-based character position (exclusive) in the document to stop copying. public void CopyRange(int start, int end) { - var textLength = TextLength; + int textLength = TextLength; start = Helpers.Clamp(start, 0, textLength); end = Helpers.Clamp(end, 0, textLength); @@ -775,7 +775,7 @@ public void CopyRange(int start, int end) /// One of the enumeration values. public void CopyRange(int start, int end, CopyFormat format) { - var textLength = TextLength; + int textLength = TextLength; start = Helpers.Clamp(start, 0, textLength); end = Helpers.Clamp(end, 0, textLength); if (start == end) @@ -795,7 +795,7 @@ public void CopyRange(int start, int end, CopyFormat format) /// You are responsible for ensuring the reference count eventually reaches 0 or memory leaks will occur. public Document CreateDocument() { - var ptr = DirectMessage(NativeMethods.SCI_CREATEDOCUMENT); + IntPtr ptr = DirectMessage(NativeMethods.SCI_CREATEDOCUMENT); return new Document { Value = ptr }; } @@ -807,7 +807,7 @@ public Document CreateDocument() public ILoader CreateLoader(int length) { length = Helpers.ClampMin(length, 0); - var ptr = DirectMessage(NativeMethods.SCI_CREATELOADER, new IntPtr(length)); + IntPtr ptr = DirectMessage(NativeMethods.SCI_CREATELOADER, new IntPtr(length)); if (ptr == IntPtr.Zero) return null; @@ -829,13 +829,13 @@ public void Cut() /// The number of characters to delete. public void DeleteRange(int position, int length) { - var textLength = TextLength; + int textLength = TextLength; position = Helpers.Clamp(position, 0, textLength); length = Helpers.Clamp(length, 0, textLength - position); // Convert to byte position/length - var byteStartPos = Lines.CharToBytePosition(position); - var byteEndPos = Lines.CharToBytePosition(position + length); + int byteStartPos = Lines.CharToBytePosition(position); + int byteEndPos = Lines.CharToBytePosition(position + length); DirectMessage(NativeMethods.SCI_DELETERANGE, new IntPtr(byteStartPos), new IntPtr(byteEndPos - byteStartPos)); } @@ -846,13 +846,13 @@ public void DeleteRange(int position, int length) /// A String describing each keyword set separated by line breaks for the current lexer. public unsafe string DescribeKeywordSets() { - var length = DirectMessage(NativeMethods.SCI_DESCRIBEKEYWORDSETS).ToInt32(); - var bytes = new byte[length + 1]; + int length = DirectMessage(NativeMethods.SCI_DESCRIBEKEYWORDSETS).ToInt32(); + byte[] bytes = new byte[length + 1]; fixed (byte* bp = bytes) DirectMessage(NativeMethods.SCI_DESCRIBEKEYWORDSETS, IntPtr.Zero, new IntPtr(bp)); - var str = Encoding.ASCII.GetString(bytes, 0, length); + string str = Encoding.ASCII.GetString(bytes, 0, length); return str; } @@ -864,17 +864,17 @@ public unsafe string DescribeKeywordSets() /// A list of supported property names for the current Lexer can be obtained by calling . public unsafe string DescribeProperty(string name) { - if (String.IsNullOrEmpty(name)) - return String.Empty; + if (string.IsNullOrEmpty(name)) + return string.Empty; - var nameBytes = Helpers.GetBytes(name, Encoding.ASCII, zeroTerminated: true); + byte[] nameBytes = Helpers.GetBytes(name, Encoding.ASCII, zeroTerminated: true); fixed (byte* nb = nameBytes) { - var length = DirectMessage(NativeMethods.SCI_DESCRIBEPROPERTY, new IntPtr(nb), IntPtr.Zero).ToInt32(); + int length = DirectMessage(NativeMethods.SCI_DESCRIBEPROPERTY, new IntPtr(nb), IntPtr.Zero).ToInt32(); if (length == 0) return string.Empty; - var descriptionBytes = new byte[length + 1]; + byte[] descriptionBytes = new byte[length + 1]; fixed (byte* db = descriptionBytes) { DirectMessage(NativeMethods.SCI_DESCRIBEPROPERTY, new IntPtr(nb), new IntPtr(db)); @@ -906,14 +906,14 @@ internal IntPtr DirectMessage(int msg, IntPtr wParam) public virtual IntPtr DirectMessage(int msg, IntPtr wParam, IntPtr lParam) { // If the control handle, ptr, direct function, etc... hasn't been created yet, it will be now. - var result = DirectMessage(SciPointer, msg, wParam, lParam); + IntPtr result = DirectMessage(SciPointer, msg, wParam, lParam); return result; } private static IntPtr DirectMessage(IntPtr sciPtr, int msg, IntPtr wParam, IntPtr lParam) { // Like Win32 SendMessage but directly to Scintilla - var result = directFunction(sciPtr, msg, wParam, lParam); + IntPtr result = directFunction(sciPtr, msg, wParam, lParam); return result; } @@ -926,17 +926,17 @@ protected override void Dispose(bool disposing) if (disposing) { // WM_DESTROY workaround - if (reparent) + if (this.reparent) { - reparent = false; + this.reparent = false; if (IsHandleCreated) DestroyHandle(); } - if (fillUpChars != IntPtr.Zero) + if (this.fillUpChars != IntPtr.Zero) { - Marshal.FreeHGlobal(fillUpChars); - fillUpChars = IntPtr.Zero; + Marshal.FreeHGlobal(this.fillUpChars); + this.fillUpChars = IntPtr.Zero; } } @@ -990,7 +990,7 @@ public void EndUndoAction() /// The command to perform. public void ExecuteCmd(Command sciCommand) { - var cmd = (int)sciCommand; + int cmd = (int)sciCommand; DirectMessage(cmd); } @@ -1033,8 +1033,8 @@ public unsafe int GetCharAt(int position) position = Helpers.Clamp(position, 0, TextLength); position = Lines.CharToBytePosition(position); - var nextPosition = DirectMessage(NativeMethods.SCI_POSITIONRELATIVE, new IntPtr(position), new IntPtr(1)).ToInt32(); - var length = (nextPosition - position); + int nextPosition = DirectMessage(NativeMethods.SCI_POSITIONRELATIVE, new IntPtr(position), new IntPtr(1)).ToInt32(); + int length = nextPosition - position; if (length <= 1) { // Position is at single-byte character @@ -1042,7 +1042,7 @@ public unsafe int GetCharAt(int position) } // Position is at multibyte character - var bytes = new byte[length + 1]; + byte[] bytes = new byte[length + 1]; fixed (byte* bp = bytes) { NativeMethods.Sci_TextRange* range = stackalloc NativeMethods.Sci_TextRange[1]; @@ -1051,7 +1051,7 @@ public unsafe int GetCharAt(int position) range->lpstrText = new IntPtr(bp); DirectMessage(NativeMethods.SCI_GETTEXTRANGE, IntPtr.Zero, new IntPtr(range)); - var str = Helpers.GetString(new IntPtr(bp), length, Encoding); + string str = Helpers.GetString(new IntPtr(bp), length, Encoding); return str[0]; } } @@ -1074,7 +1074,7 @@ public int GetColumn(int position) /// The zero-based document position of the last styled character. public int GetEndStyled() { - var pos = DirectMessage(NativeMethods.SCI_GETENDSTYLED).ToInt32(); + int pos = DirectMessage(NativeMethods.SCI_GETENDSTYLED).ToInt32(); return Lines.ByteToCharPosition(pos); } @@ -1112,17 +1112,17 @@ public int GetPrimaryStyleFromStyle(int style) /// public unsafe string GetProperty(string name) { - if (String.IsNullOrEmpty(name)) - return String.Empty; + if (string.IsNullOrEmpty(name)) + return string.Empty; - var nameBytes = Helpers.GetBytes(name, Encoding.ASCII, zeroTerminated: true); + byte[] nameBytes = Helpers.GetBytes(name, Encoding.ASCII, zeroTerminated: true); fixed (byte* nb = nameBytes) { - var length = DirectMessage(NativeMethods.SCI_GETPROPERTY, new IntPtr(nb)).ToInt32(); + int length = DirectMessage(NativeMethods.SCI_GETPROPERTY, new IntPtr(nb)).ToInt32(); if (length == 0) - return String.Empty; + return string.Empty; - var valueBytes = new byte[length + 1]; + byte[] valueBytes = new byte[length + 1]; fixed (byte* vb = valueBytes) { DirectMessage(NativeMethods.SCI_GETPROPERTY, new IntPtr(nb), new IntPtr(vb)); @@ -1142,17 +1142,17 @@ public unsafe string GetProperty(string name) /// public unsafe string GetPropertyExpanded(string name) { - if (String.IsNullOrEmpty(name)) - return String.Empty; + if (string.IsNullOrEmpty(name)) + return string.Empty; - var nameBytes = Helpers.GetBytes(name, Encoding.ASCII, zeroTerminated: true); + byte[] nameBytes = Helpers.GetBytes(name, Encoding.ASCII, zeroTerminated: true); fixed (byte* nb = nameBytes) { - var length = DirectMessage(NativeMethods.SCI_GETPROPERTYEXPANDED, new IntPtr(nb)).ToInt32(); + int length = DirectMessage(NativeMethods.SCI_GETPROPERTYEXPANDED, new IntPtr(nb)).ToInt32(); if (length == 0) - return String.Empty; + return string.Empty; - var valueBytes = new byte[length + 1]; + byte[] valueBytes = new byte[length + 1]; fixed (byte* vb = valueBytes) { DirectMessage(NativeMethods.SCI_GETPROPERTYEXPANDED, new IntPtr(nb), new IntPtr(vb)); @@ -1173,10 +1173,10 @@ public unsafe string GetPropertyExpanded(string name) /// public unsafe int GetPropertyInt(string name, int defaultValue) { - if (String.IsNullOrEmpty(name)) + if (string.IsNullOrEmpty(name)) return defaultValue; - var bytes = Helpers.GetBytes(name, Encoding.ASCII, zeroTerminated: true); + byte[] bytes = Helpers.GetBytes(name, Encoding.ASCII, zeroTerminated: true); fixed (byte* bp = bytes) return DirectMessage(NativeMethods.SCI_GETPROPERTYINT, new IntPtr(bp), new IntPtr(defaultValue)).ToInt32(); } @@ -1233,11 +1233,11 @@ public int GetSubstylesStart(int styleBase) public unsafe string GetTag(int tagNumber) { tagNumber = Helpers.Clamp(tagNumber, 1, 9); - var length = DirectMessage(NativeMethods.SCI_GETTAG, new IntPtr(tagNumber), IntPtr.Zero).ToInt32(); + int length = DirectMessage(NativeMethods.SCI_GETTAG, new IntPtr(tagNumber), IntPtr.Zero).ToInt32(); if (length <= 0) return string.Empty; - var bytes = new byte[length + 1]; + byte[] bytes = new byte[length + 1]; fixed (byte* bp = bytes) { DirectMessage(NativeMethods.SCI_GETTAG, new IntPtr(tagNumber), new IntPtr(bp)); @@ -1253,19 +1253,19 @@ public unsafe string GetTag(int tagNumber) /// A string representing the text range. public unsafe string GetWideTextRange(int position, int length) { - var textLength = TextLength; + int textLength = TextLength; position = Helpers.Clamp(position, 0, textLength); length = Helpers.Clamp(length, 0, textLength - position); // Convert to byte position/length - var byteStartPos = Lines.CharToWideBytePosition(position); - var byteEndPos = Lines.CharToWideBytePosition(position + length); + int byteStartPos = Lines.CharToWideBytePosition(position); + int byteEndPos = Lines.CharToWideBytePosition(position + length); - var ptr = DirectMessage(NativeMethods.SCI_GETRANGEPOINTER, new IntPtr(byteStartPos), new IntPtr(byteEndPos - byteStartPos)); + IntPtr ptr = DirectMessage(NativeMethods.SCI_GETRANGEPOINTER, new IntPtr(byteStartPos), new IntPtr(byteEndPos - byteStartPos)); if (ptr == IntPtr.Zero) return string.Empty; - return Helpers.GetString(ptr, (byteEndPos - byteStartPos), Encoding); + return Helpers.GetString(ptr, byteEndPos - byteStartPos, Encoding); } /// @@ -1276,19 +1276,19 @@ public unsafe string GetWideTextRange(int position, int length) /// A string representing the text range. public unsafe string GetTextRange(int position, int length) { - var textLength = TextLength; + int textLength = TextLength; position = Helpers.Clamp(position, 0, textLength); length = Helpers.Clamp(length, 0, textLength - position); // Convert to byte position/length - var byteStartPos = Lines.CharToBytePosition(position); - var byteEndPos = Lines.CharToBytePosition(position + length); + int byteStartPos = Lines.CharToBytePosition(position); + int byteEndPos = Lines.CharToBytePosition(position + length); - var ptr = DirectMessage(NativeMethods.SCI_GETRANGEPOINTER, new IntPtr(byteStartPos), new IntPtr(byteEndPos - byteStartPos)); + IntPtr ptr = DirectMessage(NativeMethods.SCI_GETRANGEPOINTER, new IntPtr(byteStartPos), new IntPtr(byteEndPos - byteStartPos)); if (ptr == IntPtr.Zero) return string.Empty; - return Helpers.GetString(ptr, (byteEndPos - byteStartPos), Encoding); + return Helpers.GetString(ptr, byteEndPos - byteStartPos, Encoding); } /// @@ -1299,12 +1299,12 @@ public unsafe string GetTextRange(int position, int length) /// A string representing the text range formatted as HTML. public string GetTextRangeAsHtml(int position, int length) { - var textLength = TextLength; + int textLength = TextLength; position = Helpers.Clamp(position, 0, textLength); length = Helpers.Clamp(length, 0, textLength - position); - var startBytePos = Lines.CharToBytePosition(position); - var endBytePos = Lines.CharToBytePosition(position + length); + int startBytePos = Lines.CharToBytePosition(position); + int endBytePos = Lines.CharToBytePosition(position + length); return Helpers.GetHtml(this, startBytePos, endBytePos); } @@ -1369,7 +1369,7 @@ public uint IndicatorAllOnFor(int position) position = Helpers.Clamp(position, 0, TextLength); position = Lines.CharToBytePosition(position); - var bitmap = DirectMessage(NativeMethods.SCI_INDICATORALLONFOR, new IntPtr(position)).ToInt32(); + int bitmap = DirectMessage(NativeMethods.SCI_INDICATORALLONFOR, new IntPtr(position)).ToInt32(); return unchecked((uint)bitmap); } @@ -1380,12 +1380,12 @@ public uint IndicatorAllOnFor(int position) /// The number of characters to clear. public void IndicatorClearRange(int position, int length) { - var textLength = TextLength; + int textLength = TextLength; position = Helpers.Clamp(position, 0, textLength); length = Helpers.Clamp(length, 0, textLength - position); - var startPos = Lines.CharToBytePosition(position); - var endPos = Lines.CharToBytePosition(position + length); + int startPos = Lines.CharToBytePosition(position); + int endPos = Lines.CharToBytePosition(position + length); DirectMessage(NativeMethods.SCI_INDICATORCLEARRANGE, new IntPtr(startPos), new IntPtr(endPos - startPos)); } @@ -1397,12 +1397,12 @@ public void IndicatorClearRange(int position, int length) /// The number of characters to fill. public void IndicatorFillRange(int position, int length) { - var textLength = TextLength; + int textLength = TextLength; position = Helpers.Clamp(position, 0, textLength); length = Helpers.Clamp(length, 0, textLength - position); - var startPos = Lines.CharToBytePosition(position); - var endPos = Lines.CharToBytePosition(position + length); + int startPos = Lines.CharToBytePosition(position); + int endPos = Lines.CharToBytePosition(position + length); DirectMessage(NativeMethods.SCI_INDICATORFILLRANGE, new IntPtr(startPos), new IntPtr(endPos - startPos)); } @@ -1441,7 +1441,7 @@ private void InitControlProps() WordChars = "abcdefghijklmnopqrstuvwxyz_ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; // Hide all default margins - foreach (var margin in Margins) + foreach (Margin margin in Margins) { margin.Width = 0; } @@ -1464,7 +1464,7 @@ public unsafe void InsertText(int position, string text) if (position != -1) { - var textLength = TextLength; + int textLength = TextLength; if (position > textLength) throw new ArgumentOutOfRangeException("position", "Position cannot exceed document length."); @@ -1491,14 +1491,14 @@ public unsafe void InsertText(int position, string text) /// public bool IsRangeWord(int start, int end) { - var textLength = TextLength; + int textLength = TextLength; start = Helpers.Clamp(start, 0, textLength); end = Helpers.Clamp(end, 0, textLength); start = Lines.CharToBytePosition(start); end = Lines.CharToBytePosition(end); - return (DirectMessage(NativeMethods.SCI_ISRANGEWORD, new IntPtr(start), new IntPtr(end)) != IntPtr.Zero); + return DirectMessage(NativeMethods.SCI_ISRANGEWORD, new IntPtr(start), new IntPtr(end)) != IntPtr.Zero; } /// @@ -1532,10 +1532,10 @@ public void LineScroll(int lines, int columns) /// The path to the external lexer DLL. public unsafe void LoadLexerLibrary(string path) { - if (String.IsNullOrEmpty(path)) + if (string.IsNullOrEmpty(path)) return; - var bytes = Helpers.GetBytes(path, Encoding.Default, zeroTerminated: true); + byte[] bytes = Helpers.GetBytes(path, Encoding.Default, zeroTerminated: true); fixed (byte* bp = bytes) DirectMessage(NativeMethods.SCI_LOADLEXERLIBRARY, IntPtr.Zero, new IntPtr(bp)); } @@ -1565,7 +1565,7 @@ public void MarkerDeleteHandle(MarkerHandle markerHandle) /// true to highlight the current folding block; otherwise, false. public void MarkerEnableHighlight(bool enabled) { - var val = (enabled ? new IntPtr(1) : IntPtr.Zero); + IntPtr val = enabled ? new IntPtr(1) : IntPtr.Zero; DirectMessage(NativeMethods.SCI_MARKERENABLEHIGHLIGHT, val); } @@ -1589,7 +1589,7 @@ public int MarkerLineFromHandle(MarkerHandle markerHandle) public void MultiEdgeAddLine(int column, Color edgeColor) { column = Helpers.ClampMin(column, 0); - var colour = HelperMethods.ToWin32Color(edgeColor); + int colour = HelperMethods.ToWin32Color(edgeColor); DirectMessage(NativeMethods.SCI_MULTIEDGEADDLINE, new IntPtr(column), new IntPtr(colour)); } @@ -1637,8 +1637,7 @@ public void MultipleSelectAddNext() /// An EventArgs that contains the event data. protected virtual void OnAutoCCancelled(EventArgs e) { - var handler = Events[autoCCancelledEventKey] as EventHandler; - if (handler != null) + if (Events[autoCCancelledEventKey] is EventHandler handler) handler(this, e); } @@ -1648,8 +1647,7 @@ protected virtual void OnAutoCCancelled(EventArgs e) /// An EventArgs that contains the event data. protected virtual void OnAutoCCharDeleted(EventArgs e) { - var handler = Events[autoCCharDeletedEventKey] as EventHandler; - if (handler != null) + if (Events[autoCCharDeletedEventKey] is EventHandler handler) handler(this, e); } @@ -1659,8 +1657,7 @@ protected virtual void OnAutoCCharDeleted(EventArgs e) /// An that contains the event data. protected virtual void OnAutoCCompleted(AutoCSelectionEventArgs e) { - var handler = Events[autoCCompletedEventKey] as EventHandler; - if (handler != null) + if (Events[autoCCompletedEventKey] is EventHandler handler) handler(this, e); } @@ -1670,8 +1667,7 @@ protected virtual void OnAutoCCompleted(AutoCSelectionEventArgs e) /// An that contains the event data. protected virtual void OnAutoCSelection(AutoCSelectionEventArgs e) { - var handler = Events[autoCSelectionEventKey] as EventHandler; - if (handler != null) + if (Events[autoCSelectionEventKey] is EventHandler handler) handler(this, e); } @@ -1681,8 +1677,7 @@ protected virtual void OnAutoCSelection(AutoCSelectionEventArgs e) /// An that contains the event data. protected virtual void OnAutoCSelectionChange(AutoCSelectionChangeEventArgs e) { - var handler = Events[autoCSelectionChangeEventKey] as EventHandler; - if (handler != null) + if (Events[autoCSelectionChangeEventKey] is EventHandler handler) handler(this, e); } @@ -1692,8 +1687,7 @@ protected virtual void OnAutoCSelectionChange(AutoCSelectionChangeEventArgs e) /// A that contains the event data. protected virtual void OnBeforeDelete(BeforeModificationEventArgs e) { - var handler = Events[beforeDeleteEventKey] as EventHandler; - if (handler != null) + if (Events[beforeDeleteEventKey] is EventHandler handler) handler(this, e); } @@ -1703,8 +1697,7 @@ protected virtual void OnBeforeDelete(BeforeModificationEventArgs e) /// A that contains the event data. protected virtual void OnBeforeInsert(BeforeModificationEventArgs e) { - var handler = Events[beforeInsertEventKey] as EventHandler; - if (handler != null) + if (Events[beforeInsertEventKey] is EventHandler handler) handler(this, e); } @@ -1714,8 +1707,7 @@ protected virtual void OnBeforeInsert(BeforeModificationEventArgs e) /// An EventArgs that contains the event data. protected virtual void OnBorderStyleChanged(EventArgs e) { - var handler = Events[borderStyleChangedEventKey] as EventHandler; - if (handler != null) + if (Events[borderStyleChangedEventKey] is EventHandler handler) handler(this, e); } @@ -1725,8 +1717,7 @@ protected virtual void OnBorderStyleChanged(EventArgs e) /// A that contains the event data. protected virtual void OnChangeAnnotation(ChangeAnnotationEventArgs e) { - var handler = Events[changeAnnotationEventKey] as EventHandler; - if (handler != null) + if (Events[changeAnnotationEventKey] is EventHandler handler) handler(this, e); } @@ -1736,8 +1727,7 @@ protected virtual void OnChangeAnnotation(ChangeAnnotationEventArgs e) /// A that contains the event data. protected virtual void OnCharAdded(CharAddedEventArgs e) { - var handler = Events[charAddedEventKey] as EventHandler; - if (handler != null) + if (Events[charAddedEventKey] is EventHandler handler) handler(this, e); } @@ -1747,8 +1737,7 @@ protected virtual void OnCharAdded(CharAddedEventArgs e) /// A that contains the event data. protected virtual void OnDelete(ModificationEventArgs e) { - var handler = Events[deleteEventKey] as EventHandler; - if (handler != null) + if (Events[deleteEventKey] is EventHandler handler) handler(this, e); } @@ -1758,8 +1747,7 @@ protected virtual void OnDelete(ModificationEventArgs e) /// A that contains the event data. protected virtual void OnDoubleClick(DoubleClickEventArgs e) { - var handler = Events[doubleClickEventKey] as EventHandler; - if (handler != null) + if (Events[doubleClickEventKey] is EventHandler handler) handler(this, e); } @@ -1769,8 +1757,7 @@ protected virtual void OnDoubleClick(DoubleClickEventArgs e) /// A that contains the event data. protected virtual void OnDwellEnd(DwellEventArgs e) { - var handler = Events[dwellEndEventKey] as EventHandler; - if (handler != null) + if (Events[dwellEndEventKey] is EventHandler handler) handler(this, e); } @@ -1780,8 +1767,7 @@ protected virtual void OnDwellEnd(DwellEventArgs e) /// A that contains the event data. protected virtual void OnDwellStart(DwellEventArgs e) { - var handler = Events[dwellStartEventKey] as EventHandler; - if (handler != null) + if (Events[dwellStartEventKey] is EventHandler handler) handler(this, e); } @@ -1791,8 +1777,7 @@ protected virtual void OnDwellStart(DwellEventArgs e) /// A that contains the event data. protected virtual void OnCallTipClick(CallTipClickEventArgs e) { - var handler = Events[callTipClickEventKey] as EventHandler; - if (handler != null) + if (Events[callTipClickEventKey] is EventHandler handler) handler(this, e); } @@ -1814,8 +1799,8 @@ protected override unsafe void OnHandleCreated(EventArgs e) // ways to solve this, but my favorite is to revoke drag and drop from the // native Scintilla control before base.OnHandleCreated does the standard // processing of AllowDrop. - if (!this._ScintillaManagedDragDrop) - NativeMethods.RevokeDragDrop(this.Handle); + if (!_ScintillaManagedDragDrop) + NativeMethods.RevokeDragDrop(Handle); base.OnHandleCreated(e); } @@ -1826,8 +1811,7 @@ protected override unsafe void OnHandleCreated(EventArgs e) /// A that contains the event data. protected virtual void OnHotspotClick(HotspotClickEventArgs e) { - var handler = Events[hotspotClickEventKey] as EventHandler; - if (handler != null) + if (Events[hotspotClickEventKey] is EventHandler handler) handler(this, e); } @@ -1837,8 +1821,7 @@ protected virtual void OnHotspotClick(HotspotClickEventArgs e) /// A that contains the event data. protected virtual void OnHotspotDoubleClick(HotspotClickEventArgs e) { - var handler = Events[hotspotDoubleClickEventKey] as EventHandler; - if (handler != null) + if (Events[hotspotDoubleClickEventKey] is EventHandler handler) handler(this, e); } @@ -1848,8 +1831,7 @@ protected virtual void OnHotspotDoubleClick(HotspotClickEventArgs e) /// A that contains the event data. protected virtual void OnHotspotReleaseClick(HotspotClickEventArgs e) { - var handler = Events[hotspotReleaseClickEventKey] as EventHandler; - if (handler != null) + if (Events[hotspotReleaseClickEventKey] is EventHandler handler) handler(this, e); } @@ -1859,8 +1841,7 @@ protected virtual void OnHotspotReleaseClick(HotspotClickEventArgs e) /// An that contains the event data. protected virtual void OnIndicatorClick(IndicatorClickEventArgs e) { - var handler = Events[indicatorClickEventKey] as EventHandler; - if (handler != null) + if (Events[indicatorClickEventKey] is EventHandler handler) handler(this, e); } @@ -1870,8 +1851,7 @@ protected virtual void OnIndicatorClick(IndicatorClickEventArgs e) /// An that contains the event data. protected virtual void OnIndicatorRelease(IndicatorReleaseEventArgs e) { - var handler = Events[indicatorReleaseEventKey] as EventHandler; - if (handler != null) + if (Events[indicatorReleaseEventKey] is EventHandler handler) handler(this, e); } @@ -1881,8 +1861,7 @@ protected virtual void OnIndicatorRelease(IndicatorReleaseEventArgs e) /// A that contains the event data. protected virtual void OnInsert(ModificationEventArgs e) { - var handler = Events[insertEventKey] as EventHandler; - if (handler != null) + if (Events[insertEventKey] is EventHandler handler) handler(this, e); } @@ -1892,8 +1871,7 @@ protected virtual void OnInsert(ModificationEventArgs e) /// An that contains the event data. protected virtual void OnInsertCheck(InsertCheckEventArgs e) { - var handler = Events[insertCheckEventKey] as EventHandler; - if (handler != null) + if (Events[insertCheckEventKey] is EventHandler handler) handler(this, e); } @@ -1903,8 +1881,7 @@ protected virtual void OnInsertCheck(InsertCheckEventArgs e) /// A that contains the event data. protected virtual void OnMarginClick(MarginClickEventArgs e) { - var handler = Events[marginClickEventKey] as EventHandler; - if (handler != null) + if (Events[marginClickEventKey] is EventHandler handler) handler(this, e); } @@ -1914,8 +1891,7 @@ protected virtual void OnMarginClick(MarginClickEventArgs e) /// A that contains the event data. protected virtual void OnMarginRightClick(MarginClickEventArgs e) { - var handler = Events[marginRightClickEventKey] as EventHandler; - if (handler != null) + if (Events[marginRightClickEventKey] is EventHandler handler) handler(this, e); } @@ -1925,8 +1901,7 @@ protected virtual void OnMarginRightClick(MarginClickEventArgs e) /// An EventArgs that contains the event data. protected virtual void OnModifyAttempt(EventArgs e) { - var handler = Events[modifyAttemptEventKey] as EventHandler; - if (handler != null) + if (Events[modifyAttemptEventKey] is EventHandler handler) handler(this, e); } @@ -1937,7 +1912,7 @@ protected virtual void OnModifyAttempt(EventArgs e) protected override void OnMouseUp(MouseEventArgs e) { // Borrowed this from TextBoxBase.OnMouseUp - if (!doubleClick) + if (!this.doubleClick) { OnClick(e); OnMouseClick(e); @@ -1947,7 +1922,7 @@ protected override void OnMouseUp(MouseEventArgs e) var doubleE = new MouseEventArgs(e.Button, 2, e.X, e.Y, e.Delta); OnDoubleClick(doubleE); OnMouseDoubleClick(doubleE); - doubleClick = false; + this.doubleClick = false; } base.OnMouseUp(e); @@ -1959,8 +1934,7 @@ protected override void OnMouseUp(MouseEventArgs e) /// A that contains the event data. protected virtual void OnNeedShown(NeedShownEventArgs e) { - var handler = Events[needShownEventKey] as EventHandler; - if (handler != null) + if (Events[needShownEventKey] is EventHandler handler) handler(this, e); } @@ -1970,8 +1944,7 @@ protected virtual void OnNeedShown(NeedShownEventArgs e) /// An EventArgs that contains the event data. protected virtual void OnPainted(EventArgs e) { - var handler = Events[paintedEventKey] as EventHandler; - if (handler != null) + if (Events[paintedEventKey] is EventHandler handler) handler(this, e); } @@ -1981,8 +1954,7 @@ protected virtual void OnPainted(EventArgs e) /// An EventArgs that contains the event data. protected virtual void OnSavePointLeft(EventArgs e) { - var handler = Events[savePointLeftEventKey] as EventHandler; - if (handler != null) + if (Events[savePointLeftEventKey] is EventHandler handler) handler(this, e); } @@ -1992,8 +1964,7 @@ protected virtual void OnSavePointLeft(EventArgs e) /// An EventArgs that contains the event data. protected virtual void OnSavePointReached(EventArgs e) { - var handler = Events[savePointReachedEventKey] as EventHandler; - if (handler != null) + if (Events[savePointReachedEventKey] is EventHandler handler) handler(this, e); } @@ -2003,8 +1974,7 @@ protected virtual void OnSavePointReached(EventArgs e) /// A that contains the event data. protected virtual void OnStyleNeeded(StyleNeededEventArgs e) { - var handler = Events[styleNeededEventKey] as EventHandler; - if (handler != null) + if (Events[styleNeededEventKey] is EventHandler handler) handler(this, e); } @@ -2014,8 +1984,7 @@ protected virtual void OnStyleNeeded(StyleNeededEventArgs e) /// An that contains the event data. protected virtual void OnUpdateUI(UpdateUIEventArgs e) { - EventHandler handler = Events[updateUIEventKey] as EventHandler; - if (handler != null) + if (Events[updateUIEventKey] is EventHandler handler) handler(this, e); } @@ -2025,8 +1994,7 @@ protected virtual void OnUpdateUI(UpdateUIEventArgs e) /// An EventArgs that contains the event data. protected virtual void OnZoomChanged(EventArgs e) { - var handler = Events[zoomChangedEventKey] as EventHandler; - if (handler != null) + if (Events[zoomChangedEventKey] is EventHandler handler) handler(this, e); } @@ -2068,11 +2036,11 @@ public int PointYFromPosition(int pos) /// A String of property names separated by line breaks. public unsafe string PropertyNames() { - var length = DirectMessage(NativeMethods.SCI_PROPERTYNAMES).ToInt32(); + int length = DirectMessage(NativeMethods.SCI_PROPERTYNAMES).ToInt32(); if (length == 0) return string.Empty; - var bytes = new byte[length + 1]; + byte[] bytes = new byte[length + 1]; fixed (byte* bp = bytes) { DirectMessage(NativeMethods.SCI_PROPERTYNAMES, IntPtr.Zero, new IntPtr(bp)); @@ -2088,10 +2056,10 @@ public unsafe string PropertyNames() /// A list of supported property names for the current Lexer can be obtained by calling . public unsafe PropertyType PropertyType(string name) { - if (String.IsNullOrEmpty(name)) + if (string.IsNullOrEmpty(name)) return ScintillaNET.PropertyType.Boolean; - var bytes = Helpers.GetBytes(name, Encoding.ASCII, zeroTerminated: true); + byte[] bytes = Helpers.GetBytes(name, Encoding.ASCII, zeroTerminated: true); fixed (byte* bp = bytes) return (PropertyType)DirectMessage(NativeMethods.SCI_PROPERTYTYPE, new IntPtr(bp)); } @@ -2124,7 +2092,7 @@ public unsafe void RegisterRgbaImage(int type, Bitmap image) DirectMessage(NativeMethods.SCI_RGBAIMAGESETWIDTH, new IntPtr(image.Width)); DirectMessage(NativeMethods.SCI_RGBAIMAGESETHEIGHT, new IntPtr(image.Height)); - var bytes = Helpers.BitmapToArgb(image); + byte[] bytes = Helpers.BitmapToArgb(image); fixed (byte* bp = bytes) DirectMessage(NativeMethods.SCI_REGISTERRGBAIMAGE, new IntPtr(type), new IntPtr(bp)); } @@ -2138,7 +2106,7 @@ public unsafe void RegisterRgbaImage(int type, Bitmap image) /// public void ReleaseDocument(Document document) { - var ptr = document.Value; + IntPtr ptr = document.Value; DirectMessage(NativeMethods.SCI_RELEASEDOCUMENT, IntPtr.Zero, ptr); } @@ -2167,12 +2135,11 @@ public unsafe void ReplaceSelection(string text) /// public unsafe int ReplaceTarget(string text) { - if (text == null) - text = string.Empty; + text ??= string.Empty; - var bytes = Helpers.GetBytes(text, Encoding, false); + byte[] bytes = Helpers.GetBytes(text, Encoding, false); // Scintilla asserts that lParam is not null, so make sure it isn't - var length = bytes.Length; + int length = bytes.Length; if (length == 0) bytes = new byte[] { 0 }; fixed (byte* bp = bytes) @@ -2194,9 +2161,9 @@ public unsafe int ReplaceTarget(string text) /// public unsafe int ReplaceTargetRe(string text) { - var bytes = Helpers.GetBytes(text ?? string.Empty, Encoding, false); + byte[] bytes = Helpers.GetBytes(text ?? string.Empty, Encoding, false); // Scintilla asserts that lParam is not null, so make sure it isn't - var length = bytes.Length; + int length = bytes.Length; if (length == 0) bytes = new byte[] { 0 }; fixed (byte* bp = bytes) @@ -2220,14 +2187,14 @@ public void RotateSelection() private void ScnDoubleClick(ref NativeMethods.SCNotification scn) { - var keys = Keys.Modifiers & (Keys)(scn.modifiers << 16); + Keys keys = Keys.Modifiers & (Keys)(scn.modifiers << 16); var eventArgs = new DoubleClickEventArgs(this, keys, scn.position.ToInt32(), scn.line.ToInt32()); OnDoubleClick(eventArgs); } private void ScnHotspotClick(ref NativeMethods.SCNotification scn) { - var keys = Keys.Modifiers & (Keys)(scn.modifiers << 16); + Keys keys = Keys.Modifiers & (Keys)(scn.modifiers << 16); var eventArgs = new HotspotClickEventArgs(this, keys, scn.position.ToInt32()); switch (scn.nmhdr.code) { @@ -2250,7 +2217,7 @@ private void ScnIndicatorClick(ref NativeMethods.SCNotification scn) switch (scn.nmhdr.code) { case NativeMethods.SCN_INDICATORCLICK: - var keys = Keys.Modifiers & (Keys)(scn.modifiers << 16); + Keys keys = Keys.Modifiers & (Keys)(scn.modifiers << 16); OnIndicatorClick(new IndicatorClickEventArgs(this, keys, scn.position.ToInt32())); break; @@ -2262,7 +2229,7 @@ private void ScnIndicatorClick(ref NativeMethods.SCNotification scn) private void ScnMarginClick(ref NativeMethods.SCNotification scn) { - var keys = Keys.Modifiers & (Keys)(scn.modifiers << 16); + Keys keys = Keys.Modifiers & (Keys)(scn.modifiers << 16); var eventArgs = new MarginClickEventArgs(this, keys, scn.position.ToInt32(), scn.margin); if (scn.nmhdr.code == NativeMethods.SCN_MARGINCLICK) @@ -2282,19 +2249,19 @@ private void ScnModified(ref NativeMethods.SCNotification scn) var eventArgs = new InsertCheckEventArgs(this, scn.position.ToInt32(), scn.length.ToInt32(), scn.text); OnInsertCheck(eventArgs); - cachedPosition = eventArgs.CachedPosition; - cachedText = eventArgs.CachedText; + this.cachedPosition = eventArgs.CachedPosition; + this.cachedText = eventArgs.CachedText; } - const int sourceMask = (NativeMethods.SC_PERFORMED_USER | NativeMethods.SC_PERFORMED_UNDO | NativeMethods.SC_PERFORMED_REDO); + const int sourceMask = NativeMethods.SC_PERFORMED_USER | NativeMethods.SC_PERFORMED_UNDO | NativeMethods.SC_PERFORMED_REDO; if ((scn.modificationType & (NativeMethods.SC_MOD_BEFOREDELETE | NativeMethods.SC_MOD_BEFOREINSERT)) > 0) { var source = (ModificationSource)(scn.modificationType & sourceMask); - var eventArgs = new BeforeModificationEventArgs(this, source, scn.position.ToInt32(), scn.length.ToInt32(), scn.text); - - eventArgs.CachedPosition = cachedPosition; - eventArgs.CachedText = cachedText; + var eventArgs = new BeforeModificationEventArgs(this, source, scn.position.ToInt32(), scn.length.ToInt32(), scn.text) { + CachedPosition = this.cachedPosition, + CachedText = this.cachedText + }; if ((scn.modificationType & NativeMethods.SC_MOD_BEFOREINSERT) > 0) { @@ -2305,17 +2272,17 @@ private void ScnModified(ref NativeMethods.SCNotification scn) OnBeforeDelete(eventArgs); } - cachedPosition = eventArgs.CachedPosition; - cachedText = eventArgs.CachedText; + this.cachedPosition = eventArgs.CachedPosition; + this.cachedText = eventArgs.CachedText; } if ((scn.modificationType & (NativeMethods.SC_MOD_DELETETEXT | NativeMethods.SC_MOD_INSERTTEXT)) > 0) { var source = (ModificationSource)(scn.modificationType & sourceMask); - var eventArgs = new ModificationEventArgs(this, source, scn.position.ToInt32(), scn.length.ToInt32(), scn.text, scn.linesAdded.ToInt32()); - - eventArgs.CachedPosition = cachedPosition; - eventArgs.CachedText = cachedText; + var eventArgs = new ModificationEventArgs(this, source, scn.position.ToInt32(), scn.length.ToInt32(), scn.text, scn.linesAdded.ToInt32()) { + CachedPosition = this.cachedPosition, + CachedText = this.cachedText + }; if ((scn.modificationType & NativeMethods.SC_MOD_INSERTTEXT) > 0) { @@ -2327,8 +2294,8 @@ private void ScnModified(ref NativeMethods.SCNotification scn) } // Always clear the cache - cachedPosition = null; - cachedText = null; + this.cachedPosition = null; + this.cachedText = null; // For backward compatibility.... Of course this means that we'll raise two // TextChanged events for replace (insert/delete) operations, but that's life. @@ -2361,7 +2328,7 @@ public void ScrollCaret() /// This may be used to make a search match visible. public void ScrollRange(int start, int end) { - var textLength = TextLength; + int textLength = TextLength; start = Helpers.Clamp(start, 0, textLength); end = Helpers.Clamp(end, 0, textLength); @@ -2386,9 +2353,9 @@ public void ScrollRange(int start, int end) public unsafe int SearchInTarget(string text) { int bytePos = 0; - var bytes = Helpers.GetBytes(text ?? string.Empty, Encoding, zeroTerminated: false); + byte[] bytes = Helpers.GetBytes(text ?? string.Empty, Encoding, zeroTerminated: false); // Scintilla asserts that lParam is not null, so make sure it isn't - var length = bytes.Length; + int length = bytes.Length; if (length == 0) bytes = new byte[] { 0 }; fixed (byte* bp = bytes) @@ -2417,7 +2384,7 @@ public void SelectAll() [Obsolete("Superseded by SelectionAdditionalBackColor property.")] public void SetAdditionalSelBack(Color color) { - var colour = HelperMethods.ToWin32Color(color); + int colour = HelperMethods.ToWin32Color(color); DirectMessage(NativeMethods.SCI_SETADDITIONALSELBACK, new IntPtr(colour)); } @@ -2429,7 +2396,7 @@ public void SetAdditionalSelBack(Color color) [Obsolete("Superseded by SelectionAdditionalTextColor property.")] public void SetAdditionalSelFore(Color color) { - var colour = HelperMethods.ToWin32Color(color); + int colour = HelperMethods.ToWin32Color(color); DirectMessage(NativeMethods.SCI_SETADDITIONALSELFORE, new IntPtr(colour)); } @@ -2462,8 +2429,8 @@ public void SetFoldFlags(FoldFlags flags) /// public void SetFoldMarginColor(bool use, Color color) { - var colour = HelperMethods.ToWin32Color(color); - var useFoldMarginColour = (use ? new IntPtr(1) : IntPtr.Zero); + int colour = HelperMethods.ToWin32Color(color); + IntPtr useFoldMarginColour = use ? new IntPtr(1) : IntPtr.Zero; DirectMessage(NativeMethods.SCI_SETFOLDMARGINCOLOUR, useFoldMarginColour, new IntPtr(colour)); } @@ -2476,8 +2443,8 @@ public void SetFoldMarginColor(bool use, Color color) /// public void SetFoldMarginHighlightColor(bool use, Color color) { - var colour = HelperMethods.ToWin32Color(color); - var useFoldMarginHighlightColour = (use ? new IntPtr(1) : IntPtr.Zero); + int colour = HelperMethods.ToWin32Color(color); + IntPtr useFoldMarginHighlightColour = use ? new IntPtr(1) : IntPtr.Zero; DirectMessage(NativeMethods.SCI_SETFOLDMARGINHICOLOUR, useFoldMarginHighlightColour, new IntPtr(colour)); } @@ -2489,13 +2456,13 @@ public void SetFoldMarginHighlightColor(bool use, Color color) /// A list of words separated by whitespace (space, tab, '\n', '\r') characters. public unsafe void SetIdentifiers(int style, string identifiers) { - var baseStyle = GetStyleFromSubstyle(style); - var min = GetSubstylesStart(baseStyle); - var length = GetSubstylesLength(baseStyle); - var max = (length > 0) ? min + length - 1 : min; + int baseStyle = GetStyleFromSubstyle(style); + int min = GetSubstylesStart(baseStyle); + int length = GetSubstylesLength(baseStyle); + int max = (length > 0) ? min + length - 1 : min; style = Helpers.Clamp(style, min, max); - var bytes = Helpers.GetBytes(identifiers ?? string.Empty, Encoding.ASCII, zeroTerminated: true); + byte[] bytes = Helpers.GetBytes(identifiers ?? string.Empty, Encoding.ASCII, zeroTerminated: true); fixed (byte* bp = bytes) DirectMessage(NativeMethods.SCI_SETIDENTIFIERS, new IntPtr(style), new IntPtr(bp)); @@ -2513,7 +2480,7 @@ public unsafe void SetIdentifiers(int style, string identifiers) public unsafe void SetKeywords(int set, string keywords) { set = Helpers.Clamp(set, 0, NativeMethods.KEYWORDSET_MAX); - var bytes = Helpers.GetBytes(keywords ?? string.Empty, Encoding.ASCII, zeroTerminated: true); + byte[] bytes = Helpers.GetBytes(keywords ?? string.Empty, Encoding.ASCII, zeroTerminated: true); fixed (byte* bp = bytes) DirectMessage(NativeMethods.SCI_SETKEYWORDS, new IntPtr(set), new IntPtr(bp)); @@ -2530,10 +2497,7 @@ public unsafe void SetKeywords(int set, string keywords) public static void SetDestroyHandleBehavior(bool reparent) { // WM_DESTROY workaround - if (Scintilla.reparentAll == null) - { - Scintilla.reparentAll = reparent; - } + Scintilla.reparentAll ??= reparent; } /// @@ -2548,11 +2512,11 @@ public static void SetDestroyHandleBehavior(bool reparent) /// Property names are case-sensitive. public unsafe void SetProperty(string name, string value) { - if (String.IsNullOrEmpty(name)) + if (string.IsNullOrEmpty(name)) return; - var nameBytes = Helpers.GetBytes(name, Encoding.ASCII, zeroTerminated: true); - var valueBytes = Helpers.GetBytes(value ?? string.Empty, Encoding.ASCII, zeroTerminated: true); + byte[] nameBytes = Helpers.GetBytes(name, Encoding.ASCII, zeroTerminated: true); + byte[] valueBytes = Helpers.GetBytes(value ?? string.Empty, Encoding.ASCII, zeroTerminated: true); fixed (byte* nb = nameBytes) fixed (byte* vb = valueBytes) @@ -2569,10 +2533,10 @@ private bool SetRenderer(VisualStyleElement element) if (!VisualStyleRenderer.IsElementDefined(element)) return false; - if (renderer == null) - renderer = new VisualStyleRenderer(element); + if (this.renderer == null) + this.renderer = new VisualStyleRenderer(element); else - renderer.SetParameters(element); + this.renderer.SetParameters(element); return true; } @@ -2606,7 +2570,7 @@ public void SetSel(int anchorPos, int currentPos) anchorPos = -1; } - var textLength = TextLength; + int textLength = TextLength; if (anchorPos >= 0) { @@ -2630,7 +2594,7 @@ public void SetSel(int anchorPos, int currentPos) /// The zero-based document position to start the selection. public void SetSelection(int caret, int anchor) { - var textLength = TextLength; + int textLength = TextLength; caret = Helpers.Clamp(caret, 0, textLength); anchor = Helpers.Clamp(anchor, 0, textLength); @@ -2650,8 +2614,8 @@ public void SetSelection(int caret, int anchor) [Obsolete("Superseded by SelectionBackColor property.")] public void SetSelectionBackColor(bool use, Color color) { - var colour = HelperMethods.ToWin32Color(color); - var useSelectionForeColour = (use ? new IntPtr(1) : IntPtr.Zero); + int colour = HelperMethods.ToWin32Color(color); + IntPtr useSelectionForeColour = use ? new IntPtr(1) : IntPtr.Zero; DirectMessage(NativeMethods.SCI_SETSELBACK, useSelectionForeColour, new IntPtr(colour)); } @@ -2665,8 +2629,8 @@ public void SetSelectionBackColor(bool use, Color color) [Obsolete("Superseded by SelectionTextColor property.")] public void SetSelectionForeColor(bool use, Color color) { - var colour = HelperMethods.ToWin32Color(color); - var useSelectionForeColour = (use ? new IntPtr(1) : IntPtr.Zero); + int colour = HelperMethods.ToWin32Color(color); + IntPtr useSelectionForeColour = use ? new IntPtr(1) : IntPtr.Zero; DirectMessage(NativeMethods.SCI_SETSELFORE, useSelectionForeColour, new IntPtr(colour)); } @@ -2707,22 +2671,22 @@ public Layer SelectionLayer /// public void SetStyling(int length, int style) { - var textLength = TextLength; + int textLength = TextLength; if (length < 0) throw new ArgumentOutOfRangeException("length", "Length cannot be less than zero."); - if (stylingPosition + length > textLength) + if (this.stylingPosition + length > textLength) throw new ArgumentOutOfRangeException("length", "Position and length must refer to a range within the document."); if (style < 0 || style >= Styles.Count) throw new ArgumentOutOfRangeException("style", "Style must be non-negative and less than the size of the collection."); - var endPos = stylingPosition + length; - var endBytePos = Lines.CharToBytePosition(endPos); - DirectMessage(NativeMethods.SCI_SETSTYLING, new IntPtr(endBytePos - stylingBytePosition), new IntPtr(style)); + int endPos = this.stylingPosition + length; + int endBytePos = Lines.CharToBytePosition(endPos); + DirectMessage(NativeMethods.SCI_SETSTYLING, new IntPtr(endBytePos - this.stylingBytePosition), new IntPtr(style)); // Track this for the next call - stylingPosition = endPos; - stylingBytePosition = endBytePos; + this.stylingPosition = endPos; + this.stylingBytePosition = endBytePos; } /// @@ -2734,7 +2698,7 @@ public void SetStyling(int length, int style) /// public void SetTargetRange(int start, int end) { - var textLength = TextLength; + int textLength = TextLength; start = Helpers.Clamp(start, 0, textLength); end = Helpers.Clamp(end, 0, textLength); @@ -2755,8 +2719,8 @@ public void SetTargetRange(int start, int end) [Obsolete("Superseded by WhitespaceBackColor property.")] public void SetWhitespaceBackColor(bool use, Color color) { - var colour = HelperMethods.ToWin32Color(color); - var useWhitespaceBackColour = (use ? new IntPtr(1) : IntPtr.Zero); + int colour = HelperMethods.ToWin32Color(color); + IntPtr useWhitespaceBackColour = use ? new IntPtr(1) : IntPtr.Zero; DirectMessage(NativeMethods.SCI_SETWHITESPACEBACK, useWhitespaceBackColour, new IntPtr(colour)); } @@ -2772,8 +2736,8 @@ public void SetWhitespaceBackColor(bool use, Color color) [Obsolete("Superseded by WhitespaceTextColor property.")] public void SetWhitespaceForeColor(bool use, Color color) { - var colour = HelperMethods.ToWin32Color(color); - var useWhitespaceForeColour = (use ? new IntPtr(1) : IntPtr.Zero); + int colour = HelperMethods.ToWin32Color(color); + IntPtr useWhitespaceForeColour = use ? new IntPtr(1) : IntPtr.Zero; DirectMessage(NativeMethods.SCI_SETWHITESPACEFORE, useWhitespaceForeColour, new IntPtr(colour)); } @@ -2830,12 +2794,12 @@ public void ShowLines(int lineStart, int lineEnd) public void StartStyling(int position) { position = Helpers.Clamp(position, 0, TextLength); - var pos = Lines.CharToBytePosition(position); + int pos = Lines.CharToBytePosition(position); DirectMessage(NativeMethods.SCI_STARTSTYLING, new IntPtr(pos)); // Track this so we can validate calls to SetStyling - stylingPosition = position; - stylingBytePosition = pos; + this.stylingPosition = position; + this.stylingBytePosition = pos; } /// @@ -2891,7 +2855,7 @@ public void TargetWholeDocument() public unsafe int TextWidth(int style, string text) { style = Helpers.Clamp(style, 0, Styles.Count - 1); - var bytes = Helpers.GetBytes(text ?? string.Empty, Encoding, zeroTerminated: true); + byte[] bytes = Helpers.GetBytes(text ?? string.Empty, Encoding, zeroTerminated: true); fixed (byte* bp = bytes) { @@ -2915,7 +2879,7 @@ public void Undo() public void UsePopup(bool enablePopup) { // NOTE: The behavior of UsePopup has changed in v3.7.1, however, this approach is still valid - var bEnablePopup = (enablePopup ? new IntPtr(1) : IntPtr.Zero); + IntPtr bEnablePopup = enablePopup ? new IntPtr(1) : IntPtr.Zero; DirectMessage(NativeMethods.SCI_USEPOPUP, bEnablePopup); } @@ -2931,7 +2895,7 @@ public void UsePopup(PopupMode popupMode) private void WmDestroy(ref Message m) { // WM_DESTROY workaround - if (reparent && IsHandleCreated) + if (this.reparent && IsHandleCreated) { // In some circumstances it's possible for the control's window handle to be destroyed // and recreated during the life of the control. I have no idea why Windows Forms was coded @@ -2977,23 +2941,20 @@ private void WmNcPaint(ref Message m) return; } - NativeMethods.RECT windowRect; - NativeMethods.GetWindowRect(m.HWnd, out windowRect); + NativeMethods.GetWindowRect(m.HWnd, out NativeMethods.RECT windowRect); Size borderSize = SystemInformation.Border3DSize; IntPtr hDC = NativeMethods.GetWindowDC(m.HWnd); try { - using (Graphics graphics = Graphics.FromHdc(hDC)) - { - // Clip everything except the border - Rectangle bounds = new Rectangle(0, 0, windowRect.right - windowRect.left, windowRect.bottom - windowRect.top); - graphics.ExcludeClip(Rectangle.Inflate(bounds, -borderSize.Width, -borderSize.Height)); - - // Paint the theme border - if (renderer.IsBackgroundPartiallyTransparent()) - renderer.DrawParentBackground(graphics, bounds, this); - renderer.DrawBackground(graphics, bounds); - } + using var graphics = Graphics.FromHdc(hDC); + // Clip everything except the border + var bounds = new Rectangle(0, 0, windowRect.right - windowRect.left, windowRect.bottom - windowRect.top); + graphics.ExcludeClip(Rectangle.Inflate(bounds, -borderSize.Width, -borderSize.Height)); + + // Paint the theme border + if (this.renderer.IsBackgroundPartiallyTransparent()) + this.renderer.DrawParentBackground(graphics, bounds, this); + this.renderer.DrawBackground(graphics, bounds); } finally { @@ -3019,11 +2980,10 @@ private void WmNcPaint(ref Message m) private void WmReflectNotify(ref Message m) { // A standard Windows notification and a Scintilla notification header are compatible - NativeMethods.SCNotification scn = (NativeMethods.SCNotification)Marshal.PtrToStructure(m.LParam, typeof(NativeMethods.SCNotification)); - if (scn.nmhdr.code >= NativeMethods.SCN_STYLENEEDED && scn.nmhdr.code <= NativeMethods.SCN_AUTOCSELECTIONCHANGE) + var scn = (NativeMethods.SCNotification)Marshal.PtrToStructure(m.LParam, typeof(NativeMethods.SCNotification)); + if (scn.nmhdr.code is >= NativeMethods.SCN_STYLENEEDED and <= NativeMethods.SCN_AUTOCSELECTIONCHANGE) { - var handler = Events[scNotificationEventKey] as EventHandler; - if (handler != null) + if (Events[scNotificationEventKey] is EventHandler handler) handler(this, new SCNotificationEventArgs(scn)); switch (scn.nmhdr.code) @@ -3119,7 +3079,7 @@ private void WmReflectNotify(ref Message m) case NativeMethods.SCN_CALLTIPCLICK: OnCallTipClick(new CallTipClickEventArgs(this, (CallTipClickType)scn.position.ToInt32())); // scn.position: 1 = Up Arrow, 2 = DownArrow: 0 = Elsewhere - break; + break; default: // Not our notification @@ -3137,7 +3097,7 @@ protected override void WndProc(ref Message m) { switch (m.Msg) { - case (NativeMethods.WM_REFLECT + NativeMethods.WM_NOTIFY): + case NativeMethods.WM_REFLECT + NativeMethods.WM_NOTIFY: WmReflectNotify(ref m); break; @@ -3153,7 +3113,7 @@ protected override void WndProc(ref Message m) case NativeMethods.WM_RBUTTONDBLCLK: case NativeMethods.WM_MBUTTONDBLCLK: case NativeMethods.WM_XBUTTONDBLCLK: - doubleClick = true; + this.doubleClick = true; goto default; case NativeMethods.WM_DESTROY: @@ -3178,7 +3138,7 @@ protected override void WndProc(ref Message m) /// public int WordEndPosition(int position, bool onlyWordCharacters) { - var onlyWordChars = (onlyWordCharacters ? new IntPtr(1) : IntPtr.Zero); + IntPtr onlyWordChars = onlyWordCharacters ? new IntPtr(1) : IntPtr.Zero; position = Helpers.Clamp(position, 0, TextLength); position = Lines.CharToBytePosition(position); position = DirectMessage(NativeMethods.SCI_WORDENDPOSITION, new IntPtr(position), onlyWordChars).ToInt32(); @@ -3197,7 +3157,7 @@ public int WordEndPosition(int position, bool onlyWordCharacters) /// public int WordStartPosition(int position, bool onlyWordCharacters) { - var onlyWordChars = (onlyWordCharacters ? new IntPtr(1) : IntPtr.Zero); + IntPtr onlyWordChars = onlyWordCharacters ? new IntPtr(1) : IntPtr.Zero; position = Helpers.Clamp(position, 0, TextLength); position = Lines.CharToBytePosition(position); position = DirectMessage(NativeMethods.SCI_WORDSTARTPOSITION, new IntPtr(position), onlyWordChars).ToInt32(); @@ -3230,8 +3190,8 @@ public void ZoomOut() /// The must be set to for this to work. public unsafe void SetRepresentation(string encodedString, string representationString) { - var bytesEncoded = Helpers.GetBytes(encodedString, Encoding, zeroTerminated: true); - var bytesRepresentation = Helpers.GetBytes(representationString, Encoding, zeroTerminated: true); + byte[] bytesEncoded = Helpers.GetBytes(encodedString, Encoding, zeroTerminated: true); + byte[] bytesRepresentation = Helpers.GetBytes(representationString, Encoding, zeroTerminated: true); fixed (byte* bpEncoded = bytesEncoded) { fixed (byte* bpRepresentation = bytesRepresentation) @@ -3248,13 +3208,13 @@ public unsafe void SetRepresentation(string encodedString, string representation /// The representation string for the . I.e. "OHM". public unsafe string GetRepresentation(string encodedString) { - var bytesEncoded = Helpers.GetBytes(encodedString, Encoding, zeroTerminated: true); + byte[] bytesEncoded = Helpers.GetBytes(encodedString, Encoding, zeroTerminated: true); fixed (byte* bpEncoded = bytesEncoded) { - var length = DirectMessage(NativeMethods.SCI_GETREPRESENTATION, new IntPtr(bpEncoded), IntPtr.Zero) + int length = DirectMessage(NativeMethods.SCI_GETREPRESENTATION, new IntPtr(bpEncoded), IntPtr.Zero) .ToInt32(); - var bytesRepresentation = new byte[length + 1]; + byte[] bytesRepresentation = new byte[length + 1]; fixed (byte* bpRepresentation = bytesRepresentation) { DirectMessage(NativeMethods.SCI_GETREPRESENTATION, new IntPtr(bpEncoded), new IntPtr(bpRepresentation)); @@ -3269,7 +3229,7 @@ public unsafe string GetRepresentation(string encodedString) /// The encoded string. I.e. the Ohm character: Ω = \u2126. public unsafe void ClearRepresentation(string encodedString) { - var bytesEncoded = Helpers.GetBytes(encodedString, Encoding, zeroTerminated: true); + byte[] bytesEncoded = Helpers.GetBytes(encodedString, Encoding, zeroTerminated: true); fixed (byte* bpEncoded = bytesEncoded) { DirectMessage(NativeMethods.SCI_CLEARREPRESENTATION, new IntPtr(bpEncoded), IntPtr.Zero); @@ -3283,9 +3243,9 @@ public unsafe void ClearRepresentation(string encodedString) public void ClearChangeHistory() { EmptyUndoBuffer(); - var ch = this.ChangeHistory; - this.ChangeHistory = ChangeHistory.Disabled; - this.ChangeHistory = ch; + ChangeHistory ch = ChangeHistory; + ChangeHistory = ChangeHistory.Disabled; + ChangeHistory = ch; } #endregion Methods @@ -3313,13 +3273,13 @@ public void ClearChangeHistory() [Description("The bi-directionality of the Scintilla control.")] public BiDirectionalDisplayType BiDirectionality { - get => (BiDirectionalDisplayType) DirectMessage(NativeMethods.SCI_GETBIDIRECTIONAL).ToInt32(); + get => (BiDirectionalDisplayType)DirectMessage(NativeMethods.SCI_GETBIDIRECTIONAL).ToInt32(); set { if (value != BiDirectionalDisplayType.Disabled) { - var technology = DirectMessage(NativeMethods.SCI_GETTECHNOLOGY).ToInt32(); + int technology = DirectMessage(NativeMethods.SCI_GETTECHNOLOGY).ToInt32(); if (technology == NativeMethods.SC_TECHNOLOGY_DEFAULT) { DirectMessage(NativeMethods.SCI_SETTECHNOLOGY, new IntPtr(NativeMethods.SC_TECHNOLOGY_DIRECTWRITE)); @@ -3347,7 +3307,7 @@ public bool UseRightToLeftReadingLayout } long exStyle = Handle.GetWindowLongPtr(WinApiHelpers.GWL_EXSTYLE).ToInt64(); - + return exStyle == (exStyle | WinApiHelpers.WS_EX_LAYOUTRTL); } set @@ -3361,7 +3321,7 @@ public bool UseRightToLeftReadingLayout if (value) { - var technology = DirectMessage(NativeMethods.SCI_GETTECHNOLOGY).ToInt32(); + int technology = DirectMessage(NativeMethods.SCI_GETTECHNOLOGY).ToInt32(); if (technology != NativeMethods.SC_TECHNOLOGY_DEFAULT) { DirectMessage(NativeMethods.SCI_SETTECHNOLOGY, new IntPtr(NativeMethods.SC_TECHNOLOGY_DEFAULT)); @@ -3373,10 +3333,11 @@ public bool UseRightToLeftReadingLayout { exStyle &= ~WinApiHelpers.WS_EX_LAYOUTRTL; } + Handle.SetWindowLongPtr(WinApiHelpers.GWL_EXSTYLE, new IntPtr(exStyle)); // Workaround Scintilla mirrored rendering issue: - var wrapMode = WrapMode; + WrapMode wrapMode = WrapMode; WrapMode = wrapMode == WrapMode.None ? WrapMode.Word : WrapMode.None; WrapMode = wrapMode; } @@ -3417,7 +3378,7 @@ public bool AdditionalCaretsBlink } set { - var additionalCaretsBlink = (value ? new IntPtr(1) : IntPtr.Zero); + IntPtr additionalCaretsBlink = value ? new IntPtr(1) : IntPtr.Zero; DirectMessage(NativeMethods.SCI_SETADDITIONALCARETSBLINK, additionalCaretsBlink); } } @@ -3437,7 +3398,7 @@ public bool AdditionalCaretsVisible } set { - var additionalCaretsBlink = (value ? new IntPtr(1) : IntPtr.Zero); + IntPtr additionalCaretsBlink = value ? new IntPtr(1) : IntPtr.Zero; DirectMessage(NativeMethods.SCI_SETADDITIONALCARETSVISIBLE, additionalCaretsBlink); } } @@ -3483,7 +3444,7 @@ public bool AdditionalSelectionTyping } set { - var additionalSelectionTyping = (value ? new IntPtr(1) : IntPtr.Zero); + IntPtr additionalSelectionTyping = value ? new IntPtr(1) : IntPtr.Zero; DirectMessage(NativeMethods.SCI_SETADDITIONALSELECTIONTYPING, additionalSelectionTyping); } } @@ -3503,13 +3464,13 @@ public int AnchorPosition { get { - var bytePos = DirectMessage(NativeMethods.SCI_GETANCHOR).ToInt32(); + int bytePos = DirectMessage(NativeMethods.SCI_GETANCHOR).ToInt32(); return Lines.ByteToCharPosition(bytePos); } set { value = Helpers.Clamp(value, 0, TextLength); - var bytePos = Lines.CharToBytePosition(value); + int bytePos = Lines.CharToBytePosition(value); DirectMessage(NativeMethods.SCI_SETANCHOR, new IntPtr(bytePos)); } } @@ -3529,7 +3490,7 @@ public Annotation AnnotationVisible } set { - var visible = (int)value; + int visible = (int)value; DirectMessage(NativeMethods.SCI_ANNOTATIONSETVISIBLE, new IntPtr(visible)); } } @@ -3646,7 +3607,7 @@ public bool AutoCAutoHide } set { - var autoHide = (value ? new IntPtr(1) : IntPtr.Zero); + IntPtr autoHide = value ? new IntPtr(1) : IntPtr.Zero; DirectMessage(NativeMethods.SCI_AUTOCSETAUTOHIDE, autoHide); } } @@ -3670,7 +3631,7 @@ public bool AutoCCancelAtStart } set { - var cancel = (value ? new IntPtr(1) : IntPtr.Zero); + IntPtr cancel = value ? new IntPtr(1) : IntPtr.Zero; DirectMessage(NativeMethods.SCI_AUTOCSETCANCELATSTART, cancel); } } @@ -3707,7 +3668,7 @@ public bool AutoCChooseSingle } set { - var chooseSingle = (value ? new IntPtr(1) : IntPtr.Zero); + IntPtr chooseSingle = value ? new IntPtr(1) : IntPtr.Zero; DirectMessage(NativeMethods.SCI_AUTOCSETCHOOSESINGLE, chooseSingle); } } @@ -3729,7 +3690,7 @@ public bool AutoCDropRestOfWord } set { - var dropRestOfWord = (value ? new IntPtr(1) : IntPtr.Zero); + IntPtr dropRestOfWord = value ? new IntPtr(1) : IntPtr.Zero; DirectMessage(NativeMethods.SCI_AUTOCSETDROPRESTOFWORD, dropRestOfWord); } } @@ -3749,7 +3710,7 @@ public bool AutoCIgnoreCase } set { - var ignoreCase = (value ? new IntPtr(1) : IntPtr.Zero); + IntPtr ignoreCase = value ? new IntPtr(1) : IntPtr.Zero; DirectMessage(NativeMethods.SCI_AUTOCSETIGNORECASE, ignoreCase); } } @@ -3814,7 +3775,7 @@ public Order AutoCOrder } set { - var order = (int)value; + int order = (int)value; DirectMessage(NativeMethods.SCI_AUTOCSETORDER, new IntPtr(order)); } } @@ -3830,7 +3791,7 @@ public int AutoCPosStart { get { - var pos = DirectMessage(NativeMethods.SCI_AUTOCPOSSTART).ToInt32(); + int pos = DirectMessage(NativeMethods.SCI_AUTOCPOSSTART).ToInt32(); pos = Lines.ByteToCharPosition(pos); return pos; @@ -3845,12 +3806,12 @@ public int AutoCPosStart [DefaultValue(' ')] [Category("Autocompletion")] [Description("The autocompletion list word delimiter. The default is a space character.")] - public Char AutoCSeparator + public char AutoCSeparator { get { - var separator = DirectMessage(NativeMethods.SCI_AUTOCGETSEPARATOR).ToInt32(); - return (Char)separator; + int separator = DirectMessage(NativeMethods.SCI_AUTOCGETSEPARATOR).ToInt32(); + return (char)separator; } set { @@ -3858,7 +3819,7 @@ public Char AutoCSeparator // not a character. Thus it's possible for a user to supply a character that does // not fit within a single byte. The likelyhood of this, however, seems so remote that // I'm willing to risk a possible conversion error to provide a better user experience. - var separator = (byte)value; + byte separator = (byte)value; DirectMessage(NativeMethods.SCI_AUTOCSETSEPARATOR, new IntPtr(separator)); } } @@ -3871,12 +3832,12 @@ public Char AutoCSeparator [DefaultValue('?')] [Category("Autocompletion")] [Description("The autocompletion list image type delimiter.")] - public Char AutoCTypeSeparator + public char AutoCTypeSeparator { get { - var separatorCharacter = DirectMessage(NativeMethods.SCI_AUTOCGETTYPESEPARATOR).ToInt32(); - return (Char)separatorCharacter; + int separatorCharacter = DirectMessage(NativeMethods.SCI_AUTOCGETTYPESEPARATOR).ToInt32(); + return (char)separatorCharacter; } set { @@ -3884,7 +3845,7 @@ public Char AutoCTypeSeparator // not a character. Thus it's possible for a user to supply a character that does // not fit within a single byte. The likelyhood of this, however, seems so remote that // I'm willing to risk a possible conversion error to provide a better user experience. - var separatorCharacter = (byte)value; + byte separatorCharacter = (byte)value; DirectMessage(NativeMethods.SCI_AUTOCSETTYPESEPARATOR, new IntPtr(separatorCharacter)); } } @@ -3909,7 +3870,7 @@ public AutomaticFold AutomaticFold } set { - var automaticFold = (int)value; + int automaticFold = (int)value; DirectMessage(NativeMethods.SCI_SETAUTOMATICFOLD, new IntPtr(automaticFold)); } } @@ -3976,11 +3937,11 @@ public bool BackspaceUnindents { get { - return (DirectMessage(NativeMethods.SCI_GETBACKSPACEUNINDENTS) != IntPtr.Zero); + return DirectMessage(NativeMethods.SCI_GETBACKSPACEUNINDENTS) != IntPtr.Zero; } set { - var ptr = (value ? new IntPtr(1) : IntPtr.Zero); + IntPtr ptr = value ? new IntPtr(1) : IntPtr.Zero; DirectMessage(NativeMethods.SCI_SETBACKSPACEUNINDENTS, ptr); } } @@ -3997,16 +3958,16 @@ public BorderStyle BorderStyle { get { - return borderStyle; + return this.borderStyle; } set { - if (borderStyle != value) + if (this.borderStyle != value) { if (!Enum.IsDefined(typeof(BorderStyle), value)) throw new InvalidEnumArgumentException("value", (int)value, typeof(BorderStyle)); - borderStyle = value; + this.borderStyle = value; UpdateStyles(); OnBorderStyleChanged(EventArgs.Empty); } @@ -4028,11 +3989,11 @@ public bool BufferedDraw { get { - return (DirectMessage(NativeMethods.SCI_GETBUFFEREDDRAW) != IntPtr.Zero); + return DirectMessage(NativeMethods.SCI_GETBUFFEREDDRAW) != IntPtr.Zero; } set { - var isBuffered = (value ? new IntPtr(1) : IntPtr.Zero); + IntPtr isBuffered = value ? new IntPtr(1) : IntPtr.Zero; DirectMessage(NativeMethods.SCI_SETBUFFEREDDRAW, isBuffered); } } @@ -4088,7 +4049,7 @@ public bool CanPaste { get { - return (DirectMessage(NativeMethods.SCI_CANPASTE) != IntPtr.Zero); + return DirectMessage(NativeMethods.SCI_CANPASTE) != IntPtr.Zero; } } @@ -4102,7 +4063,7 @@ public bool CanRedo { get { - return (DirectMessage(NativeMethods.SCI_CANREDO) != IntPtr.Zero); + return DirectMessage(NativeMethods.SCI_CANREDO) != IntPtr.Zero; } } @@ -4116,7 +4077,7 @@ public bool CanUndo { get { - return (DirectMessage(NativeMethods.SCI_CANUNDO) != IntPtr.Zero); + return DirectMessage(NativeMethods.SCI_CANUNDO) != IntPtr.Zero; } } @@ -4226,7 +4187,7 @@ public bool CaretLineVisible } set { - var visible = (value ? new IntPtr(1) : IntPtr.Zero); + IntPtr visible = value ? new IntPtr(1) : IntPtr.Zero; DirectMessage(NativeMethods.SCI_SETCARETLINEVISIBLE, visible); } } @@ -4242,11 +4203,11 @@ public bool CaretLineVisibleAlways { get { - return (DirectMessage(NativeMethods.SCI_GETCARETLINEVISIBLEALWAYS) != IntPtr.Zero); + return DirectMessage(NativeMethods.SCI_GETCARETLINEVISIBLEALWAYS) != IntPtr.Zero; } set { - var visibleAlways = (value ? new IntPtr(1) : IntPtr.Zero); + IntPtr visibleAlways = value ? new IntPtr(1) : IntPtr.Zero; DirectMessage(NativeMethods.SCI_SETCARETLINEVISIBLEALWAYS, visibleAlways); } } @@ -4309,7 +4270,7 @@ public CaretStyle CaretStyle } set { - var style = (int)value; + int style = (int)value; DirectMessage(NativeMethods.SCI_SETCARETSTYLE, new IntPtr(style)); } } @@ -4374,26 +4335,26 @@ protected override CreateParams CreateParams if (moduleHandle == IntPtr.Zero) { - var message = string.Format(CultureInfo.InvariantCulture, "Could not load the Scintilla module at the path '{0}'.", modulePathScintilla); + string message = string.Format(CultureInfo.InvariantCulture, "Could not load the Scintilla module at the path '{0}'.", modulePathScintilla); throw new Win32Exception(message, new Win32Exception()); // Calls GetLastError } // For some reason the 32-bit DLL has weird export names. - var is32Bit = IntPtr.Size == 4; + bool is32Bit = IntPtr.Size == 4; // Self-compiled DLLs required this: //var exportName = is32Bit // ? "_Scintilla_DirectFunction@16" // : nameof(NativeMethods.Scintilla_DirectFunction); - + // Native DLL: - var exportName = nameof(NativeMethods.Scintilla_DirectFunction); + string exportName = nameof(NativeMethods.Scintilla_DirectFunction); // Get the native Scintilla direct function -- the only function the library exports - var directFunctionPointer = NativeMethods.GetProcAddress(new HandleRef(this, moduleHandle), exportName); + IntPtr directFunctionPointer = NativeMethods.GetProcAddress(new HandleRef(this, moduleHandle), exportName); if (directFunctionPointer == IntPtr.Zero) { - var message = "The Scintilla module has no export for the 'Scintilla_DirectFunction' procedure."; + string message = "The Scintilla module has no export for the 'Scintilla_DirectFunction' procedure."; throw new Win32Exception(message, new Win32Exception()); // Calls GetLastError } @@ -4410,9 +4371,9 @@ protected override CreateParams CreateParams cp.ClassName = "Scintilla"; // The border effect is achieved through a native Windows style - cp.ExStyle &= (~NativeMethods.WS_EX_CLIENTEDGE); - cp.Style &= (~NativeMethods.WS_BORDER); - switch (borderStyle) + cp.ExStyle &= ~NativeMethods.WS_EX_CLIENTEDGE; + cp.Style &= ~NativeMethods.WS_BORDER; + switch (this.borderStyle) { case BorderStyle.Fixed3D: case BorderStyle.Fixed3DVisualStyles: @@ -4437,8 +4398,8 @@ public int CurrentLine { get { - var currentPos = DirectMessage(NativeMethods.SCI_GETCURRENTPOS).ToInt32(); - var line = DirectMessage(NativeMethods.SCI_LINEFROMPOSITION, new IntPtr(currentPos)).ToInt32(); + int currentPos = DirectMessage(NativeMethods.SCI_GETCURRENTPOS).ToInt32(); + int line = DirectMessage(NativeMethods.SCI_LINEFROMPOSITION, new IntPtr(currentPos)).ToInt32(); return line; } } @@ -4458,13 +4419,13 @@ public int CurrentPosition { get { - var bytePos = DirectMessage(NativeMethods.SCI_GETCURRENTPOS).ToInt32(); + int bytePos = DirectMessage(NativeMethods.SCI_GETCURRENTPOS).ToInt32(); return Lines.ByteToCharPosition(bytePos); } set { value = Helpers.Clamp(value, 0, TextLength); - var bytePos = Lines.CharToBytePosition(value); + int bytePos = Lines.CharToBytePosition(value); DirectMessage(NativeMethods.SCI_SETCURRENTPOS, new IntPtr(bytePos)); } } @@ -4545,17 +4506,17 @@ public Document Document { get { - var ptr = DirectMessage(NativeMethods.SCI_GETDOCPOINTER); + IntPtr ptr = DirectMessage(NativeMethods.SCI_GETDOCPOINTER); return new Document { Value = ptr }; } set { - var eolMode = EolMode; - var useTabs = UseTabs; - var tabWidth = TabWidth; - var indentWidth = IndentWidth; + Eol eolMode = EolMode; + bool useTabs = UseTabs; + int tabWidth = TabWidth; + int indentWidth = IndentWidth; - var ptr = value.Value; + IntPtr ptr = value.Value; DirectMessage(NativeMethods.SCI_SETDOCPOINTER, IntPtr.Zero, ptr); // Carry over properties to new document @@ -4578,12 +4539,12 @@ public Color EdgeColor { get { - var color = DirectMessage(NativeMethods.SCI_GETEDGECOLOUR).ToInt32(); + int color = DirectMessage(NativeMethods.SCI_GETEDGECOLOUR).ToInt32(); return HelperMethods.FromWin32Color(color); } set { - var color = HelperMethods.ToWin32Color(value); + int color = HelperMethods.ToWin32Color(value); DirectMessage(NativeMethods.SCI_SETEDGECOLOUR, new IntPtr(color)); } } @@ -4630,7 +4591,7 @@ public EdgeMode EdgeMode } set { - var edgeMode = (int)value; + int edgeMode = (int)value; DirectMessage(NativeMethods.SCI_SETEDGEMODE, new IntPtr(edgeMode)); } } @@ -4641,7 +4602,7 @@ internal Encoding Encoding { // Should always be UTF-8 unless someone has done an end run around us int codePage = (int)DirectMessage(NativeMethods.SCI_GETCODEPAGE); - return (codePage == 0 ? Encoding.Default : Encoding.GetEncoding(codePage)); + return codePage == 0 ? Encoding.Default : Encoding.GetEncoding(codePage); } } @@ -4656,11 +4617,11 @@ public bool EndAtLastLine { get { - return (DirectMessage(NativeMethods.SCI_GETENDATLASTLINE) != IntPtr.Zero); + return DirectMessage(NativeMethods.SCI_GETENDATLASTLINE) != IntPtr.Zero; } set { - var endAtLastLine = (value ? new IntPtr(1) : IntPtr.Zero); + IntPtr endAtLastLine = value ? new IntPtr(1) : IntPtr.Zero; DirectMessage(NativeMethods.SCI_SETENDATLASTLINE, endAtLastLine); } } @@ -4681,7 +4642,7 @@ public Eol EolMode } set { - var eolMode = (int)value; + int eolMode = (int)value; DirectMessage(NativeMethods.SCI_SETEOLMODE, new IntPtr(eolMode)); } } @@ -4750,7 +4711,7 @@ public int FirstVisibleLine /// The to apply to the text displayed by the control. The default is the value of the property. [Category("Appearance")] [Description("The font of the text displayed by the control.")] - public override Font Font + public override Font Font { get { @@ -4759,9 +4720,9 @@ public override Font Font return base.Font; } - var defaultFontStyle = Styles[Style.Default]; + Style defaultFontStyle = Styles[Style.Default]; - var fontStyle = defaultFontStyle.Bold ? FontStyle.Bold : FontStyle.Regular; + FontStyle fontStyle = defaultFontStyle.Bold ? FontStyle.Bold : FontStyle.Regular; if (defaultFontStyle.Italic) { @@ -4778,8 +4739,8 @@ public override Font Font set { - var defaultFontStyle = Styles[Style.Default]; - value = value ?? Parent?.Font ?? Control.DefaultFont; + Style defaultFontStyle = Styles[Style.Default]; + value ??= Parent?.Font ?? Control.DefaultFont; defaultFontStyle.Font = value.Name; defaultFontStyle.SizeF = value.Size; defaultFontStyle.Bold = value.Bold; @@ -4807,7 +4768,7 @@ public FontQuality FontQuality } set { - var fontQuality = (int)value; + int fontQuality = (int)value; DirectMessage(NativeMethods.SCI_SETFONTQUALITY, new IntPtr(fontQuality)); } } @@ -4860,11 +4821,11 @@ public bool HScrollBar { get { - return (DirectMessage(NativeMethods.SCI_GETHSCROLLBAR) != IntPtr.Zero); + return DirectMessage(NativeMethods.SCI_GETHSCROLLBAR) != IntPtr.Zero; } set { - var visible = (value ? new IntPtr(1) : IntPtr.Zero); + IntPtr visible = value ? new IntPtr(1) : IntPtr.Zero; DirectMessage(NativeMethods.SCI_SETHSCROLLBAR, visible); } } @@ -4887,7 +4848,7 @@ public IdleStyling IdleStyling } set { - var idleStyling = (int)value; + int idleStyling = (int)value; DirectMessage(NativeMethods.SCI_SETIDLESTYLING, new IntPtr(idleStyling)); } } @@ -4929,7 +4890,7 @@ public IndentView IndentationGuides } set { - var indentView = (int)value; + int indentView = (int)value; DirectMessage(NativeMethods.SCI_SETINDENTATIONGUIDES, new IntPtr(indentView)); } } @@ -4989,11 +4950,11 @@ public bool InternalFocusFlag { get { - return (DirectMessage(NativeMethods.SCI_GETFOCUS) != IntPtr.Zero); + return DirectMessage(NativeMethods.SCI_GETFOCUS) != IntPtr.Zero; } set { - var focus = (value ? new IntPtr(1) : IntPtr.Zero); + IntPtr focus = value ? new IntPtr(1) : IntPtr.Zero; DirectMessage(NativeMethods.SCI_SETFOCUS, focus); } } @@ -5008,13 +4969,13 @@ public bool InternalFocusFlag [Category("Lexing")] public string LexerName { - get => lexerName; + get => this.lexerName; set { if (string.IsNullOrWhiteSpace(value) && value != string.Empty) { - lexerName = value; + this.lexerName = value; return; } @@ -5024,7 +4985,7 @@ public string LexerName throw new InvalidOperationException(@$"Lexer with the name of '{value}' was not found."); } - lexerName = value; + this.lexerName = value; } } @@ -5039,11 +5000,11 @@ public unsafe string LexerLanguage { get { - var length = DirectMessage(NativeMethods.SCI_GETLEXERLANGUAGE).ToInt32(); + int length = DirectMessage(NativeMethods.SCI_GETLEXERLANGUAGE).ToInt32(); if (length == 0) return string.Empty; - var bytes = new byte[length + 1]; + byte[] bytes = new byte[length + 1]; fixed (byte* bp = bytes) { DirectMessage(NativeMethods.SCI_GETLEXERLANGUAGE, IntPtr.Zero, new IntPtr(bp)); @@ -5058,7 +5019,7 @@ public unsafe string LexerLanguage } else { - var bytes = Helpers.GetBytes(value, Encoding.ASCII, zeroTerminated: true); + byte[] bytes = Helpers.GetBytes(value, Encoding.ASCII, zeroTerminated: true); fixed (byte* bp = bytes) DirectMessage(NativeMethods.SCI_SETLEXERLANGUAGE, IntPtr.Zero, new IntPtr(bp)); } @@ -5101,7 +5062,7 @@ public LineEndType LineEndTypesAllowed } set { - var lineEndBitsSet = (int)value; + int lineEndBitsSet = (int)value; DirectMessage(NativeMethods.SCI_SETLINEENDTYPESALLOWED, new IntPtr(lineEndBitsSet)); } } @@ -5193,7 +5154,7 @@ public bool Modified { get { - return (DirectMessage(NativeMethods.SCI_GETMODIFY) != IntPtr.Zero); + return DirectMessage(NativeMethods.SCI_GETMODIFY) != IntPtr.Zero; } } @@ -5238,7 +5199,7 @@ public bool MouseSelectionRectangularSwitch } set { - var mouseSelectionRectangularSwitch = (value ? new IntPtr(1) : IntPtr.Zero); + IntPtr mouseSelectionRectangularSwitch = value ? new IntPtr(1) : IntPtr.Zero; DirectMessage(NativeMethods.SCI_SETMOUSESELECTIONRECTANGULARSWITCH, mouseSelectionRectangularSwitch); } } @@ -5290,7 +5251,7 @@ public bool MultipleSelection } set { - var multipleSelection = (value ? new IntPtr(1) : IntPtr.Zero); + IntPtr multipleSelection = value ? new IntPtr(1) : IntPtr.Zero; DirectMessage(NativeMethods.SCI_SETMULTIPLESELECTION, multipleSelection); } } @@ -5310,7 +5271,7 @@ public MultiPaste MultiPaste } set { - var multiPaste = (int)value; + int multiPaste = (int)value; DirectMessage(NativeMethods.SCI_SETMULTIPASTE, new IntPtr(multiPaste)); } } @@ -5326,11 +5287,11 @@ public bool Overtype { get { - return (DirectMessage(NativeMethods.SCI_GETOVERTYPE) != IntPtr.Zero); + return DirectMessage(NativeMethods.SCI_GETOVERTYPE) != IntPtr.Zero; } set { - var overtype = (value ? new IntPtr(1) : IntPtr.Zero); + IntPtr overtype = value ? new IntPtr(1) : IntPtr.Zero; DirectMessage(NativeMethods.SCI_SETOVERTYPE, overtype); } } @@ -5363,11 +5324,11 @@ public bool PasteConvertEndings { get { - return (DirectMessage(NativeMethods.SCI_GETPASTECONVERTENDINGS) != IntPtr.Zero); + return DirectMessage(NativeMethods.SCI_GETPASTECONVERTENDINGS) != IntPtr.Zero; } set { - var convert = (value ? new IntPtr(1) : IntPtr.Zero); + IntPtr convert = value ? new IntPtr(1) : IntPtr.Zero; DirectMessage(NativeMethods.SCI_SETPASTECONVERTENDINGS, convert); } } @@ -5387,7 +5348,7 @@ public Phases PhasesDraw } set { - var phases = (int)value; + int phases = (int)value; DirectMessage(NativeMethods.SCI_SETPHASESDRAW, new IntPtr(phases)); } } @@ -5404,11 +5365,11 @@ public bool ReadOnly { get { - return (DirectMessage(NativeMethods.SCI_GETREADONLY) != IntPtr.Zero); + return DirectMessage(NativeMethods.SCI_GETREADONLY) != IntPtr.Zero; } set { - var readOnly = (value ? new IntPtr(1) : IntPtr.Zero); + IntPtr readOnly = value ? new IntPtr(1) : IntPtr.Zero; DirectMessage(NativeMethods.SCI_SETREADONLY, readOnly); } } @@ -5423,7 +5384,7 @@ public int RectangularSelectionAnchor { get { - var pos = DirectMessage(NativeMethods.SCI_GETRECTANGULARSELECTIONANCHOR).ToInt32(); + int pos = DirectMessage(NativeMethods.SCI_GETRECTANGULARSELECTIONANCHOR).ToInt32(); if (pos <= 0) return pos; @@ -5466,7 +5427,7 @@ public int RectangularSelectionCaret { get { - var pos = DirectMessage(NativeMethods.SCI_GETRECTANGULARSELECTIONCARET).ToInt32(); + int pos = DirectMessage(NativeMethods.SCI_GETRECTANGULARSELECTIONCARET).ToInt32(); if (pos <= 0) return 0; @@ -5510,14 +5471,14 @@ private IntPtr SciPointer throw new InvalidOperationException(message); } - if (sciPtr == IntPtr.Zero) + if (this.sciPtr == IntPtr.Zero) { // Get a pointer to the native Scintilla object (i.e. C++ 'this') to use with the // direct function. This will happen for each Scintilla control instance. - sciPtr = NativeMethods.SendMessage(new HandleRef(this, Handle), NativeMethods.SCI_GETDIRECTPOINTER, IntPtr.Zero, IntPtr.Zero); + this.sciPtr = NativeMethods.SendMessage(new HandleRef(this, Handle), NativeMethods.SCI_GETDIRECTPOINTER, IntPtr.Zero, IntPtr.Zero); } - return sciPtr; + return this.sciPtr; } } @@ -5555,11 +5516,11 @@ public bool ScrollWidthTracking { get { - return (DirectMessage(NativeMethods.SCI_GETSCROLLWIDTHTRACKING) != IntPtr.Zero); + return DirectMessage(NativeMethods.SCI_GETSCROLLWIDTHTRACKING) != IntPtr.Zero; } set { - var tracking = (value ? new IntPtr(1) : IntPtr.Zero); + IntPtr tracking = value ? new IntPtr(1) : IntPtr.Zero; DirectMessage(NativeMethods.SCI_SETSCROLLWIDTHTRACKING, tracking); } } @@ -5579,7 +5540,7 @@ public SearchFlags SearchFlags } set { - var searchFlags = (int)value; + int searchFlags = (int)value; DirectMessage(NativeMethods.SCI_SETSEARCHFLAGS, new IntPtr(searchFlags)); } } @@ -5595,12 +5556,12 @@ public unsafe string SelectedText get { // NOTE: For some reason the length returned by this API includes the terminating NULL - var length = DirectMessage(NativeMethods.SCI_GETSELTEXT).ToInt32(); + int length = DirectMessage(NativeMethods.SCI_GETSELTEXT).ToInt32(); if (length <= 0) return string.Empty; - var bytes = new byte[length + 1]; + byte[] bytes = new byte[length + 1]; fixed (byte* bp = bytes) { DirectMessage(NativeMethods.SCI_GETSELTEXT, IntPtr.Zero, new IntPtr(bp)); @@ -5625,7 +5586,7 @@ public int SelectionEnd { get { - var pos = DirectMessage(NativeMethods.SCI_GETSELECTIONEND).ToInt32(); + int pos = DirectMessage(NativeMethods.SCI_GETSELECTIONEND).ToInt32(); return Lines.ByteToCharPosition(pos); } set @@ -5647,11 +5608,11 @@ public bool SelectionEolFilled { get { - return (DirectMessage(NativeMethods.SCI_GETSELEOLFILLED) != IntPtr.Zero); + return DirectMessage(NativeMethods.SCI_GETSELEOLFILLED) != IntPtr.Zero; } set { - var eolFilled = (value ? new IntPtr(1) : IntPtr.Zero); + IntPtr eolFilled = value ? new IntPtr(1) : IntPtr.Zero; DirectMessage(NativeMethods.SCI_SETSELEOLFILLED, eolFilled); } } @@ -6000,7 +5961,7 @@ public int SelectionStart { get { - var pos = DirectMessage(NativeMethods.SCI_GETSELECTIONSTART).ToInt32(); + int pos = DirectMessage(NativeMethods.SCI_GETSELECTIONSTART).ToInt32(); return Lines.ByteToCharPosition(pos); } set @@ -6029,7 +5990,7 @@ public Status Status } set { - var status = (int)value; + int status = (int)value; DirectMessage(NativeMethods.SCI_SETSTATUS, new IntPtr(status)); } } @@ -6061,7 +6022,7 @@ public TabDrawMode TabDrawMode } set { - var tabDrawMode = (int)value; + int tabDrawMode = (int)value; DirectMessage(NativeMethods.SCI_SETTABDRAWMODE, new IntPtr(tabDrawMode)); } } @@ -6077,11 +6038,11 @@ public bool TabIndents { get { - return (DirectMessage(NativeMethods.SCI_GETTABINDENTS) != IntPtr.Zero); + return DirectMessage(NativeMethods.SCI_GETTABINDENTS) != IntPtr.Zero; } set { - var ptr = (value ? new IntPtr(1) : IntPtr.Zero); + IntPtr ptr = value ? new IntPtr(1) : IntPtr.Zero; DirectMessage(NativeMethods.SCI_SETTABINDENTS, ptr); } } @@ -6119,7 +6080,7 @@ public int TargetEnd get { // The position can become stale and point to a place outside of the document so we must clamp it - var bytePos = Helpers.Clamp(DirectMessage(NativeMethods.SCI_GETTARGETEND).ToInt32(), 0, DirectMessage(NativeMethods.SCI_GETTEXTLENGTH).ToInt32()); + int bytePos = Helpers.Clamp(DirectMessage(NativeMethods.SCI_GETTARGETEND).ToInt32(), 0, DirectMessage(NativeMethods.SCI_GETTEXTLENGTH).ToInt32()); return Lines.ByteToCharPosition(bytePos); } set @@ -6144,7 +6105,7 @@ public int TargetStart get { // The position can become stale and point to a place outside of the document so we must clamp it - var bytePos = Helpers.Clamp(DirectMessage(NativeMethods.SCI_GETTARGETSTART).ToInt32(), 0, DirectMessage(NativeMethods.SCI_GETTEXTLENGTH).ToInt32()); + int bytePos = Helpers.Clamp(DirectMessage(NativeMethods.SCI_GETTARGETSTART).ToInt32(), 0, DirectMessage(NativeMethods.SCI_GETTEXTLENGTH).ToInt32()); return Lines.ByteToCharPosition(bytePos); } set @@ -6168,11 +6129,11 @@ public unsafe string TargetText { get { - var length = DirectMessage(NativeMethods.SCI_GETTARGETTEXT).ToInt32(); + int length = DirectMessage(NativeMethods.SCI_GETTARGETTEXT).ToInt32(); if (length == 0) return string.Empty; - var bytes = new byte[length + 1]; + byte[] bytes = new byte[length + 1]; fixed (byte* bp = bytes) { DirectMessage(NativeMethods.SCI_GETTARGETTEXT, IntPtr.Zero, new IntPtr(bp)); @@ -6191,18 +6152,18 @@ public unsafe string TargetText [DefaultValue(Technology.Default)] [Category("Misc")] [Description("The rendering technology used to draw text.")] - public Technology Technology - { - get - { - return (Technology)DirectMessage(NativeMethods.SCI_GETTECHNOLOGY); - } - set + public Technology Technology { - var technology = (int)value; - DirectMessage(NativeMethods.SCI_SETTECHNOLOGY, new IntPtr(technology)); + get + { + return (Technology)DirectMessage(NativeMethods.SCI_GETTECHNOLOGY); + } + set + { + int technology = (int)value; + DirectMessage(NativeMethods.SCI_SETTECHNOLOGY, new IntPtr(technology)); + } } - } /// /// Gets or sets the current document text in the control. @@ -6216,8 +6177,8 @@ public override unsafe string Text { get { - var length = DirectMessage(NativeMethods.SCI_GETTEXTLENGTH).ToInt32(); - var ptr = DirectMessage(NativeMethods.SCI_GETRANGEPOINTER, new IntPtr(0), new IntPtr(length)); + int length = DirectMessage(NativeMethods.SCI_GETTEXTLENGTH).ToInt32(); + IntPtr ptr = DirectMessage(NativeMethods.SCI_GETRANGEPOINTER, new IntPtr(0), new IntPtr(length)); if (ptr == IntPtr.Zero) { return string.Empty; @@ -6225,12 +6186,12 @@ public override unsafe string Text // Assumption is that moving the gap will always be equal to or less expensive // than using one of the APIs which requires an intermediate buffer. - var text = new string((sbyte*)ptr, 0, length, Encoding); + string text = new((sbyte*)ptr, 0, length, Encoding); return text; } set { - var previousReadOnly = DesignMode ? ReadOnly : false; + bool previousReadOnly = DesignMode && ReadOnly; // Allow Text property change in read-only mode when the designer is active. if (previousReadOnly && DesignMode) @@ -6249,7 +6210,7 @@ public override unsafe string Text } else { - fixed (byte* bp = Helpers.GetBytes(value, Encoding, zeroTerminated: true)) + fixed (byte* bp = Helpers.GetBytes(value, Encoding, zeroTerminated: true)) DirectMessage(NativeMethods.SCI_SETTEXT, IntPtr.Zero, new IntPtr(bp)); } @@ -6280,11 +6241,11 @@ public bool UseTabs { get { - return (DirectMessage(NativeMethods.SCI_GETUSETABS) != IntPtr.Zero); + return DirectMessage(NativeMethods.SCI_GETUSETABS) != IntPtr.Zero; } set { - var useTabs = (value ? new IntPtr(1) : IntPtr.Zero); + IntPtr useTabs = value ? new IntPtr(1) : IntPtr.Zero; DirectMessage(NativeMethods.SCI_SETUSETABS, useTabs); } } @@ -6302,7 +6263,7 @@ public bool UseTabs set { base.UseWaitCursor = value; - var cursor = (value ? NativeMethods.SC_CURSORWAIT : NativeMethods.SC_CURSORNORMAL); + int cursor = value ? NativeMethods.SC_CURSORWAIT : NativeMethods.SC_CURSORNORMAL; DirectMessage(NativeMethods.SCI_SETCURSOR, new IntPtr(cursor)); } } @@ -6322,7 +6283,7 @@ public bool ViewEol } set { - var visible = (value ? new IntPtr(1) : IntPtr.Zero); + IntPtr visible = value ? new IntPtr(1) : IntPtr.Zero; DirectMessage(NativeMethods.SCI_SETVIEWEOL, visible); } } @@ -6344,7 +6305,7 @@ public WhitespaceMode ViewWhitespace } set { - var wsMode = (int)value; + int wsMode = (int)value; DirectMessage(NativeMethods.SCI_SETVIEWWS, new IntPtr(wsMode)); } } @@ -6369,7 +6330,7 @@ public VirtualSpace VirtualSpaceOptions } set { - var virtualSpace = (int)value; + int virtualSpace = (int)value; DirectMessage(NativeMethods.SCI_SETVIRTUALSPACEOPTIONS, new IntPtr(virtualSpace)); } } @@ -6385,11 +6346,11 @@ public bool VScrollBar { get { - return (DirectMessage(NativeMethods.SCI_GETVSCROLLBAR) != IntPtr.Zero); + return DirectMessage(NativeMethods.SCI_GETVSCROLLBAR) != IntPtr.Zero; } set { - var visible = (value ? new IntPtr(1) : IntPtr.Zero); + IntPtr visible = value ? new IntPtr(1) : IntPtr.Zero; DirectMessage(NativeMethods.SCI_SETVSCROLLBAR, visible); } } @@ -6409,9 +6370,9 @@ private int VisibleLineCount int count = 0; for (int i = 0; i < Lines.Count; i++) { - if (allLinesVisible || this.Lines[i].Visible) + if (allLinesVisible || Lines[i].Visible) { - count += wordWrapDisabled ? 1 : this.Lines[i].WrapCount; + count += wordWrapDisabled ? 1 : Lines[i].WrapCount; } } @@ -6430,8 +6391,8 @@ public unsafe string WhitespaceChars { get { - var length = DirectMessage(NativeMethods.SCI_GETWHITESPACECHARS, IntPtr.Zero, IntPtr.Zero).ToInt32(); - var bytes = new byte[length + 1]; + int length = DirectMessage(NativeMethods.SCI_GETWHITESPACECHARS, IntPtr.Zero, IntPtr.Zero).ToInt32(); + byte[] bytes = new byte[length + 1]; fixed (byte* bp = bytes) { DirectMessage(NativeMethods.SCI_GETWHITESPACECHARS, IntPtr.Zero, new IntPtr(bp)); @@ -6448,7 +6409,7 @@ public unsafe string WhitespaceChars // Scintilla stores each of the characters specified in a char array which it then // uses as a lookup for word matching logic. Thus, any multibyte chars wouldn't work. - var bytes = Helpers.GetBytes(value, Encoding.ASCII, zeroTerminated: true); + byte[] bytes = Helpers.GetBytes(value, Encoding.ASCII, zeroTerminated: true); fixed (byte* bp = bytes) DirectMessage(NativeMethods.SCI_SETWHITESPACECHARS, IntPtr.Zero, new IntPtr(bp)); } @@ -6484,8 +6445,8 @@ public unsafe string WordChars { get { - var length = DirectMessage(NativeMethods.SCI_GETWORDCHARS, IntPtr.Zero, IntPtr.Zero).ToInt32(); - var bytes = new byte[length + 1]; + int length = DirectMessage(NativeMethods.SCI_GETWORDCHARS, IntPtr.Zero, IntPtr.Zero).ToInt32(); + byte[] bytes = new byte[length + 1]; fixed (byte* bp = bytes) { DirectMessage(NativeMethods.SCI_GETWORDCHARS, IntPtr.Zero, new IntPtr(bp)); @@ -6502,7 +6463,7 @@ public unsafe string WordChars // Scintilla stores each of the characters specified in a char array which it then // uses as a lookup for word matching logic. Thus, any multibyte chars wouldn't work. - var bytes = Helpers.GetBytes(value, Encoding.ASCII, zeroTerminated: true); + byte[] bytes = Helpers.GetBytes(value, Encoding.ASCII, zeroTerminated: true); fixed (byte* bp = bytes) DirectMessage(NativeMethods.SCI_SETWORDCHARS, IntPtr.Zero, new IntPtr(bp)); } @@ -6526,7 +6487,7 @@ public WrapIndentMode WrapIndentMode } set { - var wrapIndentMode = (int)value; + int wrapIndentMode = (int)value; DirectMessage(NativeMethods.SCI_SETWRAPINDENTMODE, new IntPtr(wrapIndentMode)); } } @@ -6549,7 +6510,7 @@ public WrapMode WrapMode } set { - var wrapMode = (int)value; + int wrapMode = (int)value; DirectMessage(NativeMethods.SCI_SETWRAPMODE, new IntPtr(wrapMode)); } } @@ -6621,7 +6582,7 @@ public WrapVisualFlagLocation WrapVisualFlagLocation } set { - var location = (int)value; + int location = (int)value; DirectMessage(NativeMethods.SCI_SETWRAPVISUALFLAGSLOCATION, new IntPtr(location)); } } @@ -6978,7 +6939,6 @@ public event EventHandler CallTipClick } } - /// /// Occurs when the mouse is kept in one position (hovers) for the . /// @@ -7167,7 +7127,6 @@ public event EventHandler MarginClick } } - // TODO This isn't working in my tests. Could be Windows Forms interfering. /// /// Occurs when the mouse was right-clicked inside a margin that was marked as sensitive. @@ -7378,7 +7337,7 @@ public Scintilla() { // WM_DESTROY workaround if (Scintilla.reparentAll == null || (bool)Scintilla.reparentAll) - reparent = true; + this.reparent = true; // We don't want .NET to use GetWindowText because we manage ('cache') our own text base.SetStyle(ControlStyles.CacheText, true); diff --git a/Scintilla.NET/ScintillaReader.cs b/Scintilla.NET/ScintillaReader.cs index 2388fc9..4014835 100644 --- a/Scintilla.NET/ScintillaReader.cs +++ b/Scintilla.NET/ScintillaReader.cs @@ -6,38 +6,40 @@ namespace ScintillaNET; /// /// Implements a TextReader that reads from a Scintilla control. /// -public class ScintillaReader : TextReader { +public class ScintillaReader : TextReader +{ /// /// Arbitrarily chosen default buffer size /// - const int DefaultBufferSize = 256; + private const int DefaultBufferSize = 256; /// /// Returns the number of buffered characters left to be read. /// - private int BufferRemaining => _data != null ? _data.Length - _dataIndex : 0; + private int BufferRemaining => this._data != null ? this._data.Length - this._dataIndex : 0; /// /// Returns the number of unbuffered characters left to be read. /// - private int UnbufferedRemaining => _lastData - _nextData; + private int UnbufferedRemaining => this._lastData - this._nextData; /// /// Returns the total number of characters left to be read. /// private int TotalRemaining => BufferRemaining + UnbufferedRemaining; - private Scintilla _scintilla; - private int _bufferSize; + private readonly Scintilla _scintilla; + private readonly int _bufferSize; private string _data; private int _dataIndex; private int _nextData; - private int _lastData; + private readonly int _lastData; /// /// Initializes a new instance of the ScintillaReader class that reads all text from the specified Scintilla control. /// /// The Scintilla control from which to read. public ScintillaReader(Scintilla scintilla) - : this(scintilla, 0, scintilla.TextLength) { + : this(scintilla, 0, scintilla.TextLength) + { } /// /// Initializes a new instance of the ScintillaReader class that reads all text from the specified Scintilla control. @@ -45,7 +47,8 @@ public ScintillaReader(Scintilla scintilla) /// The Scintilla control from which to read. /// The number of characters to buffer at a time. public ScintillaReader(Scintilla scintilla, int bufferSize) - : this(scintilla, 0, scintilla.TextLength, bufferSize) { + : this(scintilla, 0, scintilla.TextLength, bufferSize) + { } /// /// Initializes a new instance of the ScintillaReader class that reads a subsection from the specified Scintilla control. @@ -54,7 +57,8 @@ public ScintillaReader(Scintilla scintilla, int bufferSize) /// The index of the first character to read. /// The index just past the last character to read. public ScintillaReader(Scintilla scintilla, int start, int end) - : this(scintilla, start, end, DefaultBufferSize) { + : this(scintilla, start, end, DefaultBufferSize) + { } /// /// Initializes a new instance of the ScintillaReader class that reads a subsection from the specified Scintilla control. @@ -63,11 +67,12 @@ public ScintillaReader(Scintilla scintilla, int start, int end) /// The index of the first character to read. /// The index just past the last character to read. /// The number of characters to buffer at a time. - public ScintillaReader(Scintilla scintilla, int start, int end, int bufferSize) { - _scintilla = scintilla; - _bufferSize = bufferSize > 0 ? bufferSize : DefaultBufferSize; - _nextData = start; - _lastData = end; + public ScintillaReader(Scintilla scintilla, int start, int end, int bufferSize) + { + this._scintilla = scintilla; + this._bufferSize = bufferSize > 0 ? bufferSize : DefaultBufferSize; + this._nextData = start; + this._lastData = end; // ensure start state is valid BufferNextRegion(); } @@ -76,24 +81,31 @@ public ScintillaReader(Scintilla scintilla, int start, int end, int bufferSize) /// Returns the next character to be read from the reader without actually removing it from the stream. Returns -1 if no characters are available. /// /// The next character from the input stream, or -1 if no more characters are available. - public override int Peek() { + public override int Peek() + { // _data is set to null upon EOF - return _data != null ? _data[_dataIndex] : -1; + return this._data != null ? this._data[this._dataIndex] : -1; } /// /// Removes a character from the stream and returns it. Returns -1 if no characters are available. /// /// The next character from the input stream, or -1 if no more characters are available. - public override int Read() { - if (_data != null) { + public override int Read() + { + if (this._data != null) + { // EOF not reached - var n = _data[_dataIndex++]; - if (_dataIndex >= _data.Length) { + char n = this._data[this._dataIndex++]; + if (this._dataIndex >= this._data.Length) + { // end of buffer reached; load next section BufferNextRegion(); } + return n; - } else { + } + else + { return -1; } } @@ -107,7 +119,8 @@ public override int Read() { /// buffer is null. /// The buffer length minus index is less than count. /// index or count is negative. - public override int Read(char[] buffer, int index, int count) { + public override int Read(char[] buffer, int index, int count) + { return ReadBlock(buffer, index, count); } @@ -121,30 +134,38 @@ public override int Read(char[] buffer, int index, int count) { /// buffer is null. /// The buffer length minus index is less than count. /// index or count is negative. - public override int ReadBlock(char[] buffer, int index, int count) { - if (_data != null) { - var bufferRemaining = BufferRemaining; - if (count < bufferRemaining) { + public override int ReadBlock(char[] buffer, int index, int count) + { + if (this._data != null) + { + int bufferRemaining = BufferRemaining; + if (count < bufferRemaining) + { // buffer larger than read size - _data.CopyTo(_dataIndex, buffer, index, count); + this._data.CopyTo(this._dataIndex, buffer, index, count); return count; - } else { + } + else + { // buffer smaller or equal to read size - _data.CopyTo(_dataIndex, buffer, index, bufferRemaining); - if (count > bufferRemaining) { + this._data.CopyTo(this._dataIndex, buffer, index, bufferRemaining); + if (count > bufferRemaining) + { // buffer is smaller; read rest - var rest = _scintilla.GetTextRange( - _nextData, + string rest = this._scintilla.GetTextRange( + this._nextData, Math.Min(count - bufferRemaining, UnbufferedRemaining)); rest.CopyTo(0, buffer, index + bufferRemaining, rest.Length); count = bufferRemaining + rest.Length; - _nextData += rest.Length; + this._nextData += rest.Length; } // read at least up to buffer's end; refill buffer BufferNextRegion(); return count; } - } else { + } + else + { return 0; } } @@ -152,14 +173,18 @@ public override int ReadBlock(char[] buffer, int index, int count) { /// /// Fills the buffer with the next section of text. /// - private void BufferNextRegion() { - if (_nextData < _lastData) { - var size = Math.Min(_lastData - _nextData, _bufferSize); - _data = _scintilla.GetTextRange(_nextData, size); - _nextData += _data.Length; - _dataIndex = 0; - } else { - _data = null; + private void BufferNextRegion() + { + if (this._nextData < this._lastData) + { + int size = Math.Min(this._lastData - this._nextData, this._bufferSize); + this._data = this._scintilla.GetTextRange(this._nextData, size); + this._nextData += this._data.Length; + this._dataIndex = 0; + } + else + { + this._data = null; } } } \ No newline at end of file diff --git a/Scintilla.NET/Selection.cs b/Scintilla.NET/Selection.cs index 7c4bfc1..f287eda 100644 --- a/Scintilla.NET/Selection.cs +++ b/Scintilla.NET/Selection.cs @@ -17,17 +17,17 @@ public int Anchor { get { - var pos = scintilla.DirectMessage(NativeMethods.SCI_GETSELECTIONNANCHOR, new IntPtr(Index)).ToInt32(); + int pos = this.scintilla.DirectMessage(NativeMethods.SCI_GETSELECTIONNANCHOR, new IntPtr(Index)).ToInt32(); if (pos <= 0) return pos; - return scintilla.Lines.ByteToCharPosition(pos); + return this.scintilla.Lines.ByteToCharPosition(pos); } set { - value = Helpers.Clamp(value, 0, scintilla.TextLength); - value = scintilla.Lines.CharToBytePosition(value); - scintilla.DirectMessage(NativeMethods.SCI_SETSELECTIONNANCHOR, new IntPtr(Index), new IntPtr(value)); + value = Helpers.Clamp(value, 0, this.scintilla.TextLength); + value = this.scintilla.Lines.CharToBytePosition(value); + this.scintilla.DirectMessage(NativeMethods.SCI_SETSELECTIONNANCHOR, new IntPtr(Index), new IntPtr(value)); } } @@ -39,12 +39,12 @@ public int AnchorVirtualSpace { get { - return scintilla.DirectMessage(NativeMethods.SCI_GETSELECTIONNANCHORVIRTUALSPACE, new IntPtr(Index)).ToInt32(); + return this.scintilla.DirectMessage(NativeMethods.SCI_GETSELECTIONNANCHORVIRTUALSPACE, new IntPtr(Index)).ToInt32(); } set { value = Helpers.ClampMin(value, 0); - scintilla.DirectMessage(NativeMethods.SCI_SETSELECTIONNANCHORVIRTUALSPACE, new IntPtr(Index), new IntPtr(value)); + this.scintilla.DirectMessage(NativeMethods.SCI_SETSELECTIONNANCHORVIRTUALSPACE, new IntPtr(Index), new IntPtr(value)); } } @@ -56,17 +56,17 @@ public int Caret { get { - var pos = scintilla.DirectMessage(NativeMethods.SCI_GETSELECTIONNCARET, new IntPtr(Index)).ToInt32(); + int pos = this.scintilla.DirectMessage(NativeMethods.SCI_GETSELECTIONNCARET, new IntPtr(Index)).ToInt32(); if (pos <= 0) return pos; - return scintilla.Lines.ByteToCharPosition(pos); + return this.scintilla.Lines.ByteToCharPosition(pos); } set { - value = Helpers.Clamp(value, 0, scintilla.TextLength); - value = scintilla.Lines.CharToBytePosition(value); - scintilla.DirectMessage(NativeMethods.SCI_SETSELECTIONNCARET, new IntPtr(Index), new IntPtr(value)); + value = Helpers.Clamp(value, 0, this.scintilla.TextLength); + value = this.scintilla.Lines.CharToBytePosition(value); + this.scintilla.DirectMessage(NativeMethods.SCI_SETSELECTIONNCARET, new IntPtr(Index), new IntPtr(value)); } } @@ -78,12 +78,12 @@ public int CaretVirtualSpace { get { - return scintilla.DirectMessage(NativeMethods.SCI_GETSELECTIONNCARETVIRTUALSPACE, new IntPtr(Index)).ToInt32(); + return this.scintilla.DirectMessage(NativeMethods.SCI_GETSELECTIONNCARETVIRTUALSPACE, new IntPtr(Index)).ToInt32(); } set { value = Helpers.ClampMin(value, 0); - scintilla.DirectMessage(NativeMethods.SCI_SETSELECTIONNCARETVIRTUALSPACE, new IntPtr(Index), new IntPtr(value)); + this.scintilla.DirectMessage(NativeMethods.SCI_SETSELECTIONNCARETVIRTUALSPACE, new IntPtr(Index), new IntPtr(value)); } } @@ -95,17 +95,17 @@ public int End { get { - var pos = scintilla.DirectMessage(NativeMethods.SCI_GETSELECTIONNEND, new IntPtr(Index)).ToInt32(); + int pos = this.scintilla.DirectMessage(NativeMethods.SCI_GETSELECTIONNEND, new IntPtr(Index)).ToInt32(); if (pos <= 0) return pos; - return scintilla.Lines.ByteToCharPosition(pos); + return this.scintilla.Lines.ByteToCharPosition(pos); } set { - value = Helpers.Clamp(value, 0, scintilla.TextLength); - value = scintilla.Lines.CharToBytePosition(value); - scintilla.DirectMessage(NativeMethods.SCI_SETSELECTIONNEND, new IntPtr(Index), new IntPtr(value)); + value = Helpers.Clamp(value, 0, this.scintilla.TextLength); + value = this.scintilla.Lines.CharToBytePosition(value); + this.scintilla.DirectMessage(NativeMethods.SCI_SETSELECTIONNEND, new IntPtr(Index), new IntPtr(value)); } } @@ -123,17 +123,17 @@ public int Start { get { - var pos = scintilla.DirectMessage(NativeMethods.SCI_GETSELECTIONNSTART, new IntPtr(Index)).ToInt32(); + int pos = this.scintilla.DirectMessage(NativeMethods.SCI_GETSELECTIONNSTART, new IntPtr(Index)).ToInt32(); if (pos <= 0) return pos; - return scintilla.Lines.ByteToCharPosition(pos); + return this.scintilla.Lines.ByteToCharPosition(pos); } set { - value = Helpers.Clamp(value, 0, scintilla.TextLength); - value = scintilla.Lines.CharToBytePosition(value); - scintilla.DirectMessage(NativeMethods.SCI_SETSELECTIONNSTART, new IntPtr(Index), new IntPtr(value)); + value = Helpers.Clamp(value, 0, this.scintilla.TextLength); + value = this.scintilla.Lines.CharToBytePosition(value); + this.scintilla.DirectMessage(NativeMethods.SCI_SETSELECTIONNSTART, new IntPtr(Index), new IntPtr(value)); } } diff --git a/Scintilla.NET/SelectionCollection.cs b/Scintilla.NET/SelectionCollection.cs index 20f745f..9370f8f 100644 --- a/Scintilla.NET/SelectionCollection.cs +++ b/Scintilla.NET/SelectionCollection.cs @@ -26,7 +26,7 @@ public IEnumerator GetEnumerator() IEnumerator IEnumerable.GetEnumerator() { - return this.GetEnumerator(); + return GetEnumerator(); } /// @@ -37,7 +37,7 @@ public int Count { get { - return scintilla.DirectMessage(NativeMethods.SCI_GETSELECTIONS).ToInt32(); + return this.scintilla.DirectMessage(NativeMethods.SCI_GETSELECTIONS).ToInt32(); } } @@ -49,7 +49,7 @@ public bool IsEmpty { get { - return scintilla.DirectMessage(NativeMethods.SCI_GETSELECTIONEMPTY) != IntPtr.Zero; + return this.scintilla.DirectMessage(NativeMethods.SCI_GETSELECTIONEMPTY) != IntPtr.Zero; } } @@ -63,7 +63,7 @@ public Selection this[int index] get { index = Helpers.Clamp(index, 0, Count - 1); - return new Selection(scintilla, index); + return new Selection(this.scintilla, index); } } diff --git a/Scintilla.NET/Style.cs b/Scintilla.NET/Style.cs index cc92e64..64ad2f3 100644 --- a/Scintilla.NET/Style.cs +++ b/Scintilla.NET/Style.cs @@ -97,7 +97,7 @@ public Color BackColor { get { - var color = scintilla.DirectMessage(NativeMethods.SCI_STYLEGETBACK, new IntPtr(Index), IntPtr.Zero).ToInt32(); + int color = this.scintilla.DirectMessage(NativeMethods.SCI_STYLEGETBACK, new IntPtr(Index), IntPtr.Zero).ToInt32(); return HelperMethods.FromWin32Color(color); } set @@ -105,8 +105,8 @@ public Color BackColor if (value.IsEmpty) value = Color.White; - var color = HelperMethods.ToWin32Color(value); - scintilla.DirectMessage(NativeMethods.SCI_STYLESETBACK, new IntPtr(Index), new IntPtr(color)); + int color = HelperMethods.ToWin32Color(value); + this.scintilla.DirectMessage(NativeMethods.SCI_STYLESETBACK, new IntPtr(Index), new IntPtr(color)); } } @@ -119,12 +119,12 @@ public bool Bold { get { - return scintilla.DirectMessage(NativeMethods.SCI_STYLEGETBOLD, new IntPtr(Index), IntPtr.Zero) != IntPtr.Zero; + return this.scintilla.DirectMessage(NativeMethods.SCI_STYLEGETBOLD, new IntPtr(Index), IntPtr.Zero) != IntPtr.Zero; } set { - var bold = (value ? new IntPtr(1) : IntPtr.Zero); - scintilla.DirectMessage(NativeMethods.SCI_STYLESETBOLD, new IntPtr(Index), bold); + IntPtr bold = value ? new IntPtr(1) : IntPtr.Zero; + this.scintilla.DirectMessage(NativeMethods.SCI_STYLESETBOLD, new IntPtr(Index), bold); } } @@ -137,14 +137,14 @@ public StyleCase Case { get { - var @case = scintilla.DirectMessage(NativeMethods.SCI_STYLEGETCASE, new IntPtr(Index), IntPtr.Zero).ToInt32(); + int @case = this.scintilla.DirectMessage(NativeMethods.SCI_STYLEGETCASE, new IntPtr(Index), IntPtr.Zero).ToInt32(); return (StyleCase)@case; } set { // Just an excuse to use @... syntax - var @case = (int)value; - scintilla.DirectMessage(NativeMethods.SCI_STYLESETCASE, new IntPtr(Index), new IntPtr(@case)); + int @case = (int)value; + this.scintilla.DirectMessage(NativeMethods.SCI_STYLESETCASE, new IntPtr(Index), new IntPtr(@case)); } } @@ -159,12 +159,12 @@ public bool Changeable { get { - return scintilla.DirectMessage(NativeMethods.SCI_STYLEGETCHANGEABLE, new IntPtr(Index), IntPtr.Zero) != IntPtr.Zero; + return this.scintilla.DirectMessage(NativeMethods.SCI_STYLEGETCHANGEABLE, new IntPtr(Index), IntPtr.Zero) != IntPtr.Zero; } set { - var changeable = (value ? new IntPtr(1) : IntPtr.Zero); - scintilla.DirectMessage(NativeMethods.SCI_STYLESETCHANGEABLE, new IntPtr(Index), changeable); + IntPtr changeable = value ? new IntPtr(1) : IntPtr.Zero; + this.scintilla.DirectMessage(NativeMethods.SCI_STYLESETCHANGEABLE, new IntPtr(Index), changeable); } } @@ -177,12 +177,12 @@ public bool FillLine { get { - return scintilla.DirectMessage(NativeMethods.SCI_STYLEGETEOLFILLED, new IntPtr(Index), IntPtr.Zero) != IntPtr.Zero; + return this.scintilla.DirectMessage(NativeMethods.SCI_STYLEGETEOLFILLED, new IntPtr(Index), IntPtr.Zero) != IntPtr.Zero; } set { - var fillLine = (value ? new IntPtr(1) : IntPtr.Zero); - scintilla.DirectMessage(NativeMethods.SCI_STYLESETEOLFILLED, new IntPtr(Index), fillLine); + IntPtr fillLine = value ? new IntPtr(1) : IntPtr.Zero; + this.scintilla.DirectMessage(NativeMethods.SCI_STYLESETEOLFILLED, new IntPtr(Index), fillLine); } } @@ -195,15 +195,15 @@ public string Font { get { - var length = scintilla.DirectMessage(NativeMethods.SCI_STYLEGETFONT, new IntPtr(Index), IntPtr.Zero).ToInt32(); - var font = new byte[length]; + int length = this.scintilla.DirectMessage(NativeMethods.SCI_STYLEGETFONT, new IntPtr(Index), IntPtr.Zero).ToInt32(); + byte[] font = new byte[length]; unsafe { fixed (byte* bp = font) - scintilla.DirectMessage(NativeMethods.SCI_STYLEGETFONT, new IntPtr(Index), new IntPtr(bp)); + this.scintilla.DirectMessage(NativeMethods.SCI_STYLEGETFONT, new IntPtr(Index), new IntPtr(bp)); } - var name = Encoding.UTF8.GetString(font, 0, length); + string name = Encoding.UTF8.GetString(font, 0, length); return name; } set @@ -212,11 +212,11 @@ public string Font value = "Verdana"; // Scintilla expects UTF-8 - var font = Helpers.GetBytes(value, Encoding.UTF8, true); + byte[] font = Helpers.GetBytes(value, Encoding.UTF8, true); unsafe { fixed (byte* bp = font) - scintilla.DirectMessage(NativeMethods.SCI_STYLESETFONT, new IntPtr(Index), new IntPtr(bp)); + this.scintilla.DirectMessage(NativeMethods.SCI_STYLESETFONT, new IntPtr(Index), new IntPtr(bp)); } } } @@ -230,7 +230,7 @@ public Color ForeColor { get { - var color = scintilla.DirectMessage(NativeMethods.SCI_STYLEGETFORE, new IntPtr(Index), IntPtr.Zero).ToInt32(); + int color = this.scintilla.DirectMessage(NativeMethods.SCI_STYLEGETFORE, new IntPtr(Index), IntPtr.Zero).ToInt32(); return HelperMethods.FromWin32Color(color); } set @@ -238,8 +238,8 @@ public Color ForeColor if (value.IsEmpty) value = Color.Black; - var color = HelperMethods.ToWin32Color(value); - scintilla.DirectMessage(NativeMethods.SCI_STYLESETFORE, new IntPtr(Index), new IntPtr(color)); + int color = HelperMethods.ToWin32Color(value); + this.scintilla.DirectMessage(NativeMethods.SCI_STYLESETFORE, new IntPtr(Index), new IntPtr(color)); } } @@ -251,12 +251,12 @@ public bool Hotspot { get { - return scintilla.DirectMessage(NativeMethods.SCI_STYLEGETHOTSPOT, new IntPtr(Index), IntPtr.Zero) != IntPtr.Zero; + return this.scintilla.DirectMessage(NativeMethods.SCI_STYLEGETHOTSPOT, new IntPtr(Index), IntPtr.Zero) != IntPtr.Zero; } set { - var hotspot = (value ? new IntPtr(1) : IntPtr.Zero); - scintilla.DirectMessage(NativeMethods.SCI_STYLESETHOTSPOT, new IntPtr(Index), hotspot); + IntPtr hotspot = value ? new IntPtr(1) : IntPtr.Zero; + this.scintilla.DirectMessage(NativeMethods.SCI_STYLESETHOTSPOT, new IntPtr(Index), hotspot); } } @@ -274,12 +274,12 @@ public bool Italic { get { - return scintilla.DirectMessage(NativeMethods.SCI_STYLEGETITALIC, new IntPtr(Index), IntPtr.Zero) != IntPtr.Zero; + return this.scintilla.DirectMessage(NativeMethods.SCI_STYLEGETITALIC, new IntPtr(Index), IntPtr.Zero) != IntPtr.Zero; } set { - var italic = (value ? new IntPtr(1) : IntPtr.Zero); - scintilla.DirectMessage(NativeMethods.SCI_STYLESETITALIC, new IntPtr(Index), italic); + IntPtr italic = value ? new IntPtr(1) : IntPtr.Zero; + this.scintilla.DirectMessage(NativeMethods.SCI_STYLESETITALIC, new IntPtr(Index), italic); } } @@ -291,11 +291,11 @@ public int Size { get { - return scintilla.DirectMessage(NativeMethods.SCI_STYLEGETSIZE, new IntPtr(Index), IntPtr.Zero).ToInt32(); + return this.scintilla.DirectMessage(NativeMethods.SCI_STYLEGETSIZE, new IntPtr(Index), IntPtr.Zero).ToInt32(); } set { - scintilla.DirectMessage(NativeMethods.SCI_STYLESETSIZE, new IntPtr(Index), new IntPtr(value)); + this.scintilla.DirectMessage(NativeMethods.SCI_STYLESETSIZE, new IntPtr(Index), new IntPtr(value)); } } @@ -307,13 +307,13 @@ public float SizeF { get { - var fraction = scintilla.DirectMessage(NativeMethods.SCI_STYLEGETSIZEFRACTIONAL, new IntPtr(Index), IntPtr.Zero).ToInt32(); + int fraction = this.scintilla.DirectMessage(NativeMethods.SCI_STYLEGETSIZEFRACTIONAL, new IntPtr(Index), IntPtr.Zero).ToInt32(); return (float)fraction / NativeMethods.SC_FONT_SIZE_MULTIPLIER; } set { - var fraction = (int)(value * NativeMethods.SC_FONT_SIZE_MULTIPLIER); - scintilla.DirectMessage(NativeMethods.SCI_STYLESETSIZEFRACTIONAL, new IntPtr(Index), new IntPtr(fraction)); + int fraction = (int)(value * NativeMethods.SC_FONT_SIZE_MULTIPLIER); + this.scintilla.DirectMessage(NativeMethods.SCI_STYLESETSIZEFRACTIONAL, new IntPtr(Index), new IntPtr(fraction)); } } @@ -325,12 +325,12 @@ public bool Underline { get { - return scintilla.DirectMessage(NativeMethods.SCI_STYLEGETUNDERLINE, new IntPtr(Index), IntPtr.Zero) != IntPtr.Zero; + return this.scintilla.DirectMessage(NativeMethods.SCI_STYLEGETUNDERLINE, new IntPtr(Index), IntPtr.Zero) != IntPtr.Zero; } set { - var underline = (value ? new IntPtr(1) : IntPtr.Zero); - scintilla.DirectMessage(NativeMethods.SCI_STYLESETUNDERLINE, new IntPtr(Index), underline); + IntPtr underline = value ? new IntPtr(1) : IntPtr.Zero; + this.scintilla.DirectMessage(NativeMethods.SCI_STYLESETUNDERLINE, new IntPtr(Index), underline); } } @@ -342,12 +342,12 @@ public bool Visible { get { - return scintilla.DirectMessage(NativeMethods.SCI_STYLEGETVISIBLE, new IntPtr(Index), IntPtr.Zero) != IntPtr.Zero; + return this.scintilla.DirectMessage(NativeMethods.SCI_STYLEGETVISIBLE, new IntPtr(Index), IntPtr.Zero) != IntPtr.Zero; } set { - var visible = (value ? new IntPtr(1) : IntPtr.Zero); - scintilla.DirectMessage(NativeMethods.SCI_STYLESETVISIBLE, new IntPtr(Index), visible); + IntPtr visible = value ? new IntPtr(1) : IntPtr.Zero; + this.scintilla.DirectMessage(NativeMethods.SCI_STYLESETVISIBLE, new IntPtr(Index), visible); } } @@ -360,11 +360,11 @@ public int Weight { get { - return scintilla.DirectMessage(NativeMethods.SCI_STYLEGETWEIGHT, new IntPtr(Index), IntPtr.Zero).ToInt32(); + return this.scintilla.DirectMessage(NativeMethods.SCI_STYLEGETWEIGHT, new IntPtr(Index), IntPtr.Zero).ToInt32(); } set { - scintilla.DirectMessage(NativeMethods.SCI_STYLESETWEIGHT, new IntPtr(Index), new IntPtr(value)); + this.scintilla.DirectMessage(NativeMethods.SCI_STYLESETWEIGHT, new IntPtr(Index), new IntPtr(value)); } } @@ -731,12 +731,12 @@ public static class CLW /// Attributes style index /// public const int Attributes = NativeMethods.SCE_CLW_ATTRIBUTE; - + /// /// Built in procedures function style index. /// public const int BuiltInProceduresFunction = NativeMethods.SCE_CLW_BUILTIN_PROCEDURES_FUNCTION; - + /// /// Comment style index. /// @@ -751,27 +751,27 @@ public static class CLW /// Default (whitespace) style index. /// public const int Default = NativeMethods.SCE_CLW_DEFAULT; - + /// /// Depreciated style index /// public const int Depreciated = NativeMethods.SCE_CLW_DEPRECATED; - + /// /// Error style index /// public const int Error = NativeMethods.SCE_CLW_ERROR; - + /// /// Integer Constant style index. /// public const int IntegerConstant = NativeMethods.SCE_CLW_INTEGER_CONSTANT; - + /// /// Keyword style index /// public const int Keyword = NativeMethods.SCE_CLW_KEYWORD; - + /// /// Label string style index. /// @@ -781,7 +781,7 @@ public static class CLW /// Real Constant style index. /// public const int PictureString = NativeMethods.SCE_CLW_PICTURE_STRING; - + /// /// Real Constant style index. /// @@ -791,22 +791,22 @@ public static class CLW /// Runtime expressions style index /// public const int RuntimeExpressions = NativeMethods.SCE_CLW_RUNTIME_EXPRESSIONS; - + /// /// Standard equates style index /// public const int StandardEquates = NativeMethods.SCE_CLW_STANDARD_EQUATE; - + /// /// Single-quoted string style index. /// public const int String = NativeMethods.SCE_CLW_STRING; - + /// /// Structure data type style index. /// public const int StructureDataTypes = NativeMethods.SCE_CLW_STRUCTURE_DATA_TYPE; - + /// /// User Identifier style index. /// @@ -964,7 +964,7 @@ public static class Cpp } #endregion Cpp - + #region Css /// diff --git a/Scintilla.NET/StyleCollection.cs b/Scintilla.NET/StyleCollection.cs index 49f24df..a63840f 100644 --- a/Scintilla.NET/StyleCollection.cs +++ b/Scintilla.NET/StyleCollection.cs @@ -25,7 +25,7 @@ public IEnumerator