/*
Copyright (C) 2014-2019 de4dot@gmail.com
This file is part of dnSpy
dnSpy is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
dnSpy is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with dnSpy. If not, see .
*/
using System;
using VSTE = Microsoft.VisualStudio.Text.Editor;
using VSUTIL = Microsoft.VisualStudio.Utilities;
namespace dnSpy.Contracts.Hex.Editor {
///
/// Hex editor option definition
///
public abstract class HexEditorOptionDefinition : VSTE.EditorOptionDefinition {
///
/// Constructor
///
protected HexEditorOptionDefinition() { }
}
///
/// Hex editor option definition
///
///
public abstract class HexEditorOptionDefinition : HexEditorOptionDefinition {
///
/// Constructor
///
protected HexEditorOptionDefinition() { }
///
/// Gets the value type
///
public sealed override Type ValueType => typeof(T);
///
/// Gets the name of the option
///
public sealed override string Name => Key.Name;
///
/// Gets the default value
///
public sealed override object? DefaultValue => Default;
///
/// Gets the option key
///
public abstract VSTE.EditorOptionKey Key { get; }
///
/// Gets the default value
///
public virtual T Default => default!;
///
/// Checks whether the new value is valid
///
/// Proposed value
///
public sealed override bool IsValid(ref object proposedValue) {
if (!(proposedValue is T))
return false;
var t = (T)proposedValue;
var res = IsValid(ref t);
proposedValue = t!;
return res;
}
///
/// Checks whether the new value is valid
///
/// Proposed value
///
public virtual bool IsValid(ref T proposedValue) => true;
}
///
/// option definition
///
public abstract class HexViewOptionDefinition : HexEditorOptionDefinition {
///
/// Constructor
///
protected HexViewOptionDefinition() { }
///
/// Returns true if is a
///
/// Scope
///
public override bool IsApplicableToScope(VSUTIL.IPropertyOwner scope) => scope is HexView;
}
///
/// option definition
///
public abstract class WpfHexViewOptionDefinition : HexEditorOptionDefinition {
///
/// Constructor
///
protected WpfHexViewOptionDefinition() { }
///
/// Returns true if is a
///
/// Scope
///
public override bool IsApplicableToScope(VSUTIL.IPropertyOwner scope) => scope is WpfHexView;
}
}