Skip to content

Instantly share code, notes, and snippets.

Avatar

lindexi lindexi

View GitHub Profile
@lindexi
lindexi / CharUnicodeRange.cs
Last active May 14, 2020
获取字符所在哪个 Unicode 平面
View CharUnicodeRange.cs
// NuGet install System.Text.Encodings.Web
// <PackageReference Include="System.Text.Encodings.Web" Version="4.7.1" />
// using System.Text.Unicode;
// UnicodeRange: https://github.com/dotnet/runtime/blob/5372ee9dbe48058ca8d3591763e989d3b2e65581/src/libraries/System.Text.Encodings.Web/src/System/Text/Unicode/UnicodeRange.cs
// UnicodeRanges https://github.com/dotnet/runtime/blob/5372ee9dbe48058ca8d3591763e989d3b2e65581/src/libraries/System.Text.Encodings.Web/src/System/Text/Unicode/UnicodeRanges.generated.cs
/// <summary>
/// 获取字符所在哪个 Unicode 平面
/// </summary>
@lindexi
lindexi / ReferenceVersion.cs
Created Jun 23, 2018
转换引用的版本
View ReferenceVersion.cs
/// <summary>
/// 引用的版本
/// 用来转换 [2.1.0.293,3.0)、 (1.1.0.3,2.0]、 5.2 的版本
/// </summary>
public class ReferenceVersion
{
/// <summary>
/// 创建引用版本
/// </summary>
/// <param name="version">版本</param>
View UWPStringToColor.cs
public SolidColorBrush GetSolidColorBrush(string hex)
{
hex = hex.Replace("#", string.Empty);
//#FFDFD991
//#DFD991
//#FD92
//#DAC
bool existAlpha = hex.Length == 8 || hex.Length == 4;
@lindexi
lindexi / ExtendedWindowStyles.cs
Created Mar 1, 2018
ExtendedWindowStyles code from msdn
View ExtendedWindowStyles.cs
/// <summary>
/// 扩展的窗口风格
/// </summary>
/// 代码:[Extended Window Styles (Windows)](https://msdn.microsoft.com/en-us/library/windows/desktop/ff700543(v=vs.85).aspx )
/// code from [Extended Window Styles (Windows)](https://msdn.microsoft.com/en-us/library/windows/desktop/ff700543(v=vs.85).aspx )
[Flags]
public enum ExtendedWindowStyles : long
{
/// <summary>
/// The window accepts drag-drop files
@lindexi
lindexi / MakeValidFileName.cs
Created Feb 23, 2018
替换不能做文件名的字符
View MakeValidFileName.cs
public static string MakeValidFileName(string text, string replacement = "_")
{
StringBuilder str=new StringBuilder();
var invalidFileNameChars = System.IO.Path.GetInvalidFileNameChars();
foreach (var c in text)
{
if (invalidFileNameChars.Contains(c))
{
str.Append(replacement??"");
}
@lindexi
lindexi / Bbcode2md.cs
Last active Feb 12, 2018
从 BBCode 转换为 Markdown
View Bbcode2md.cs
class Bbcode2md
{
/// <summary>
/// To convert bbcode to markdown
/// </summary>
/// <remarks>[JonDum/BBCode-To-Markdown-Converter](https://github.com/JonDum/BBCode-To-Markdown-Converter )</remarks>
/// <param name="str"></param>
/// <returns></returns>
public static string BbcodetoMd(string str)
@lindexi
lindexi / GifImageControl.cs
Last active Feb 11, 2018
WPF 使用 WinForm 播放 gif
View GifImageControl.cs
/// <summary>
/// 使用 WinForm 播放 Gif
/// </summary>
/// <example>
/// xaml:
/// <local:GifImageControl x:Name="Image" Path="lindexi.gif"></local:GifImageControl>
/// cs:
/// var image = new GifImageControl("E:\\lindexi.gif");
/// Grid.Children.Add(image);
/// </example>
View LayoutTransformer
using System;
using System.Diagnostics.CodeAnalysis;
using Windows.Foundation;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Media;
namespace Common
{
/// <summary>
@lindexi
lindexi / unix timestamp to DateTime.cs
Last active Jun 21, 2017
json unix timestamp to dateTime
View unix timestamp to DateTime.cs
public class UnixConvert : JsonConverter
{
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
var time = ToUnixTimestamp((DateTime) value);
writer.WriteValue(time);
}
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
View C# git
public class GitControl
{
public GitControl(string fileDirectory)
{
FileDirectory = fileDirectory;
}
/// <summary>
/// git的文件夹
/// </summary>