# 常用 API 声明参考 来源:MAX.Common,2026-10-27 工作区源码快照。 按下方主题或文件名搜索。仅摘录选定文件的 public / protected 声明;省略方法体、初始化表达式与 XML 注释。这是定位参考,不是可直接编译的 C#,不保证包含嵌套类型的完整可见性上下文。行为说明见 SKILL.md;目标包版本不同时以实际包为准。 目录:命令与绑定模型、集合与数据、文件、数值与校验、事件与运行控制 ## 命令与绑定模型 ### Commands/MethodCommand.cs 命名空间:`MAX.Common.Commands` ```csharp public class MethodCommand( Action execute, Func? canExecute = null ) : ICommand public event EventHandler? CanExecuteChanged public bool CanExecute(object parameter) public void Execute(object parameter) public void RaiseCanExecuteChanged() public class MethodCommand : ICommand public MethodCommand( Action execute, Func? canExecute = null ) public event EventHandler? CanExecuteChanged public bool CanExecute(object parameter) public void Execute(object parameter) public void RaiseCanExecuteChanged() ``` ### Commands/AsyncMethodCommand.cs 命名空间:`MAX.Common.Commands` ```csharp public class AsyncMethodCommand(Func execute, Func? canExecute = null) : ICommand public event EventHandler? CanExecuteChanged public bool CanExecute(object parameter) public async void Execute(object parameter) public void RaiseCanExecuteChanged() public class AsyncMethodCommand : ICommand public event EventHandler? CanExecuteChanged public AsyncMethodCommand(Func execute, Func? canExecute = null) public bool CanExecute(object parameter) public async void Execute(object parameter) public void RaiseCanExecuteChanged() ``` ### Models/BindModelBase.cs 命名空间:`MAX.Common.Models` ```csharp public abstract class BindModelBase : INotifyPropertyChanged public event PropertyChangedEventHandler? PropertyChanged public BindModelBase() public virtual void OnInitialized() public virtual bool ShouldCheckValueMatching(string? propertyName, T from, T to) protected virtual bool SetProperty(ref T storage, T value, Action? onChanged = null, [CallerMemberName] string? propertyName = null) protected virtual bool SetPropertyNoCheck(ref T storage, T value, Action? onChanged = null, [CallerMemberName] string? propertyName = null) protected virtual void OnPropertyChanging(string? propertyName, T from, T to, CancelEventArgs cancelEventArgs) protected virtual void OnPropertyChanged(PropertyChangedEventArgs args) protected void RaisePropertyChanged([CallerMemberName] string? propertyName = null) ``` ### Models/BindableBaseEx.cs 命名空间:`MAX.Common.Models` ```csharp public abstract class BindableBaseEx : INotifyPropertyChanged public event PropertyChangedEventHandler? PropertyChanged public BindableBaseEx() public virtual void OnInitialized() public static string GetPropertyName(Expression> expression) protected T? GetProperty(Expression> expression) protected bool SetProperty(Expression> expression, T value) protected bool SetProperty(Expression> expression, T value, Action? changedCallback) protected bool SetProperty(Expression> expression, T value, Action? changedCallback) protected bool SetProperty(ref T storage, T value, Expression> expression) protected bool SetProperty(ref T storage, T value, Expression> expression, Action? changedCallback) protected void RaisePropertyChanged(Expression> expression) protected T? GetValue([CallerMemberName] string? propertyName = null) protected bool SetValue(T value, [CallerMemberName] string? propertyName = null) protected bool SetValue(T value, Action? changedCallback, [CallerMemberName] string? propertyName = null) protected bool SetValue(T value, Action? changedCallback, [CallerMemberName] string? propertyName = null) protected bool SetValue(ref T storage, T value, [CallerMemberName] string? propertyName = null) protected bool SetValue(ref T storage, T value, Action? changedCallback, [CallerMemberName] string? propertyName = null) protected bool SetProperty(ref T storage, T value, string propertyName) protected virtual bool SetProperty(ref T storage, T value, string propertyName, Action? changedCallback) protected virtual bool SetPropertyCore(string propertyName, T value, out T? oldValue) protected virtual void RaisePropertyChanged(string propertyName) protected void RaisePropertyChanged() protected void RaisePropertiesChanged(params string[]? propertyNames) protected virtual void VerifyAccess() protected virtual bool CompareValues(T storage, T value, string propertyName) ``` ### Models/BindObject.cs 命名空间:`MAX.Common.Models` ```csharp public sealed class BindObject : BindModelBase public event TypedEventHandler, PropertyValueUpdatedEventArgs>? ValueChanged public T? Value public BindObject(T? defaultValue = default) public void Set(T value) public static implicit operator BindObject(T value) public static implicit operator T?(BindObject value) ``` ## 集合与数据 ### Data/Collections/BidirectionalDictionary.cs 命名空间:`MAX.Common.Data.Collections` ```csharp public class BidirectionalDictionary : IDictionary, IDictionary, IReadOnlyCollection> public TValue this[TKey key] public int Count public ICollection Keys public ICollection Values public bool IsReadOnly public bool IsFixedSize public bool IsSynchronized public object SyncRoot public BidirectionalDictionary() public BidirectionalDictionary(int capacity) public void Add(TKey key, TValue value) public bool Remove(TKey key) public bool RemoveByValue(TValue value) public void Clear() public bool TryGetValue(TKey key, out TValue value) public bool TryGetKey(TValue value, out TKey key) public TKey GetKey(TValue value) public TValue GetValue(TKey key) public bool ContainsKey(TKey key) public bool ContainsValue(TValue value) public void Add(KeyValuePair item) public bool Contains(KeyValuePair item) public void CopyTo(KeyValuePair[] array, int arrayIndex) public bool Remove(KeyValuePair item) public IEnumerator> GetEnumerator() ``` ### Data/Lists/CyclicReadOnlyList.cs 命名空间:`MAX.Common.Data.Lists` ```csharp public class CyclicReadOnlyList : IReadOnlyList public CyclicReadOnlyList(IReadOnlyList source, int startIndex, int loopCount) public int Count public T this[int index] public IEnumerator GetEnumerator() ``` ### Data/Lists/SelectorReadonlyList.cs 命名空间:`MAX.Common.Data.Lists` ```csharp public class SelectorReadonlyList(IReadOnlyList source, Func selector) : IReadOnlyList public TResult this[int index] public int Count public IEnumerator GetEnumerator() public static class SelectorReadonlyListExtensions public static IReadOnlyList SelectAsReadonlyList(this IReadOnlyList source, Func selector) ``` ### Data/Lists/ReversedReadonlyList.cs 命名空间:`MAX.Common.Data.Lists` ```csharp public class ReversedReadonlyList(IReadOnlyList source) : IReadOnlyList public IReadOnlyList Source public virtual T this[int index] public int Count public IEnumerator GetEnumerator() ``` ### Data/PrecisionBuilder.cs 命名空间:`MAX.Common.Data` ```csharp public class PrecisionBuilder public int PrecisionLength public bool UseScientificNotation public int ScientificNatationTriggerLength public bool RemoveTrailingZeros public PrecisionBuilder( int precisionLength, bool useScientificNotation, int scientificNatationTriggerLength, bool removeTrailingZeros ) public PrecisionBuilder( int precisionLength, bool useScientificNotation, int scientificNatationTriggerLength, bool removeTrailingZeros, string scientificNotationString, string autoString ) public string GetResultString(double d) ``` ### Models/EnumItem.cs 命名空间:`MAX.Common.Models` ```csharp public readonly record struct EnumItem( string Name, object Value, string? Description, string? ToolTip ) public static IEnumerable GetEnumItems() where T : Enum public static IEnumerable GetEnumItems(Type type) public static EnumItem GetEnumItem(Enum @enum) ``` ## 文件、数值与校验 ### Helpers/FileHelper.Size.cs 命名空间:`MAX.Common.Helpers` ```csharp public static partial class FileHelper public static string FileSizeToKB(this long size, string format = "#,##0", string prefix = "", string suffix = " KB") public static string FileSizeToMB(this long size, string format = "#,##0", string prefix = "", string suffix = " MB") public static string FileSizeToGB(this long size, string format = "#,##0", string prefix = "", string suffix = " GB") public static string FileSizeToTB(this long size, string format = "#,##0", string prefix = "", string suffix = " TB") public static string FileSizeToPB(this long size, string format = "#,##0", string prefix = "", string suffix = " PB") public static string FileSizeToString(this long size, string format = "#,##0.##", string prefix = "") ``` ### Helpers/FileHelper.cs 命名空间:`MAX.Common.Helpers` ```csharp public static partial class FileHelper public static string GetUniqueFileName(string fullPath) public static string FixInvalidFullFilePath(string fullPath, string replacement = " ") public static bool IsFileNameInvalid(this string name) public static string FixInvalidFileName(string fileName, string replacement = " ") public static bool FileNameExists(this string fileName, IEnumerable fileNames) public static Exception? ShowInExplorer(this string? filePath) public static Exception? OpenPathInSystemDefault(this string? filePath) public static async Task CalculateFileMD5Async(string filePath, int bufferSize = 4096) public static string CalculateFileMD5(string filePath, int bufferSize = 4096) public static string? CalculateFileMD5(byte[]? bytes) public static async Task CalculateFileMD5Async(byte[]? bytes) public static List ReadAllLines(string filePath, Encoding? encoding = null) public static FileInfo? SafeGetFileInfo(this string? filePath, Action? handleException = null) public static bool AreFilePathsEqual(this string? path1, string? path2) public static bool? AreFilePathsEqualSafe(this string? path1, string? path2) public static string NormalizePath(this string? path) public static string NormalizePathSafe(this string? path) ``` ### Helpers/DirectoryHelper.cs 命名空间:`MAX.Common.Helpers` ```csharp public static class DirectoryHelper public static bool IsRootDirectory(string path) public static bool IsWindowsRootDirectory(string path) public static bool IsUnixRootDirectory(string path) public static DirectoryInfo CreateDirectory(string? dir, bool checkFileParent = false) public static Exception? TryCreateDirectory(string? dir, bool checkFileParent = false) public static bool HasWriteAccessToFolder(string folderPath) public static void CopyDirectory( string sourceDir, string destinationDir, bool recursive = true, Predicate? handleFile = null ) public static string GetUniqueFolderName(string folderPath, bool reuseEmptyDirectory = false) public static bool IsDirectoryEmpty(this string folderPath) public static bool IsDirectoryEmptyOrNotExist(this string folderPath) public static string AppendDirectorySeparatorChar(string path) public static string GetRelativePath(string relativeTo, string path) ``` ### Helpers/NumberHelper.Clamp.cs 命名空间:`MAX.Common.Helpers` ```csharp public static partial class NumberHelper public static T ClampGeneric(this T value, T min, T max) where T : IComparable public static float Clamp(this float input, float min, float max) public static double Clamp(this double input, double min, double max) public static decimal Clamp(this decimal input, decimal min, decimal max) public static int Clamp(this int input, int min, int max) public static long Clamp(this long input, long min, long max) public static short Clamp(this short input, short min, short max) public static sbyte Clamp(this sbyte input, sbyte min, sbyte max) public static uint Clamp(this uint input, uint min, uint max) public static ulong Clamp(this ulong input, ulong min, ulong max) public static ushort Clamp(this ushort input, ushort min, ushort max) public static byte Clamp(this byte input, byte min, byte max) ``` ### Utilities/PathValidator.cs 命名空间:`MAX.Common.Utilities` ```csharp public static partial class PathValidator public static bool IsFolderPathValidAndSafe([NotNullWhen(true)] string? path, bool allowRelativePath) ``` ### Utilities/FolderNameValidator.cs 命名空间:`MAX.Common.Utilities` ```csharp public static class FolderNameValidator public enum ValidationResult public static IReadOnlyCollection ReservedNamesInWindows public static bool IsValidFolderName([NotNullWhen(true)] string? folderName) public static ValidationResult Validate(string? folderName) public static string GetErrorMessage(ValidationResult result) ``` ## 事件与运行控制 ### Events/TypedEvent.cs 命名空间:`MAX.Common.Events` ```csharp public class TypedEvent public event TypedEventHandler? Event public void Raise(TSender sender, TArgs args) public class TypedEvent public event Action? Event public void Raise(TArgs args) public class TypedEvent public event Action? Event public void Raise() ``` ### Events/AsyncEvent.cs 命名空间:`MAX.Common.Events` ```csharp public class AsyncEvent where TEventArgs : EventArgs public static AsyncEvent operator +(AsyncEvent? e, Func? callback) public static AsyncEvent? operator -(AsyncEvent? e, Func callback) public async Task InvokeAsync(object sender, TEventArgs eventArgs) ``` ### Utilities/RunLimiter.cs 命名空间:`MAX.Common.Utilities` ```csharp public class RunLimiter(Action action, int maxLimit = 1) public bool Run() public bool CanRun() ``` ### Utilities/DisposeAction.cs 命名空间:`MAX.Common.Utilities` ```csharp public class DisposeAction(Action action) : IDisposable public Action Action public void Dispose() ``` ### Utilities/CompensatingTimer.cs 命名空间:`MAX.Common.Utilities` ```csharp public class CompensatingTimer : IDisposable public event Action? OnTickException public CompensatingTimer(TimeSpan interval, Action tickCallback) public void Start() public void Stop() public void Dispose() ``` ### Helpers/SerializationHelper.cs 命名空间:`MAX.Common.Helpers` ```csharp public static class SerializationHelper public static T? TryGetValue(this SerializationInfo info, string name, T? defaultWhenException = default) ```