1+ #region README
2+
3+ /*
4+ * README
5+ *
6+ * Current Thread User : GUOCOLAND\wangyucai
7+ * Machine Name : GLCHQWYCWINW7
8+ * Visual Studio : Microsoft Visual Studio 2010 Ultimate Edition
9+ * Create Time : 2014-11-20 16:23:34
10+ * Common Language Runtime : 4.0.30319.18444
11+ * Minimum .Net Framework Version : 4.0
12+ *
13+ * SourcePro Studio 2014
14+ * Project Url : https://github.com/SourceproStudio/CodeTemplates
15+ * Home Page Url : https://github.com/SourceproStudio
16+ * E-mail Address : MasterDuner@yeah.net or Yucai.Wang-Public@outlook.com
17+ * QQ : 180261899
18+ */
19+
20+ #endregion
21+
22+ using System . ComponentModel ;
23+ using System . IO ;
24+ using System . Text . RegularExpressions ;
25+
26+ namespace SourcePro . Csharp . Lab . Entity
27+ {
28+ /// <summary>
29+ /// <para>
30+ /// 定义了程序集信息实体。
31+ /// </para>
32+ /// <para>
33+ /// Namespace : <see cref="SourcePro.Csharp.Lab.Entity"/>
34+ /// </para>
35+ /// <para>
36+ /// Type : <see cref="AssemblyInformation"/>
37+ /// </para>
38+ /// <para>
39+ /// The minimum .Net Framework version requirements : 4.0
40+ /// </para>
41+ /// <para>
42+ /// Can not inherit from <see cref="AssemblyInformation"/> !
43+ /// </para>
44+ /// </summary>
45+ /// <seealso cref="SourcePro.Csharp.Lab.Entity"/>
46+ /// <remarks>
47+ /// Can not inherit from <see cref="AssemblyInformation"/> !
48+ /// </remarks>
49+ public sealed class AssemblyInformation
50+ {
51+ private AssemblyVersion _version ;
52+ private string _title ;
53+ private string _description ;
54+ private string _companyName ;
55+ private string _productName ;
56+ private string _copyright ;
57+ private string _trademark ;
58+ private const string AssemblyTitle = @"^\[assembly\s?:\s*AssemblyTitle\(\""(?<AssemblyTitle>[\u0020\u0021\u0023-\uFFFF]*)\""\)]" ;
59+ private const string AssemblyDescription = @"^\[assembly\s?:\s*AssemblyDescription\(\""(?<AssemblyDescription>[\u0020\u0021\u0023-\uFFFF]*)\""\)]" ;
60+ private const string AssemblyCompany = @"^\[assembly\s?:\s*AssemblyCompany\(\""(?<AssemblyCompany>[\u0020\u0021\u0023-\uFFFF]*)\""\)]" ;
61+ private const string AssemblyProduct = @"^\[assembly\s?:\s*AssemblyProduct\(\""(?<AssemblyProduct>[\u0020\u0021\u0023-\uFFFF]*)\""\)]" ;
62+ private const string AssemblyCopyright = @"^\[assembly\s?:\s*AssemblyCopyright\(\""(?<AssemblyCopyright>[\u0020\u0021\u0023-\uFFFF]*)\""\)]" ;
63+ private const string AssemblyTrademark = @"^\[assembly\s?:\s*AssemblyTrademark\(\""(?<AssemblyTrademark>[\u0020\u0021\u0023-\uFFFF]*)\""\)]" ;
64+
65+ #region AssemblyInformation Constructors
66+
67+ /// <summary>
68+ /// <para>
69+ /// 用于初始化一个<see cref="AssemblyInformation" />对象实例。
70+ /// </para>
71+ /// </summary>
72+ public AssemblyInformation ( )
73+ {
74+ this . Version = new AssemblyVersion ( ) ;
75+ }
76+
77+ #endregion
78+
79+ #region Version
80+ /// <summary>
81+ /// 设置或获取程序集版本信息。
82+ /// </summary>
83+ [ Description ( "Set or get the assembly's version information." ) ]
84+ [ Category ( "Base Information" ) ]
85+ [ TypeConverter ( typeof ( ExpandableObjectConverter ) ) ]
86+ public AssemblyVersion Version
87+ {
88+ get { return _version ; }
89+ set { _version = value ; }
90+ }
91+ #endregion
92+
93+ #region Title
94+ /// <summary>
95+ /// 设置或获取程序集标题。
96+ /// </summary>
97+ [ Description ( "Set or get the assembly's title." ) ]
98+ [ Category ( "Base Information" ) ]
99+ public string Title
100+ {
101+ get { return _title ; }
102+ set { _title = value ; }
103+ }
104+ #endregion
105+
106+ #region Description
107+ /// <summary>
108+ /// 设置或获取程序集的描述信息。
109+ /// </summary>
110+ [ Description ( "Set or get the assembly's description." ) ]
111+ [ Category ( "Base Information" ) ]
112+ public string Description
113+ {
114+ get { return _description ; }
115+ set { _description = value ; }
116+ }
117+ #endregion
118+
119+ #region CompanyName
120+ /// <summary>
121+ /// 设置或获取发布程序集的公司名称。
122+ /// </summary>
123+ [ Description ( "Set or get the publishing company name of the assembly." ) ]
124+ [ Category ( "Base Information" ) ]
125+ public string CompanyName
126+ {
127+ get { return _companyName ; }
128+ set { _companyName = value ; }
129+ }
130+ #endregion
131+
132+ #region ProductName
133+ /// <summary>
134+ /// 设置或获取产品名称。
135+ /// </summary>
136+ [ Description ( "Set or set product name of the assembly." ) ]
137+ [ Category ( "Base Information" ) ]
138+ public string ProductName
139+ {
140+ get { return _productName ; }
141+ set { _productName = value ; }
142+ }
143+ #endregion
144+
145+ #region Copyright
146+ /// <summary>
147+ /// 设置或获取程序集的版权声明。
148+ /// </summary>
149+ [ Description ( "Set or get copyright declaration of the assembly." ) ]
150+ [ Category ( "Base Information" ) ]
151+ public string Copyright
152+ {
153+ get { return _copyright ; }
154+ set { _copyright = value ; }
155+ }
156+ #endregion
157+
158+ #region Trademark
159+ /// <summary>
160+ /// 设置或获取程序集的商标。
161+ /// </summary>
162+ [ Description ( "Set or get trademark of the assembly." ) ]
163+ [ Category ( "Base Information" ) ]
164+ public string Trademark
165+ {
166+ get { return _trademark ; }
167+ set { _trademark = value ; }
168+ }
169+ #endregion
170+
171+ #region Create
172+ /// <summary>
173+ /// 从模板文件创建<see cref="AssemblyInformation"/>对象实例。
174+ /// </summary>
175+ /// <param name="fileName">模板文件名称。</param>
176+ /// <returns><see cref="AssemblyInformation"/>对象实例。</returns>
177+ static public AssemblyInformation Create ( string fileName )
178+ {
179+ AssemblyInformation info = new AssemblyInformation ( ) ;
180+ if ( ! File . Exists ( fileName ) )
181+ {
182+ return info ;
183+ }
184+ else
185+ {
186+ using ( Stream templateStream = File . OpenRead ( fileName ) )
187+ {
188+ using ( StreamReader reader = new StreamReader ( templateStream ) )
189+ {
190+ try
191+ {
192+ while ( ! reader . EndOfStream )
193+ {
194+ SetProperties ( reader . ReadLine ( ) , info ) ;
195+ }
196+ }
197+ finally
198+ {
199+ reader . Close ( ) ;
200+ templateStream . Close ( ) ;
201+ }
202+ }
203+ }
204+ }
205+ return info ;
206+ }
207+ #endregion
208+
209+ #region SetProperties
210+ /// <summary>
211+ /// 设置属性值。
212+ /// </summary>
213+ /// <param name="s">当前行的文本内容。</param>
214+ /// <param name="instance">新创建的<see cref="AssemblyInformation"/>对象实例。</param>
215+ private static void SetProperties ( string s , AssemblyInformation instance )
216+ {
217+ if ( ! string . IsNullOrWhiteSpace ( s ) )
218+ {
219+ if ( Regex . IsMatch ( s , AssemblyTitle ) ) instance . Title = Regex . Match ( s , AssemblyTitle ) . Groups [ "AssemblyTitle" ] . Value ;
220+ if ( Regex . IsMatch ( s , AssemblyDescription ) ) instance . Description = Regex . Match ( s , AssemblyDescription ) . Groups [ "AssemblyDescription" ] . Value ;
221+ if ( Regex . IsMatch ( s , AssemblyCompany ) ) instance . CompanyName = Regex . Match ( s , AssemblyCompany ) . Groups [ "AssemblyCompany" ] . Value ;
222+ if ( Regex . IsMatch ( s , AssemblyProduct ) ) instance . ProductName = Regex . Match ( s , AssemblyProduct ) . Groups [ "AssemblyProduct" ] . Value ;
223+ if ( Regex . IsMatch ( s , AssemblyCopyright ) ) instance . Copyright = Regex . Match ( s , AssemblyCopyright ) . Groups [ "AssemblyCopyright" ] . Value ;
224+ if ( Regex . IsMatch ( s , AssemblyTrademark ) ) instance . Trademark = Regex . Match ( s , AssemblyTrademark ) . Groups [ "AssemblyTrademark" ] . Value ;
225+ if ( AssemblyVersion . IsMatchAssemblyVersion ( s ) ) instance . Version = AssemblyVersion . Create ( s ) ;
226+ }
227+ }
228+ #endregion
229+ }
230+ }
231+
232+ /*
233+ * Copyright © 2014 Wang Yucai. All rights reserved.
234+ */
0 commit comments