安装完后,第一次启动,一定要以管理员权限启动VS
After installation, start it for the first time, be sure to start VS with administrator privileges.
Also Develop: SharpBoxes
同人开发:SharpBoxes
- 集成了一些常用的方法; 如通用的缓存静态操作类、常用的Wpf的ValueConverters、内置的委托类型、通用的反射加载dll操作类、Wpf的ViewModel、Command、Navigation、Messenger、部分常用UserControls(可绑定的PasswordBox、PlaceHolderTextBox、HighlightTextBlock等),以及Wpf一些常用的后台数据绑定方法 其他是一些通用的扩展方法类
- It integrates some commonly used methods. Such as the general cache static operation class, the commonly used Wpf ValueConverters, the built-in delegate type, the general reflective loading dll operation class, Wpf's ViewModel, Command, Navigation, Messenger, some commonly used UserControls (bindable PasswordBox, PlaceHolderTextBox, HighlightTextBlock, etc.), and some commonly used background data binding methods of Wpf Others are some general extension method classes
Visual Studio 扩展代码片段
CSharp代码片段
检查文件是否存在
fileexist
if (System.IO.File.Exists(""))
{
}
检查文件夹是否存在
direxist
if (System.IO.Directory.Exists(""))
{
}
带Index的Foreach
forwithitem
for (int index = 0; index < collection.Count; index++)
{
var item = collection[index];
}
插入文档摘要
hddoc
/*
* Title:
* Author:
* Date:
* Purpose:
*
* Revisions:
* 1.
*/
快速创建方法
method
public int GoWork(string p)
{
}
快速创建类
cc
public class MyClass
{
public MyClass()
{
}
}
快速创建Int属性
pi
public int p { get; set; }
快速创建Double属性
pd
public double p { get; set; }
快速创建String属性
ps
public string p { get; set; }
快速创建List属性
pl
public List<int> p { get; set; }
快速MessageBox
mberror
MessageBox.Show(
"",
"Error",
MessageBoxButton.OK,
MessageBoxImage.Error
);
mbinfo
mbwarn
...
快速创建带TryCatchFinally方法
methodWithTryCFg
public int GoWork(string p)
{
try
{
}
catch (Exception ex)
{
// Exception handling code
}
finally
{
// Cleanup code
}
}
快速Null检查
nullcheck
if (null == null)
{
}
快速生成带有消息通知的属性
propchanged
private string myProperty;
public string MyProperty
{
get
{
return myProperty;
}
set
{
myProperty = value;
OnPropertyChanged(myProperty, value);
}
}
快速生成ReadLine
cr
快速生成StopWatch
swg
var sw = Stopwatch.StartNew();
快速生成Student类(带模拟数据)
stuclass
public class Student
{
public string Name { get; set; }
public int Age { get; set; }
public string Address { get; set; }
public static IEnumerable<Student> FakeManyStudents(int count)
{
var students = new List<Student>();
var names = GenerateRandomNumber(count).Select(s => s.ToString()).ToList();
var addresses = GenerateRandomNumber(count).Select(s => s.ToString()).ToList();
for (int i = 0; i < count; i++)
{
students.Add(
new Student
{
Name = "Student " + names[i],
Age = 20 + i,
Address = "Address " + addresses[i]
}
);
}
return students;
}
private static List<int> GenerateRandomNumber(int count)
{
var rd = new Random(Guid.NewGuid().GetHashCode());
var result = new List<int>();
for (int i = 0; i < count; i++)
{
var number = rd.Next(1, 20);
result.Add(number);
}
return result;
}
}
快速生成结果状态类(通用返回值)
status
[DebuggerStepThrough]
public class Status
{
public int Code = 0;
public string Message = "运行成功";
public bool Result = true;
public Status(int code = 0, string message = null, bool result = false)
{
Code = code;
Message = message;
Result = result;
}
public Status(string message)
{
Message = message;
}
public Status(string message, bool result)
{
Message = message;
Result = result;
}
public static Status OkDef = new Status(0, "结果OK", true);
public static Status NgDef = new Status(-1, "结果NG", false);
public static Status Ng(string message) => new Status(message, false);
public static Status Ok(string message) => new Status(message, true);
public static implicit operator bool(Status d) => d.Result;
public static implicit operator string(Status d) => d.ToString();
public override string ToString()
{
return $"{Code},{Result},{Message}";
}
}
快速生成Task.Run包裹
taskg
Task.Run(() =>
{
});
TryCatchFinally包裹
trycatchfinally
try
{
}
catch (Exception ex)
{
// Exception handling code
}
finally
{
// Cleanup code
}
带属性修改回调的依赖属性
propdpn
public string Title
{
get { return (string)GetValue(TitleProperty); }
set { SetValue(TitleProperty, value); }
}
public static readonly DependencyProperty TitleProperty =
DependencyProperty.Register("Title", typeof(string), typeof(Test), new PropertyMetadata(string.Empty, TitleChanged));
private static void TitleChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
if (d is TextBox control)
{
}
}
带属性修改回调的附加属性
propan
public static string GetName(DependencyObject obj)
{
return (string)obj.GetValue(NameProperty);
}
public static void SetName(DependencyObject obj, string value)
{
obj.SetValue(NameProperty, value);
}
public static readonly DependencyProperty NameProperty =
DependencyProperty.RegisterAttached(
"Name",
typeof(string),
typeof(Test),
new PropertyMetadata(string.Empty, NameChanged)
);
private static void NameChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
if (d is TextBox control)
{
}
}
Xaml代码片段
快速生成DoubleAnimation
anidouble
快速生成ItemTemplate
itemtemplate
快速生成mscorlib命名空间
nssys
xmlns:sys="clr-namespace:System;assembly=mscorlib"
快速生成包URI语法
pack
"pack://application:,,,/$TargetAssembly$;component/$Resource$"
快速生成Resources
res
快速生成Style
style