#region和#endregion指令用于把一段代码标记为有给定名称的一个块,从而使代码在屏幕上更好地布局。例如:
/// <summary>
/// Parses one line in a GEDCOM file.
/// </summary>
class GedcomLine
{
#region fields
// Parts of the GEDCOM line.
private int level;
private string tag;
private string data;
// Expression pattern used to parse the GEDCOM line.
private readonly Regex regSplit = new Regex(
@"(?<level>/d+)/s+(?<tag>[/S]+)(/s+(?<data>.+))?");
// Expression pattern used to clean up the GEDCOM line.
// Only allow viewable characters.
private readonly Regex regClean = new Regex(@"[^/x20-/x7e]");
// Expression pattern used to clean up the GEDCOM tag.
// Tag can contain alphanumeric characters, _, ., or -.
private readonly Regex regTag = new Regex(@"[^/w.-]");
#endregion
#region properties
/// <summary>
/// Level of the tag.
/// </summary>
public int Level
{
get { return this.level; }
set { this.level = value; }
}
/// <summary>
/// Line tag.
/// </summary>
public string Tag
{
get { return this.tag; }
set { this.tag = value; }
}
/// <summary>
/// Data of the tag.
/// </summary>
public string Data
{
get { return this.data; }
set { this.data = value; }
}
#endregion
.
.
.
}
在VS编辑视图下就可以缩小为:
/// <summary>
/// Parses one line in a GEDCOM file.
/// </summary>
class GedcomLine
{
fields
properties
.
.
.
}