aop相关开发包
内容包括:
aopalliance.jar
aspectj-1.8.9.jar
aspectjrt.jar
aspectjweaver.jar
org.springframework.aop.jar
c# 自定义特性
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Entity;
using System.Collections;
using System.Diagnostics;
using System.Reflection;
namespace TestConsole
{
public class JWAttribute : Attribute
{
public string param1 { get; set; }
public string param2 { get; set; }
public string paramDefault = "paramDefault";
}
[JW(param1 = "JW-A")]
public class A
{
[JW(param2 = "JW-property")]
public string property { get; set; }
[JW(param2 = "JW-fun")]
public void fun() {}
public void nofun() {}
}
class Program
{
static void Main(string[] args)
{
JWAttribute jw;
jw = typeof(A).GetCustomAttributes(typeof(JWAttribute), false).Single() as JWAttribute;
Console.WriteLine(jw.param1);
jw = typeof(A).GetProperty("property").GetCustomAttributes(typeof(JWAttribute), false).Single() as JWAttribute;
Console.WriteLine(jw.param2);
jw = typeof(A).GetMember("fun").Single().GetCustomAttributes(typeof(JWAttribute), false).Single() as JWAttribute;
Console.WriteLine(jw.param2);
Console.WriteLine(typeof(A).GetMember("nofun").Single().GetCustomAttributes(typeof(JWAttribute), false).Count());
Console.WriteLine(jw.paramDefault);
AssemblyCopyrightAttribute aca = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false).Single() as AssemblyCopyrightAttribute;
Console.WriteLine(aca.Copyright);
Console.ReadKey();
}
}
}
共享服务例程
使用SvcHost.exe共享服务。
0.
关闭360等软件
1.
TestServiceGroup.reg
重启(svchost识别)
2.
install.bat
start.bat
stop.bat
uninstall.bat
Excel大小写转换
Excel大小写转换
Sub Upper()
Dim itarget As Range
Set itarget = Selection
For Each ran In itarget
ran.Value = UCase(ran)
Next
End Sub
Sub Lower()
Dim itarget As Range
Set itarget = Selection
For Each ran In itarget
ran.Value = LCase(ran)
Next
End Sub
ProPowerTools.vsix
ProPowerTools.vsix vs2010 最新编辑插件...
好用
简单对象序列化 扩展Object.ToJson
简单对象序列化 扩展Object.ToJson
有时候需要将对象内部的成员全部打印出来。就用这个扩展...
json2.js 下载
使用xmlhttp, 或ajax与服务器间互传数据结构的时候,非常奏效。
找了好久...
c#安全字典
直接使用Dictionary,在获取未定义的key的value时,会抛出异常。
SafeDictionary,将之安全封装。就像使用Session一样。
c# object, dynamic, var的区别用例
// object, dynamic, var的区别用例
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
public string param = "param";
static void Main(string[] args)
{
object obj; obj = new Program();
dynamic dyn; dyn = new Program();
//var v; v = new Program(); // 错误写法。正确写法如下:
var v = new Program(); // 定义的同时必须指明初始化类型。
// 等价于:Program v = new Program();编译器自动识别。
//string info1 = obj.param; // 错误写法。正确写法如下:
string info1 = ((Program)obj).param; // 必须显示告诉编译器,object是什么类型。
string info2 = dyn.param + new Program() + 1; // 正确。但.param不能智能感知。
// 编译通过是因为与dynamic相关的所有类型操作,编译器全部放行。
// 很显然,运行时必然通过“自动反射”进行检查。
string info3 = v.param;
Console.WriteLine(info1);
Console.WriteLine(info2);
Console.WriteLine(info3);
Console.ReadKey();
}
}
}
mvc3源代码 mvc3-rtm-sources.zip
有了这份源代码,就可以看到mvc3框架的内部实现。
给调试带来了很多方便...
c#使用命名管道实现打印调试
命名管道的实际用例。
// 服务端
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;
using System.IO.Pipes;
using System.IO;
namespace CSharpTraceServer
{
public partial class CSharpTraceForm : Form
{
NamedPipeServerStream server;
StreamReader reader;
public CSharpTraceForm()
{
InitializeComponent();
}
private void CSharpTraceForm_Load(object sender, EventArgs e)
{
// 命名管道
server = new NamedPipeServerStream("_");
// 后台线程
backgroundWorker.DoWork += new DoWorkEventHandler(backgroundWorker_DoWork);
backgroundWorker.ProgressChanged += new ProgressChangedEventHandler(backgroundWorker_ProgressChanged);
backgroundWorker.RunWorkerAsync();
// 窗口事件关联
this.SizeChanged += new EventHandler(CSharpTraceForm_SizeChanged);
// 窗口配置
WindowState = FormWindowState.Maximized;
}
private void AdjustSize()
{
int X = 0;
int Y = menuStrip1.Size.Height;
int Width = Size.Width;
int Height = Size.Height;
textboxInformation.Location = new Point(X, Y);
textboxInformation.Size = new Size(Width, Height);
}
void CSharpTraceForm_SizeChanged(object sender, EventArgs e)
{
AdjustSize();
}
private void clearToolStripMenuItem_Click(object sender, EventArgs e)
{
textboxInformation.Text = "";
}
void backgroundWorker_DoWork(object sender, DoWorkEventArgs e)
{
string strInformation;
while (true)
{
if (!server.IsConnected)
{
server.Close();
server = new NamedPipeServerStream("CSharpTrace");
reader = new StreamReader(server);
server.WaitForConnection();
}
strInformation = reader.ReadLine();
backgroundWorker.ReportProgress(1, strInformation);
}
}
void backgroundWorker_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
textboxInformation.Text += e.UserState + "\r\n";
}
}
}
// 客户端
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO.Pipes;
using System.Threading;
using System.IO;
namespace CSharpTraceDll
{
public class CSharpTraceDll
{
// 简易接口
public static void Debug(string strInformation)
{
Init();
WriteLine(strInformation);
}
// 初始化连接环境
public static void Init()
{
// 初始化命名管道
if (_client == null)
{
_client = new NamedPipeClientStream("_");
}
// 启动线程
if (_thread == null)
{
_thread = new Thread(new ThreadStart(ThreadRun));
_thread.IsBackground = true;
_thread.Start();
}
}
// 断开连接
public static void UnInit()
{
// 终止线程
if (_thread != null)
{
_thread.Abort();
_thread = null;
}
// 释放命名管道
if (_client != null)
{
_client.Close();
_client = null;
}
}
// 发送数据
public static void WriteLine(string strInformation)
{
// 检查合法性
if (_client == null) return;
if (_writer == null) return;
try
{
// 检查连接状态
if (_client.IsConnected)
{
// 发送信息
string strLine = string.Format("[{0}]:{1}", System.DateTime.Now.ToString(), strInformation);
_writer.WriteLine(strLine);
}
}
catch (Exception e)
{
// 捕获连接异常
Console.WriteLine(e.Message);
}
}
// 内部线程
private static void ThreadRun()
{
while (true)
{
// 确保连接状态
if (!_client.IsConnected)
{
_client.Close();
_client = new NamedPipeClientStream(".", "CSharpTrace");
_writer = new StreamWriter(_client);
_client.Connect();
_writer.AutoFlush = true;
}
Thread.Sleep(1000);
}
}
private static NamedPipeClientStream _client;
private static StreamWriter _writer;
private static Thread _thread;
}
}
vs2010 c# 独立打印调试
每次使用Visual Studio C#的Debug.WriteLine调试。个人调试信息与系统调试信息混杂在一起,难以区分。
CSharpTraceServer,与CSharpTraceDll应此出现。
使用方法:
1.CSharpTraceServer。打开CSharpTraceServer.exe。
2.CSharpTraceDll。在个人项目中添加CSharpTraceDll.dll的引用。
3.使用如下接口开始调试:
CSharpTraceDll.CSharpTraceDll.Debug("打印信息");
使用例程:
Test(Test.exe)
c# 反射实例
//c# 反射实例
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
namespace ConsoleApplication1
{
class Program
{
static void Main( string[] args )
{
// 类型名,方法名,参数
string className = "ConsoleApplication1.A";
string methodName = "Fun";
string param = "param";
// 获取程序集
Assembly assembly = Assembly.GetExecutingAssembly();
// 取得类型,方法;定义参数
Type type = assembly.GetType(className);
MethodInfo method = type.GetMethod(methodName);
object[] parameters = new object[] { param };
// 创建实例;调用方法(传递参数,获取返回值)
object instance = assembly.CreateInstance(type.ToString());
string rt = (string)method.Invoke(instance, parameters);
// 打印输出
Console.WriteLine(rt);
Console.ReadKey();
}
}
class A
{
public string Fun(string param)
{
return "A.Fun:" + param;
}
}
}
vs2010 c# 独立打印调试工具
每次使用Visual Studio C#的Debug.WriteLine调试。个人调试信息与系统调试信息混杂在一起,难以区分。
CSharpTraceServer,与CSharpTraceDll应此出现。
使用方法:
1.CSharpTraceServer。打开CSharpTraceServer.exe。
2.CSharpTraceDll。在个人项目中添加CSharpTraceDll.dll的引用。
3.使用如下接口开始调试:
CSharpTraceDll.CSharpTraceDll.Debug("打印信息");
使用例程:
Test(Test.exe)