A C# utility library.
The library is available on nuget.org.
To install PureLib, run the following command in the Package Manager Console
PM> Install-Package PureLib
PM> Install-Package PureLib.WPF
PM> Install-Package PureLib.MediaInfo
PM> Install-Package PureLib.Generators.DicToInstGenerator
More information about NuGet package avaliable at:
Package | Version |
---|---|
PureLib | |
PureLib.WPF | |
PureLib.MediaInfo | |
PureLib.Generators.DicToInstGenerator |
- Utility
- Source Generators
- WPF
- Web
Convert a wildcard to a regular expression:
string regex = "*.txt".WildcardToRegex();
Convert a string of enum list to an enum array:
DayOfWeek[] days = "Sunday,Saturday".ToEnum<DayOfWeek>();
Conversions between binary data and base64url string:
byte[] data = Encoding.UTF8.GetBytes("test");
string result = Base64Url.Encode(data);
byte[] bin = Base64Url.Decode(result);
[FromDictionary]
public class Payload {
public int Id { get; set; }
public string Name { get; init; }
[Ignore]
public string Value { get; set; }
}
will generate
public static class DictionaryToPayloadExtensions {
public static Payload ToPayload(this Dictionary<string, object> dic) {
ref var refOfId = ref CollectionsMarshal.GetValueRefOrNullRef(dic, "Id");
ref var refOfName = ref CollectionsMarshal.GetValueRefOrNullRef(dic, "Name");
return new Payload {
Id = Unsafe.IsNullRef(ref refOfId) ? default : (Int32)refOfId,
Name = Unsafe.IsNullRef(ref refOfName) ? default : (String)refOfName,
};
}
}
NotifyObject
implements INotifyPropertyChanged
, which enables you to raise changes of properties.
public string StatusBarText {
get { return _statusBarText; }
set {
_statusBarText = value;
RaiseChange(() => StatusBarText); // or RaiseChange("StatusBarText");
}
}
ViewModelBase
inherits NotifyObject
, which is designed to be the base class of ViewModels in MVVM pattern.
public class MainWindowViewModel : ViewModelBase {
public ObservableCollection<string> Files { get; set; }
private void OnTaskStarted(object sender, TaskStartedEventArgs e) {
RunOnUIThread(() => {
if (!Files.Contains(e.File))
Files.Add(e.File);
});
}
}
RelayCommand
implements ICommand
, which could be bound to UI controls.
private ICommand _openDescriptionCommand;
public ICommand OpenDescriptionCommand {
get {
if (_openDescriptionCommand == null)
_openDescriptionCommand = new RelayCommand(p => {
OpeningDescription(this, new EventArgs<string>(((WatFile)p).Description));
}, p => !((WatFile)p).Description.IsNullOrEmpty());
return _openDescriptionCommand;
}
}
SingletonApp
inherits Application
. The application inherits SingletonApp
will not be able to run multiple instances.
public partial class App : SingletonApp {
}
PureLib provides commonly used converters for UI bindings.
BooleanToVisibilityConverter
InverseBooleanConverter
WebDownloader
contains essential functions of a download manager. It can dispatch any number of threads to download concurrently.
WebDownloader downloader = new WebDownloader(Global.Config.ThreadCount, null, false);
downloader.DownloadCompleting = OnDownloadCompleting;
downloader.AddItems(_itemPostMaps.Keys.ToList());
MIT