PageCompiler.cs 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540
  1. //
  2. // System.Web.Compilation.PageCompiler
  3. //
  4. // Authors:
  5. // Gonzalo Paniagua Javier ([email protected])
  6. //
  7. // (C) 2002,2003 Ximian, Inc (http://www.ximian.com)
  8. //
  9. //
  10. // Permission is hereby granted, free of charge, to any person obtaining
  11. // a copy of this software and associated documentation files (the
  12. // "Software"), to deal in the Software without restriction, including
  13. // without limitation the rights to use, copy, modify, merge, publish,
  14. // distribute, sublicense, and/or sell copies of the Software, and to
  15. // permit persons to whom the Software is furnished to do so, subject to
  16. // the following conditions:
  17. //
  18. // The above copyright notice and this permission notice shall be
  19. // included in all copies or substantial portions of the Software.
  20. //
  21. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  22. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  23. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  24. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  25. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  26. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  27. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  28. //
  29. using System;
  30. using System.CodeDom;
  31. using System.Collections;
  32. using System.Collections.Generic;
  33. using System.IO;
  34. using System.Reflection;
  35. using System.Text;
  36. using System.Web.Configuration;
  37. using System.Web.UI;
  38. using System.Web.SessionState;
  39. using System.Web.Util;
  40. using System.Web.Profile;
  41. namespace System.Web.Compilation
  42. {
  43. class PageCompiler : TemplateControlCompiler
  44. {
  45. PageParser pageParser;
  46. static CodeTypeReference intRef = new CodeTypeReference (typeof (int));
  47. public PageCompiler (PageParser pageParser)
  48. : base (pageParser)
  49. {
  50. this.pageParser = pageParser;
  51. }
  52. protected override void CreateStaticFields ()
  53. {
  54. base.CreateStaticFields ();
  55. CodeMemberField fld = new CodeMemberField (typeof (object), "__fileDependencies");
  56. fld.Attributes = MemberAttributes.Private | MemberAttributes.Static;
  57. fld.InitExpression = new CodePrimitiveExpression (null);
  58. mainClass.Members.Add (fld);
  59. if (pageParser.OutputCache) {
  60. fld = new CodeMemberField (typeof (OutputCacheParameters), "__outputCacheSettings");
  61. fld.Attributes = MemberAttributes.Private | MemberAttributes.Static;
  62. fld.InitExpression = new CodePrimitiveExpression (null);
  63. mainClass.Members.Add (fld);
  64. }
  65. }
  66. protected override void CreateConstructor (CodeStatementCollection localVars,
  67. CodeStatementCollection trueStmt)
  68. {
  69. if (!String.IsNullOrEmpty (pageParser.MasterPageFile))
  70. // This is here just to trigger master page build, so that its type
  71. // is available when compiling the page itself.
  72. BuildManager.GetCompiledType (pageParser.MasterPageFile);
  73. if (pageParser.ClientTarget != null) {
  74. CodeExpression prop;
  75. prop = new CodePropertyReferenceExpression (thisRef, "ClientTarget");
  76. CodeExpression ct = new CodePrimitiveExpression (pageParser.ClientTarget);
  77. if (localVars == null)
  78. localVars = new CodeStatementCollection ();
  79. localVars.Add (new CodeAssignStatement (prop, ct));
  80. }
  81. ArrayList deps = pageParser.Dependencies;
  82. int depsCount = deps != null ? deps.Count : 0;
  83. if (depsCount > 0) {
  84. if (localVars == null)
  85. localVars = new CodeStatementCollection ();
  86. if (trueStmt == null)
  87. trueStmt = new CodeStatementCollection ();
  88. CodeAssignStatement assign;
  89. localVars.Add (
  90. new CodeVariableDeclarationStatement (
  91. typeof (string[]),
  92. "dependencies")
  93. );
  94. CodeVariableReferenceExpression dependencies = new CodeVariableReferenceExpression ("dependencies");
  95. trueStmt.Add (
  96. new CodeAssignStatement (dependencies, new CodeArrayCreateExpression (typeof (string), depsCount))
  97. );
  98. CodeArrayIndexerExpression arrayIndex;
  99. object o;
  100. for (int i = 0; i < depsCount; i++) {
  101. o = deps [i];
  102. arrayIndex = new CodeArrayIndexerExpression (dependencies, new CodeExpression[] {new CodePrimitiveExpression (i)});
  103. assign = new CodeAssignStatement (arrayIndex, new CodePrimitiveExpression (o));
  104. trueStmt.Add (assign);
  105. }
  106. CodeMethodInvokeExpression getDepsCall = new CodeMethodInvokeExpression (
  107. thisRef,
  108. "GetWrappedFileDependencies",
  109. new CodeExpression[] {dependencies}
  110. );
  111. assign = new CodeAssignStatement (GetMainClassFieldReferenceExpression ("__fileDependencies"), getDepsCall);
  112. trueStmt.Add (assign);
  113. }
  114. base.CreateConstructor (localVars, trueStmt);
  115. }
  116. protected override void AddInterfaces ()
  117. {
  118. base.AddInterfaces ();
  119. CodeTypeReference cref;
  120. if (pageParser.EnableSessionState) {
  121. cref = new CodeTypeReference (typeof (IRequiresSessionState));
  122. if (partialClass != null)
  123. partialClass.BaseTypes.Add (cref);
  124. else
  125. mainClass.BaseTypes.Add (cref);
  126. }
  127. if (pageParser.ReadOnlySessionState) {
  128. cref = new CodeTypeReference (typeof (IReadOnlySessionState));
  129. if (partialClass != null)
  130. partialClass.BaseTypes.Add (cref);
  131. else
  132. mainClass.BaseTypes.Add (cref);
  133. }
  134. if (pageParser.Async)
  135. mainClass.BaseTypes.Add (new CodeTypeReference (typeof (System.Web.IHttpAsyncHandler)));
  136. mainClass.BaseTypes.Add (new CodeTypeReference (typeof (System.Web.IHttpHandler)));
  137. }
  138. void CreateGetTypeHashCode ()
  139. {
  140. CodeMemberMethod method = new CodeMemberMethod ();
  141. method.ReturnType = intRef;
  142. method.Name = "GetTypeHashCode";
  143. method.Attributes = MemberAttributes.Public | MemberAttributes.Override;
  144. Random rnd = new Random (pageParser.InputFile.GetHashCode ());
  145. method.Statements.Add (new CodeMethodReturnStatement (new CodePrimitiveExpression (rnd.Next ())));
  146. mainClass.Members.Add (method);
  147. }
  148. static CodeExpression GetExpressionForValueAndType (object value, Type valueType)
  149. {
  150. // Put short circuit types here
  151. if (valueType == typeof (TimeSpan)) {
  152. CodeMethodReferenceExpression mref = new CodeMethodReferenceExpression (
  153. new CodeTypeReferenceExpression (typeof (TimeSpan)),
  154. "Parse");
  155. return new CodeMethodInvokeExpression (
  156. mref,
  157. new CodeExpression[] { new CodePrimitiveExpression (((TimeSpan) value).ToString ()) }
  158. );
  159. }
  160. throw new HttpException (String.Format ("Unable to create assign expression for type '{0}'.", valueType));
  161. }
  162. static CodeAssignStatement CreatePropertyAssign (CodeExpression expr, string name, object value)
  163. {
  164. CodeExpression rhs;
  165. if (value == null || value is string)
  166. rhs = new CodePrimitiveExpression (value);
  167. else {
  168. Type vt = value.GetType ();
  169. if (vt.IsPrimitive)
  170. rhs = new CodePrimitiveExpression (value);
  171. else
  172. rhs = GetExpressionForValueAndType (value, vt);
  173. }
  174. return new CodeAssignStatement (new CodePropertyReferenceExpression (expr, name), rhs);
  175. }
  176. static CodeAssignStatement CreatePropertyAssign (string name, object value)
  177. {
  178. return CreatePropertyAssign (thisRef, name, value);
  179. }
  180. void AddStatementsFromDirective (CodeMemberMethod method)
  181. {
  182. string responseEncoding = pageParser.ResponseEncoding;
  183. if (responseEncoding != null)
  184. method.Statements.Add (CreatePropertyAssign ("ResponseEncoding", responseEncoding));
  185. int codepage = pageParser.CodePage;
  186. if (codepage != -1)
  187. method.Statements.Add (CreatePropertyAssign ("CodePage", codepage));
  188. string contentType = pageParser.ContentType;
  189. if (contentType != null)
  190. method.Statements.Add (CreatePropertyAssign ("ContentType", contentType));
  191. int lcid = pageParser.LCID;
  192. if (lcid != -1)
  193. method.Statements.Add (CreatePropertyAssign ("LCID", lcid));
  194. string culture = pageParser.Culture;
  195. if (culture != null)
  196. method.Statements.Add (CreatePropertyAssign ("Culture", culture));
  197. culture = pageParser.UICulture;
  198. if (culture != null)
  199. method.Statements.Add (CreatePropertyAssign ("UICulture", culture));
  200. string errorPage = pageParser.ErrorPage;
  201. if (errorPage != null)
  202. method.Statements.Add (CreatePropertyAssign ("ErrorPage", errorPage));
  203. if (pageParser.HaveTrace) {
  204. CodeAssignStatement stmt = new CodeAssignStatement ();
  205. stmt.Left = new CodePropertyReferenceExpression (thisRef, "TraceEnabled");
  206. stmt.Right = new CodePrimitiveExpression (pageParser.Trace);
  207. method.Statements.Add (stmt);
  208. }
  209. if (pageParser.TraceMode != TraceMode.Default) {
  210. CodeAssignStatement stmt = new CodeAssignStatement ();
  211. CodeTypeReferenceExpression tm = new CodeTypeReferenceExpression ("System.Web.TraceMode");
  212. stmt.Left = new CodePropertyReferenceExpression (thisRef, "TraceModeValue");
  213. stmt.Right = new CodeFieldReferenceExpression (tm, pageParser.TraceMode.ToString ());
  214. method.Statements.Add (stmt);
  215. }
  216. if (pageParser.NotBuffer) {
  217. CodeAssignStatement stmt = new CodeAssignStatement ();
  218. stmt.Left = new CodePropertyReferenceExpression (thisRef, "Buffer");
  219. stmt.Right = new CodePrimitiveExpression (false);
  220. method.Statements.Add (stmt);
  221. }
  222. if (!pageParser.EnableEventValidation) {
  223. CodeAssignStatement stmt = new CodeAssignStatement ();
  224. CodePropertyReferenceExpression prop;
  225. prop = new CodePropertyReferenceExpression (thisRef, "EnableEventValidation");
  226. stmt.Left = prop;
  227. stmt.Right = new CodePrimitiveExpression (pageParser.EnableEventValidation);
  228. method.Statements.Add (stmt);
  229. }
  230. if (pageParser.MaintainScrollPositionOnPostBack) {
  231. CodeAssignStatement stmt = new CodeAssignStatement ();
  232. CodePropertyReferenceExpression prop;
  233. prop = new CodePropertyReferenceExpression (thisRef, "MaintainScrollPositionOnPostBack");
  234. stmt.Left = prop;
  235. stmt.Right = new CodePrimitiveExpression (pageParser.MaintainScrollPositionOnPostBack);
  236. method.Statements.Add (stmt);
  237. }
  238. }
  239. protected override void AddStatementsToConstructor (CodeConstructor ctor)
  240. {
  241. base.AddStatementsToConstructor (ctor);
  242. if (pageParser.OutputCache)
  243. OutputCacheParamsBlock (ctor);
  244. }
  245. protected override void AddStatementsToInitMethod (CodeMemberMethod method)
  246. {
  247. AddStatementsFromDirective (method);
  248. ILocation directiveLocation = pageParser.DirectiveLocation;
  249. CodeArgumentReferenceExpression ctrlVar = new CodeArgumentReferenceExpression("__ctrl");
  250. if (pageParser.Title != null)
  251. method.Statements.Add (AddLinePragma (CreatePropertyAssign (ctrlVar, "Title", pageParser.Title), directiveLocation));
  252. if (pageParser.MasterPageFile != null)
  253. method.Statements.Add (AddLinePragma (CreatePropertyAssign (ctrlVar, "MasterPageFile", pageParser.MasterPageFile), directiveLocation));
  254. if (pageParser.Theme != null)
  255. method.Statements.Add (AddLinePragma (CreatePropertyAssign (ctrlVar, "Theme", pageParser.Theme), directiveLocation));
  256. if (pageParser.StyleSheetTheme != null)
  257. method.Statements.Add (AddLinePragma (CreatePropertyAssign (ctrlVar, "StyleSheetTheme", pageParser.StyleSheetTheme), directiveLocation));
  258. if (pageParser.Async != false)
  259. method.Statements.Add (AddLinePragma (CreatePropertyAssign (ctrlVar, "AsyncMode", pageParser.Async), directiveLocation));
  260. if (pageParser.AsyncTimeout != -1)
  261. method.Statements.Add (AddLinePragma (CreatePropertyAssign (ctrlVar, "AsyncTimeout",
  262. TimeSpan.FromSeconds (pageParser.AsyncTimeout)), directiveLocation));
  263. CodeMethodInvokeExpression expr = new CodeMethodInvokeExpression (thisRef, "InitializeCulture");
  264. method.Statements.Add (AddLinePragma (new CodeExpressionStatement (expr), directiveLocation));
  265. }
  266. protected override void PrependStatementsToFrameworkInitialize (CodeMemberMethod method)
  267. {
  268. base.PrependStatementsToFrameworkInitialize (method);
  269. if (pageParser.StyleSheetTheme != null)
  270. method.Statements.Add (CreatePropertyAssign ("StyleSheetTheme", pageParser.StyleSheetTheme));
  271. }
  272. protected override void AppendStatementsToFrameworkInitialize (CodeMemberMethod method)
  273. {
  274. base.AppendStatementsToFrameworkInitialize (method);
  275. ArrayList deps = pageParser.Dependencies;
  276. int depsCount = deps != null ? deps.Count : 0;
  277. if (depsCount > 0) {
  278. CodeFieldReferenceExpression fileDependencies = GetMainClassFieldReferenceExpression ("__fileDependencies");
  279. method.Statements.Add (
  280. new CodeMethodInvokeExpression (
  281. thisRef,
  282. "AddWrappedFileDependencies",
  283. new CodeExpression[] {fileDependencies})
  284. );
  285. }
  286. if (pageParser.OutputCache) {
  287. CodeMethodReferenceExpression init = new CodeMethodReferenceExpression (thisRef, "InitOutputCache");
  288. CodeMethodInvokeExpression invoke = new CodeMethodInvokeExpression (init, GetMainClassFieldReferenceExpression ("__outputCacheSettings"));
  289. method.Statements.Add (invoke);
  290. }
  291. if (pageParser.ValidateRequest) {
  292. CodeMethodInvokeExpression expr = new CodeMethodInvokeExpression ();
  293. CodePropertyReferenceExpression prop;
  294. prop = new CodePropertyReferenceExpression (thisRef, "Request");
  295. expr.Method = new CodeMethodReferenceExpression (prop, "ValidateInput");
  296. method.Statements.Add (expr);
  297. }
  298. if (!pageParser.EnableViewStateMac) {
  299. CodeAssignStatement stmt = new CodeAssignStatement ();
  300. stmt.Left = new CodePropertyReferenceExpression (thisRef, "EnableViewStateMac");
  301. stmt.Right = new CodePrimitiveExpression (false);
  302. method.Statements.Add (stmt);
  303. }
  304. }
  305. CodeAssignStatement AssignOutputCacheParameter (CodeVariableReferenceExpression variable, string propName, object value)
  306. {
  307. var ret = new CodeAssignStatement ();
  308. ret.Left = new CodeFieldReferenceExpression (variable, propName);
  309. if (value is OutputCacheLocation)
  310. ret.Right = new CodeFieldReferenceExpression (
  311. new CodeTypeReferenceExpression (new CodeTypeReference (typeof (OutputCacheLocation), CodeTypeReferenceOptions.GlobalReference)),
  312. value.ToString ()
  313. );
  314. else
  315. ret.Right = new CodePrimitiveExpression (value);
  316. return ret;
  317. }
  318. void OutputCacheParamsBlock (CodeMemberMethod method)
  319. {
  320. var statements = new List <CodeStatement> ();
  321. var localSettingsDecl = new CodeVariableDeclarationStatement (typeof (OutputCacheParameters), "outputCacheSettings");
  322. var localSettings = new CodeVariableReferenceExpression ("outputCacheSettings");
  323. statements.Add (localSettingsDecl);
  324. statements.Add (
  325. new CodeAssignStatement (
  326. localSettings,
  327. new CodeObjectCreateExpression (typeof (OutputCacheParameters), new CodeExpression[] {})
  328. )
  329. );
  330. TemplateParser.OutputCacheParsedParams parsed = pageParser.OutputCacheParsedParameters;
  331. if ((parsed & TemplateParser.OutputCacheParsedParams.CacheProfile) != 0)
  332. statements.Add (AssignOutputCacheParameter (localSettings, "CacheProfile", pageParser.OutputCacheCacheProfile));
  333. statements.Add (AssignOutputCacheParameter (localSettings, "Duration", pageParser.OutputCacheDuration));
  334. if ((parsed & TemplateParser.OutputCacheParsedParams.Location) != 0)
  335. statements.Add (AssignOutputCacheParameter (localSettings, "Location", pageParser.OutputCacheLocation));
  336. if ((parsed & TemplateParser.OutputCacheParsedParams.NoStore) != 0)
  337. statements.Add (AssignOutputCacheParameter (localSettings, "NoStore", pageParser.OutputCacheNoStore));
  338. if ((parsed & TemplateParser.OutputCacheParsedParams.SqlDependency) != 0)
  339. statements.Add (AssignOutputCacheParameter (localSettings, "SqlDependency", pageParser.OutputCacheSqlDependency));
  340. if ((parsed & TemplateParser.OutputCacheParsedParams.VaryByContentEncodings) != 0)
  341. statements.Add (AssignOutputCacheParameter (localSettings, "VaryByContentEncoding", pageParser.OutputCacheVaryByContentEncodings));
  342. if ((parsed & TemplateParser.OutputCacheParsedParams.VaryByControl) != 0)
  343. statements.Add (AssignOutputCacheParameter (localSettings, "VaryByControl", pageParser.OutputCacheVaryByControls));
  344. if ((parsed & TemplateParser.OutputCacheParsedParams.VaryByCustom) != 0)
  345. statements.Add (AssignOutputCacheParameter (localSettings, "VaryByCustom", pageParser.OutputCacheVaryByCustom));
  346. if ((parsed & TemplateParser.OutputCacheParsedParams.VaryByHeader) != 0)
  347. statements.Add (AssignOutputCacheParameter (localSettings, "VaryByHeader", pageParser.OutputCacheVaryByHeader));
  348. statements.Add (AssignOutputCacheParameter (localSettings, "VaryByParam", pageParser.OutputCacheVaryByParam));
  349. CodeFieldReferenceExpression outputCacheSettings = GetMainClassFieldReferenceExpression ("__outputCacheSettings");
  350. statements.Add (new CodeAssignStatement (outputCacheSettings, localSettings));
  351. var cond = new CodeConditionStatement (
  352. new CodeBinaryOperatorExpression (
  353. outputCacheSettings,
  354. CodeBinaryOperatorType.IdentityEquality,
  355. new CodePrimitiveExpression (null)
  356. ),
  357. statements.ToArray ()
  358. );
  359. method.Statements.Add (cond);
  360. }
  361. void CreateStronglyTypedProperty (Type type, string name)
  362. {
  363. if (type == null)
  364. return;
  365. CodeMemberProperty mprop = new CodeMemberProperty ();
  366. mprop.Name = name;
  367. mprop.Type = new CodeTypeReference (type);
  368. mprop.Attributes = MemberAttributes.Public | MemberAttributes.New;
  369. CodeExpression prop = new CodePropertyReferenceExpression (new CodeBaseReferenceExpression (), name);
  370. prop = new CodeCastExpression (type, prop);
  371. mprop.GetStatements.Add (new CodeMethodReturnStatement (prop));
  372. if (partialClass != null)
  373. partialClass.Members.Add (mprop);
  374. else
  375. mainClass.Members.Add (mprop);
  376. AddReferencedAssembly (type.Assembly);
  377. }
  378. protected internal override void CreateMethods ()
  379. {
  380. base.CreateMethods ();
  381. CreateProfileProperty ();
  382. CreateStronglyTypedProperty (pageParser.MasterType, "Master");
  383. CreateStronglyTypedProperty (pageParser.PreviousPageType, "PreviousPage");
  384. CreateGetTypeHashCode ();
  385. if (pageParser.Async)
  386. CreateAsyncMethods ();
  387. }
  388. void CreateAsyncMethods ()
  389. {
  390. CodeMemberMethod method = new CodeMemberMethod ();
  391. CodeParameterDeclarationExpression arg;
  392. CodeMethodInvokeExpression invoke;
  393. // public virtual System.IAsyncResult BeginProcessRequest(System.Web.HttpContext context, System.AsyncCallback cb, object data);
  394. method.ReturnType = new CodeTypeReference (typeof (IAsyncResult));
  395. method.Name = "BeginProcessRequest";
  396. method.Attributes = MemberAttributes.Public;
  397. arg = new CodeParameterDeclarationExpression ();
  398. arg.Type = new CodeTypeReference (typeof (HttpContext));
  399. arg.Name = "context";
  400. method.Parameters.Add (arg);
  401. arg = new CodeParameterDeclarationExpression ();
  402. arg.Type = new CodeTypeReference (typeof (AsyncCallback));
  403. arg.Name = "cb";
  404. method.Parameters.Add (arg);
  405. arg = new CodeParameterDeclarationExpression ();
  406. arg.Type = new CodeTypeReference (typeof (object));
  407. arg.Name = "data";
  408. method.Parameters.Add (arg);
  409. invoke = new CodeMethodInvokeExpression (thisRef, "AsyncPageBeginProcessRequest");
  410. invoke.Parameters.Add (new CodeArgumentReferenceExpression ("context"));
  411. invoke.Parameters.Add (new CodeArgumentReferenceExpression ("cb"));
  412. invoke.Parameters.Add (new CodeArgumentReferenceExpression ("data"));
  413. method.Statements.Add (new CodeMethodReturnStatement (invoke));
  414. mainClass.Members.Add (method);
  415. // public virtual void EndProcessRequest(System.IAsyncResult ar);
  416. method = new CodeMemberMethod ();
  417. method.ReturnType = new CodeTypeReference (typeof (void));
  418. method.Name = "EndProcessRequest";
  419. method.Attributes = MemberAttributes.Public;
  420. arg = new CodeParameterDeclarationExpression ();
  421. arg.Type = new CodeTypeReference (typeof (IAsyncResult));
  422. arg.Name = "ar";
  423. method.Parameters.Add (arg);
  424. invoke = new CodeMethodInvokeExpression (thisRef, "AsyncPageEndProcessRequest");
  425. invoke.Parameters.Add (new CodeArgumentReferenceExpression ("ar"));
  426. method.Statements.Add (invoke);
  427. mainClass.Members.Add (method);
  428. // public override void ProcessRequest(System.Web.HttpContext context);
  429. method = new CodeMemberMethod ();
  430. method.ReturnType = new CodeTypeReference (typeof (void));
  431. method.Name = "ProcessRequest";
  432. method.Attributes = MemberAttributes.Public | MemberAttributes.Override;
  433. arg = new CodeParameterDeclarationExpression ();
  434. arg.Type = new CodeTypeReference (typeof (HttpContext));
  435. arg.Name = "context";
  436. method.Parameters.Add (arg);
  437. invoke = new CodeMethodInvokeExpression (new CodeBaseReferenceExpression (), "ProcessRequest");
  438. invoke.Parameters.Add (new CodeArgumentReferenceExpression ("context"));
  439. method.Statements.Add (invoke);
  440. mainClass.Members.Add (method);
  441. }
  442. public static Type CompilePageType (PageParser pageParser)
  443. {
  444. PageCompiler compiler = new PageCompiler (pageParser);
  445. return compiler.GetCompiledType ();
  446. }
  447. }
  448. }