博文
使用SandCastle生成API文档(2010-03-11 05:15:00)
摘要:1.安装
在http://www.codeplex.com/Sandcastle下载安装文件。
2. 程序安装好后,检查是否有环境变量”DXROOT”,该环境变量即为SandCastle的安装路径。
3. 使用SandCastle生成API文档。
(1) 假设我们有一个VS项目,生成一个程序集SharedDemo.dll;
(2)对该项目生成xml 注释文件;
项目属性 -> Build ->
(3) 将%DXROOT %\Examples\sandcastle\build_Sandcastle.bat复制到与SharedDemo.xml和SharedDemo.dll同一个目录下。
(4) 打开命令提示符,进到 SharedDemo.dll的目录下,运行下面的命令
build_Sandcastle.bat vs2005 SharedDemo
注意,最后一个参数是”SharedDemo”而不是”SharedDemo.dll”
(5)在当前目录下,API文档被生成在chm文件夹内......
如何使用嵌入资源(2010-02-14 00:55:00)
摘要:假如我们要使用两幅图片,并把它们编译到DLL中去。
首先我们要把这些图片的属性进行修改,
然后我们还需要以下的代码,
[assembly: WebResource("WebApplication2.adobe.jpg", "image/jpg")]
[assembly: WebResource("WebApplication2.img.xx.gif", "image/gif")]
这些代码可以放在AssemblyInfo.cs中,也可以放到其他地方,比如像下面这样
[assembly: WebResource("WebApplication2.adobe.jpg", "image/jpg")]
[assembly: WebResource("WebApplication2.img.xx.gif", "image/gif")]
namespace WebApplication2
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
this.Image1.ImageUrl = Page.ClientScript.GetWebResourceUrl(typeof(_Default), "WebApplication2.img.xx.gif");
}
}
}
最后在使用的时候要像上面代码中Page.ClientScript.GetWebResourceUrl那样使用。......
浅谈ViewState(2010-02-03 16:54:00)
摘要:参见《Pro ASP.NET 3.5 in C# 2008》
Once your page code(.aspx) has finished running(and just before the final HTML is rendered and sent to the client), ASP.NET examines all the properties(.aspx) of all the controls on your page. If any of these properties has been changed from its initial state, ASP.NET makes a note of this information in a name/value collection. Finally, ASP.NET takes all the information it has amassed and then serializes it as a Base64 string. (A Base64 string ensures that there aren’t any special characters that wouldn’t be valid HTML.) The final string is inserted in the <form> section of the page as a new hidden field.
The next time the page is posted back, ASP.NET follows these steps:
1. ASP.NET re-creates the page and control objects based on its default(as defined in the .aspx file). Thus, the page has the same state that it had when it was first requested.
2. Next, ASP.N......
C# 命名空间嵌套(2009-11-26 00:20:00)
摘要:下面是一个简单的例子。注意 IBankAccount 是在 SaverAccount 的上一层命名空间。
由下面这个例子可以看出,嵌套的命名空间可以识别上层命名空间内的东西。
namespace Wrox.ProCSharp
{
public interface IBankAccount
{
void PayIn(decimal amount);
bool Withdraw(decimal amount);
decimal Balance
{
get;
}
}
}
namespace Wrox.ProCSharp.Vennus
{
public class SaverAccount : IBankAccount
{
private decimal balance;
public void PayIn(decimal amount)
{
......
C# 静态类(2009-11-24 20:36:00)
摘要:参见《C#高级编程》第四版
如果类只包含静态的方法和属性,该类就可以是静态的。不能创建静态类的实例。使用static 关键字,编译器可以检查以后是否给该类添加了实例成员。如果是,就生成一个编译错误。这可以确保不创建静态类的实例。
static class StaticUtilities
{
public static void HelperMethod()
{
}
}
调用HelperMethod()不需要StaticUtilities类型的对象。
StaticUtilities.HelperMethod();......
C# 只读字段(2009-11-24 19:13:00)
摘要:参考《C#高级编程》第四版
只读字段可以在构造函数中给只读字段赋值,但不能在其他地方赋值,只读字段还可以是一个实例字段,而不是静态字段,类的每个实例可以有不同的值。与const字段不同,如果要把字段设置为静态,就必须显式声明。
如果有一个编辑文档的MDI程序,因为要注册,需要限制可以同时打开的文档数。现在假定要销售该软件的不同版本,而且顾客可以升级他们的版本,以便同时打开更多的文档。显然,不能再源代码中队最大文档数进行硬编程。而是需要一个字段表示这个最大文档数。这个字段必须是只读的---每次安装程序时,从注册表或其他文件存储中读取。代码如下所示:
public class DocumentEditor
{
public static readonly uint MaxDocuments;
static DocumentEditor()
{
MaxDocuments = DoSomethingToFindOutMaxNumber();
}
}
在本例中,字段是静态的,因为每次运行程序的实例时,只需存储最大文档数一次。这就是在静态构造函数中初始化它的原因。如果只读字段是一个实例字段,就要在实例构造函数中初始化它。
public class Document
{
public readonly DateTime CreationDate;
......
C# 静态构造函数(2009-11-24 17:15:00)
摘要:
参见 《C# 高级编程》第四版
· 编写静态构造函数的一个原因是,类有一些静态字段或属性,需要在第一次使用类之前,从外部源中初始化这些静态字段和属性。
· 静态构造函数至多运行一次,即在代码引用类之前执行。
· 静态构造函数没有访问修饰符,其他C#代码从来不调用它,所以像public和private这样的访问修饰符就没有意义了。
· 静态构造函数不能带任何参数,一个类也只能有一个静态构造函数。
· 静态构造函数只能访问类的静态成员,不能访问实例成员。
下面给出一个实例:
public class UserPreferences
{
public static readonly Color BackColor;
static UserPreferences()
{
//read BackColor from out source;
}
// ...
}
class MainEntryPoint
{
static void Main()
{
&nb......
Getting the w3wp.exe Process ID(2009-11-23 19:42:00)
摘要:Often when you try to attach to the w3wp.exe process and debug an assembly there are multiple instances from which to choose. How do you know which one to pick?
Open a command prompt and run the iisapp.vbs script with no parameters as follows:
It will output a list of the currently running application pools and the associated PIDs.......
如何启动 Internet Information Services (IIS)(2009-11-23 02:58:00)
摘要:有两种方法:
(1)可以运行命令 inetmgr
(2)也可通过控制面板 --> 管理工具--> 来打开......
Web User Controls(2009-11-18 20:46:00)
摘要:Introduction to Web User Controls
The ASP.NET server controls provide a great deal of functionality, but they cannot cover every situation. Web user controls enable you to easily define controls as you need them for your applications, using the same programming techniques that you use to write Web Forms pages. You can even convert a Web Forms page into a Web user control with a few modifications. (For details see Walkthrough: Converting a Web Forms Page to a User Control.) To make sure that a user control cannot be run as a standalone Web Forms page, user controls are identified by the file name extension .ascx.
Note Web user controls are not to be confused with Web custom controls. For more information, see Recommendations for Web User Controls vs. Web Custom Controls.
User Control Structure
A Web user control is similar to a complete Web Forms page, with both a user interface page and a code-behind file. The user interface page differs from an .aspx file in these......
