PageCompiler.cs 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569
  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. MainDirectiveAttribute <string> masterPageFile = pageParser.MasterPageFile;
  70. if (masterPageFile != null && !masterPageFile.IsExpression)
  71. // This is here just to trigger master page build, so that its type
  72. // is available when compiling the page itself.
  73. BuildManager.GetCompiledType (masterPageFile.Value);
  74. MainDirectiveAttribute <string> clientTarget;
  75. clientTarget = pageParser.ClientTarget;
  76. if (clientTarget != null) {
  77. CodeExpression prop;
  78. prop = new CodePropertyReferenceExpression (thisRef, "ClientTarget");
  79. CodeExpression ct = null;
  80. if (clientTarget.IsExpression) {
  81. var pi = GetFieldOrProperty (typeof (Page), "ClientTarget") as PropertyInfo;
  82. if (pi != null)
  83. ct = CompileExpression (pi, pi.PropertyType, clientTarget.UnparsedValue, false);
  84. }
  85. if (ct == null)
  86. ct = new CodePrimitiveExpression (clientTarget.Value);
  87. if (localVars == null)
  88. localVars = new CodeStatementCollection ();
  89. localVars.Add (new CodeAssignStatement (prop, ct));
  90. }
  91. ArrayList deps = pageParser.Dependencies;
  92. int depsCount = deps != null ? deps.Count : 0;
  93. if (depsCount > 0) {
  94. if (localVars == null)
  95. localVars = new CodeStatementCollection ();
  96. if (trueStmt == null)
  97. trueStmt = new CodeStatementCollection ();
  98. CodeAssignStatement assign;
  99. localVars.Add (
  100. new CodeVariableDeclarationStatement (
  101. typeof (string[]),
  102. "dependencies")
  103. );
  104. CodeVariableReferenceExpression dependencies = new CodeVariableReferenceExpression ("dependencies");
  105. trueStmt.Add (
  106. new CodeAssignStatement (dependencies, new CodeArrayCreateExpression (typeof (string), depsCount))
  107. );
  108. CodeArrayIndexerExpression arrayIndex;
  109. object o;
  110. for (int i = 0; i < depsCount; i++) {
  111. o = deps [i];
  112. arrayIndex = new CodeArrayIndexerExpression (dependencies, new CodeExpression[] {new CodePrimitiveExpression (i)});
  113. assign = new CodeAssignStatement (arrayIndex, new CodePrimitiveExpression (o));
  114. trueStmt.Add (assign);
  115. }
  116. CodeMethodInvokeExpression getDepsCall = new CodeMethodInvokeExpression (
  117. thisRef,
  118. "GetWrappedFileDependencies",
  119. new CodeExpression[] {dependencies}
  120. );
  121. assign = new CodeAssignStatement (GetMainClassFieldReferenceExpression ("__fileDependencies"), getDepsCall);
  122. trueStmt.Add (assign);
  123. }
  124. base.CreateConstructor (localVars, trueStmt);
  125. }
  126. protected override void AddInterfaces ()
  127. {
  128. base.AddInterfaces ();
  129. CodeTypeReference cref;
  130. if (pageParser.EnableSessionState) {
  131. cref = new CodeTypeReference (typeof (IRequiresSessionState));
  132. if (partialClass != null)
  133. partialClass.BaseTypes.Add (cref);
  134. else
  135. mainClass.BaseTypes.Add (cref);
  136. }
  137. if (pageParser.ReadOnlySessionState) {
  138. cref = new CodeTypeReference (typeof (IReadOnlySessionState));
  139. if (partialClass != null)
  140. partialClass.BaseTypes.Add (cref);
  141. else
  142. mainClass.BaseTypes.Add (cref);
  143. }
  144. if (pageParser.Async)
  145. mainClass.BaseTypes.Add (new CodeTypeReference (typeof (System.Web.IHttpAsyncHandler)));
  146. mainClass.BaseTypes.Add (new CodeTypeReference (typeof (System.Web.IHttpHandler)));
  147. }
  148. void CreateGetTypeHashCode ()
  149. {
  150. CodeMemberMethod method = new CodeMemberMethod ();
  151. method.ReturnType = intRef;
  152. method.Name = "GetTypeHashCode";
  153. method.Attributes = MemberAttributes.Public | MemberAttributes.Override;
  154. Random rnd = new Random (pageParser.InputFile.GetHashCode ());
  155. method.Statements.Add (new CodeMethodReturnStatement (new CodePrimitiveExpression (rnd.Next ())));
  156. mainClass.Members.Add (method);
  157. }
  158. static CodeExpression GetExpressionForValueAndType (object value, Type valueType)
  159. {
  160. // Put short circuit types here
  161. if (valueType == typeof (TimeSpan)) {
  162. CodeMethodReferenceExpression mref = new CodeMethodReferenceExpression (
  163. new CodeTypeReferenceExpression (typeof (TimeSpan)),
  164. "Parse");
  165. return new CodeMethodInvokeExpression (
  166. mref,
  167. new CodeExpression[] { new CodePrimitiveExpression (((TimeSpan) value).ToString ()) }
  168. );
  169. }
  170. throw new HttpException (String.Format ("Unable to create assign expression for type '{0}'.", valueType));
  171. }
  172. static CodeAssignStatement CreatePropertyAssign (CodeExpression owner, string name, CodeExpression rhs)
  173. {
  174. return new CodeAssignStatement (new CodePropertyReferenceExpression (owner, name), rhs);
  175. }
  176. static CodeAssignStatement CreatePropertyAssign (CodeExpression owner, string name, object value)
  177. {
  178. CodeExpression rhs;
  179. if (value == null || value is string)
  180. rhs = new CodePrimitiveExpression (value);
  181. else {
  182. Type vt = value.GetType ();
  183. if (vt.IsPrimitive)
  184. rhs = new CodePrimitiveExpression (value);
  185. else
  186. rhs = GetExpressionForValueAndType (value, vt);
  187. }
  188. return CreatePropertyAssign (owner, name, rhs);
  189. }
  190. static CodeAssignStatement CreatePropertyAssign (string name, object value)
  191. {
  192. return CreatePropertyAssign (thisRef, name, value);
  193. }
  194. void AssignPropertyWithExpression <T> (CodeMemberMethod method, string name, MainDirectiveAttribute <T> value, ILocation location)
  195. {
  196. if (value == null)
  197. return;
  198. CodeAssignStatement assign;
  199. CodeExpression rhs = null;
  200. if (value.IsExpression) {
  201. var pi = GetFieldOrProperty (typeof (Page), name) as PropertyInfo;
  202. if (pi != null)
  203. rhs = CompileExpression (pi, pi.PropertyType, value.UnparsedValue, false);
  204. }
  205. if (rhs != null)
  206. assign = CreatePropertyAssign (thisRef, name, rhs);
  207. else
  208. assign = CreatePropertyAssign (name, value.Value);
  209. method.Statements.Add (AddLinePragma (assign, location));
  210. }
  211. void AddStatementsFromDirective (ControlBuilder builder, CodeMemberMethod method, ILocation location)
  212. {
  213. AssignPropertyWithExpression <string> (method, "ResponseEncoding", pageParser.ResponseEncoding, location);
  214. AssignPropertyWithExpression <int> (method, "CodePage", pageParser.CodePage, location);
  215. AssignPropertyWithExpression <int> (method, "LCID", pageParser.LCID, location);
  216. string contentType = pageParser.ContentType;
  217. if (contentType != null)
  218. method.Statements.Add (AddLinePragma (CreatePropertyAssign ("ContentType", contentType), location));
  219. string culture = pageParser.Culture;
  220. if (culture != null)
  221. method.Statements.Add (AddLinePragma (CreatePropertyAssign ("Culture", culture), location));
  222. culture = pageParser.UICulture;
  223. if (culture != null)
  224. method.Statements.Add (AddLinePragma (CreatePropertyAssign ("UICulture", culture), location));
  225. string errorPage = pageParser.ErrorPage;
  226. if (errorPage != null)
  227. method.Statements.Add (AddLinePragma (CreatePropertyAssign ("ErrorPage", errorPage), location));
  228. if (pageParser.HaveTrace) {
  229. CodeAssignStatement stmt = new CodeAssignStatement ();
  230. stmt.Left = new CodePropertyReferenceExpression (thisRef, "TraceEnabled");
  231. stmt.Right = new CodePrimitiveExpression (pageParser.Trace);
  232. method.Statements.Add (AddLinePragma (stmt, location));
  233. }
  234. if (pageParser.TraceMode != TraceMode.Default) {
  235. CodeAssignStatement stmt = new CodeAssignStatement ();
  236. CodeTypeReferenceExpression tm = new CodeTypeReferenceExpression ("System.Web.TraceMode");
  237. stmt.Left = new CodePropertyReferenceExpression (thisRef, "TraceModeValue");
  238. stmt.Right = new CodeFieldReferenceExpression (tm, pageParser.TraceMode.ToString ());
  239. method.Statements.Add (AddLinePragma (stmt, location));
  240. }
  241. if (pageParser.NotBuffer) {
  242. CodeAssignStatement stmt = new CodeAssignStatement ();
  243. stmt.Left = new CodePropertyReferenceExpression (thisRef, "Buffer");
  244. stmt.Right = new CodePrimitiveExpression (false);
  245. method.Statements.Add (AddLinePragma (stmt, location));
  246. }
  247. if (!pageParser.EnableEventValidation) {
  248. CodeAssignStatement stmt = new CodeAssignStatement ();
  249. CodePropertyReferenceExpression prop;
  250. prop = new CodePropertyReferenceExpression (thisRef, "EnableEventValidation");
  251. stmt.Left = prop;
  252. stmt.Right = new CodePrimitiveExpression (pageParser.EnableEventValidation);
  253. method.Statements.Add (AddLinePragma (stmt, location));
  254. }
  255. if (pageParser.MaintainScrollPositionOnPostBack) {
  256. CodeAssignStatement stmt = new CodeAssignStatement ();
  257. CodePropertyReferenceExpression prop;
  258. prop = new CodePropertyReferenceExpression (thisRef, "MaintainScrollPositionOnPostBack");
  259. stmt.Left = prop;
  260. stmt.Right = new CodePrimitiveExpression (pageParser.MaintainScrollPositionOnPostBack);
  261. method.Statements.Add (AddLinePragma (stmt, location));
  262. }
  263. }
  264. protected override void AddStatementsToConstructor (CodeConstructor ctor)
  265. {
  266. base.AddStatementsToConstructor (ctor);
  267. if (pageParser.OutputCache)
  268. OutputCacheParamsBlock (ctor);
  269. }
  270. protected override void AddStatementsToInitMethodTop (ControlBuilder builder, CodeMemberMethod method)
  271. {
  272. base.AddStatementsToInitMethodTop (builder, method);
  273. ILocation directiveLocation = pageParser.DirectiveLocation;
  274. AddStatementsFromDirective (builder, method, directiveLocation);
  275. CodeArgumentReferenceExpression ctrlVar = new CodeArgumentReferenceExpression("__ctrl");
  276. if (pageParser.EnableViewStateMacSet)
  277. method.Statements.Add (AddLinePragma (CreatePropertyAssign (ctrlVar, "EnableViewStateMac", pageParser.EnableViewStateMacSet), directiveLocation));
  278. AssignPropertyWithExpression <string> (method, "Title", pageParser.Title, directiveLocation);
  279. AssignPropertyWithExpression <string> (method, "MasterPageFile", pageParser.MasterPageFile, directiveLocation);
  280. AssignPropertyWithExpression <string> (method, "Theme", pageParser.Theme, directiveLocation);
  281. if (pageParser.StyleSheetTheme != null)
  282. method.Statements.Add (AddLinePragma (CreatePropertyAssign (ctrlVar, "StyleSheetTheme", pageParser.StyleSheetTheme), directiveLocation));
  283. if (pageParser.Async != false)
  284. method.Statements.Add (AddLinePragma (CreatePropertyAssign (ctrlVar, "AsyncMode", pageParser.Async), directiveLocation));
  285. if (pageParser.AsyncTimeout != -1)
  286. method.Statements.Add (AddLinePragma (CreatePropertyAssign (ctrlVar, "AsyncTimeout",
  287. TimeSpan.FromSeconds (pageParser.AsyncTimeout)), directiveLocation));
  288. CodeMethodInvokeExpression expr = new CodeMethodInvokeExpression (thisRef, "InitializeCulture");
  289. method.Statements.Add (AddLinePragma (new CodeExpressionStatement (expr), directiveLocation));
  290. }
  291. #if NET_4_0
  292. protected override void AddStatementsToInitMethodBottom (ControlBuilder builder, CodeMemberMethod method)
  293. {
  294. ILocation directiveLocation = pageParser.DirectiveLocation;
  295. AssignPropertyWithExpression <string> (method, "MetaDescription", pageParser.MetaDescription, directiveLocation);
  296. AssignPropertyWithExpression <string> (method, "MetaKeywords", pageParser.MetaKeywords, directiveLocation);
  297. }
  298. #endif
  299. protected override void PrependStatementsToFrameworkInitialize (CodeMemberMethod method)
  300. {
  301. base.PrependStatementsToFrameworkInitialize (method);
  302. if (pageParser.StyleSheetTheme != null)
  303. method.Statements.Add (CreatePropertyAssign ("StyleSheetTheme", pageParser.StyleSheetTheme));
  304. }
  305. protected override void AppendStatementsToFrameworkInitialize (CodeMemberMethod method)
  306. {
  307. base.AppendStatementsToFrameworkInitialize (method);
  308. ArrayList deps = pageParser.Dependencies;
  309. int depsCount = deps != null ? deps.Count : 0;
  310. if (depsCount > 0) {
  311. CodeFieldReferenceExpression fileDependencies = GetMainClassFieldReferenceExpression ("__fileDependencies");
  312. method.Statements.Add (
  313. new CodeMethodInvokeExpression (
  314. thisRef,
  315. "AddWrappedFileDependencies",
  316. new CodeExpression[] {fileDependencies})
  317. );
  318. }
  319. if (pageParser.OutputCache) {
  320. CodeMethodReferenceExpression init = new CodeMethodReferenceExpression (thisRef, "InitOutputCache");
  321. CodeMethodInvokeExpression invoke = new CodeMethodInvokeExpression (init, GetMainClassFieldReferenceExpression ("__outputCacheSettings"));
  322. method.Statements.Add (invoke);
  323. }
  324. if (pageParser.ValidateRequest) {
  325. CodeMethodInvokeExpression expr = new CodeMethodInvokeExpression ();
  326. CodePropertyReferenceExpression prop;
  327. prop = new CodePropertyReferenceExpression (thisRef, "Request");
  328. expr.Method = new CodeMethodReferenceExpression (prop, "ValidateInput");
  329. method.Statements.Add (expr);
  330. }
  331. }
  332. CodeAssignStatement AssignOutputCacheParameter (CodeVariableReferenceExpression variable, string propName, object value)
  333. {
  334. var ret = new CodeAssignStatement ();
  335. ret.Left = new CodeFieldReferenceExpression (variable, propName);
  336. if (value is OutputCacheLocation)
  337. ret.Right = new CodeFieldReferenceExpression (
  338. new CodeTypeReferenceExpression (new CodeTypeReference (typeof (OutputCacheLocation), CodeTypeReferenceOptions.GlobalReference)),
  339. value.ToString ()
  340. );
  341. else
  342. ret.Right = new CodePrimitiveExpression (value);
  343. return ret;
  344. }
  345. void OutputCacheParamsBlock (CodeMemberMethod method)
  346. {
  347. var statements = new List <CodeStatement> ();
  348. var localSettingsDecl = new CodeVariableDeclarationStatement (typeof (OutputCacheParameters), "outputCacheSettings");
  349. var localSettings = new CodeVariableReferenceExpression ("outputCacheSettings");
  350. statements.Add (localSettingsDecl);
  351. statements.Add (
  352. new CodeAssignStatement (
  353. localSettings,
  354. new CodeObjectCreateExpression (typeof (OutputCacheParameters), new CodeExpression[] {})
  355. )
  356. );
  357. TemplateParser.OutputCacheParsedParams parsed = pageParser.OutputCacheParsedParameters;
  358. if ((parsed & TemplateParser.OutputCacheParsedParams.CacheProfile) != 0)
  359. statements.Add (AssignOutputCacheParameter (localSettings, "CacheProfile", pageParser.OutputCacheCacheProfile));
  360. statements.Add (AssignOutputCacheParameter (localSettings, "Duration", pageParser.OutputCacheDuration));
  361. if ((parsed & TemplateParser.OutputCacheParsedParams.Location) != 0)
  362. statements.Add (AssignOutputCacheParameter (localSettings, "Location", pageParser.OutputCacheLocation));
  363. if ((parsed & TemplateParser.OutputCacheParsedParams.NoStore) != 0)
  364. statements.Add (AssignOutputCacheParameter (localSettings, "NoStore", pageParser.OutputCacheNoStore));
  365. if ((parsed & TemplateParser.OutputCacheParsedParams.SqlDependency) != 0)
  366. statements.Add (AssignOutputCacheParameter (localSettings, "SqlDependency", pageParser.OutputCacheSqlDependency));
  367. if ((parsed & TemplateParser.OutputCacheParsedParams.VaryByContentEncodings) != 0)
  368. statements.Add (AssignOutputCacheParameter (localSettings, "VaryByContentEncoding", pageParser.OutputCacheVaryByContentEncodings));
  369. if ((parsed & TemplateParser.OutputCacheParsedParams.VaryByControl) != 0)
  370. statements.Add (AssignOutputCacheParameter (localSettings, "VaryByControl", pageParser.OutputCacheVaryByControls));
  371. if ((parsed & TemplateParser.OutputCacheParsedParams.VaryByCustom) != 0)
  372. statements.Add (AssignOutputCacheParameter (localSettings, "VaryByCustom", pageParser.OutputCacheVaryByCustom));
  373. if ((parsed & TemplateParser.OutputCacheParsedParams.VaryByHeader) != 0)
  374. statements.Add (AssignOutputCacheParameter (localSettings, "VaryByHeader", pageParser.OutputCacheVaryByHeader));
  375. statements.Add (AssignOutputCacheParameter (localSettings, "VaryByParam", pageParser.OutputCacheVaryByParam));
  376. CodeFieldReferenceExpression outputCacheSettings = GetMainClassFieldReferenceExpression ("__outputCacheSettings");
  377. statements.Add (new CodeAssignStatement (outputCacheSettings, localSettings));
  378. var cond = new CodeConditionStatement (
  379. new CodeBinaryOperatorExpression (
  380. outputCacheSettings,
  381. CodeBinaryOperatorType.IdentityEquality,
  382. new CodePrimitiveExpression (null)
  383. ),
  384. statements.ToArray ()
  385. );
  386. method.Statements.Add (cond);
  387. }
  388. void CreateStronglyTypedProperty (Type type, string name)
  389. {
  390. if (type == null)
  391. return;
  392. CodeMemberProperty mprop = new CodeMemberProperty ();
  393. mprop.Name = name;
  394. mprop.Type = new CodeTypeReference (type);
  395. mprop.Attributes = MemberAttributes.Public | MemberAttributes.New;
  396. CodeExpression prop = new CodePropertyReferenceExpression (new CodeBaseReferenceExpression (), name);
  397. prop = new CodeCastExpression (type, prop);
  398. mprop.GetStatements.Add (new CodeMethodReturnStatement (prop));
  399. if (partialClass != null)
  400. partialClass.Members.Add (mprop);
  401. else
  402. mainClass.Members.Add (mprop);
  403. AddReferencedAssembly (type.Assembly);
  404. }
  405. protected internal override void CreateMethods ()
  406. {
  407. base.CreateMethods ();
  408. CreateProfileProperty ();
  409. CreateStronglyTypedProperty (pageParser.MasterType, "Master");
  410. CreateStronglyTypedProperty (pageParser.PreviousPageType, "PreviousPage");
  411. CreateGetTypeHashCode ();
  412. if (pageParser.Async)
  413. CreateAsyncMethods ();
  414. }
  415. void CreateAsyncMethods ()
  416. {
  417. CodeMemberMethod method = new CodeMemberMethod ();
  418. CodeParameterDeclarationExpression arg;
  419. CodeMethodInvokeExpression invoke;
  420. // public virtual System.IAsyncResult BeginProcessRequest(System.Web.HttpContext context, System.AsyncCallback cb, object data);
  421. method.ReturnType = new CodeTypeReference (typeof (IAsyncResult));
  422. method.Name = "BeginProcessRequest";
  423. method.Attributes = MemberAttributes.Public;
  424. arg = new CodeParameterDeclarationExpression ();
  425. arg.Type = new CodeTypeReference (typeof (HttpContext));
  426. arg.Name = "context";
  427. method.Parameters.Add (arg);
  428. arg = new CodeParameterDeclarationExpression ();
  429. arg.Type = new CodeTypeReference (typeof (AsyncCallback));
  430. arg.Name = "cb";
  431. method.Parameters.Add (arg);
  432. arg = new CodeParameterDeclarationExpression ();
  433. arg.Type = new CodeTypeReference (typeof (object));
  434. arg.Name = "data";
  435. method.Parameters.Add (arg);
  436. invoke = new CodeMethodInvokeExpression (thisRef, "AsyncPageBeginProcessRequest");
  437. invoke.Parameters.Add (new CodeArgumentReferenceExpression ("context"));
  438. invoke.Parameters.Add (new CodeArgumentReferenceExpression ("cb"));
  439. invoke.Parameters.Add (new CodeArgumentReferenceExpression ("data"));
  440. method.Statements.Add (new CodeMethodReturnStatement (invoke));
  441. mainClass.Members.Add (method);
  442. // public virtual void EndProcessRequest(System.IAsyncResult ar);
  443. method = new CodeMemberMethod ();
  444. method.ReturnType = new CodeTypeReference (typeof (void));
  445. method.Name = "EndProcessRequest";
  446. method.Attributes = MemberAttributes.Public;
  447. arg = new CodeParameterDeclarationExpression ();
  448. arg.Type = new CodeTypeReference (typeof (IAsyncResult));
  449. arg.Name = "ar";
  450. method.Parameters.Add (arg);
  451. invoke = new CodeMethodInvokeExpression (thisRef, "AsyncPageEndProcessRequest");
  452. invoke.Parameters.Add (new CodeArgumentReferenceExpression ("ar"));
  453. method.Statements.Add (invoke);
  454. mainClass.Members.Add (method);
  455. // public override void ProcessRequest(System.Web.HttpContext context);
  456. method = new CodeMemberMethod ();
  457. method.ReturnType = new CodeTypeReference (typeof (void));
  458. method.Name = "ProcessRequest";
  459. method.Attributes = MemberAttributes.Public | MemberAttributes.Override;
  460. arg = new CodeParameterDeclarationExpression ();
  461. arg.Type = new CodeTypeReference (typeof (HttpContext));
  462. arg.Name = "context";
  463. method.Parameters.Add (arg);
  464. invoke = new CodeMethodInvokeExpression (new CodeBaseReferenceExpression (), "ProcessRequest");
  465. invoke.Parameters.Add (new CodeArgumentReferenceExpression ("context"));
  466. method.Statements.Add (invoke);
  467. mainClass.Members.Add (method);
  468. }
  469. public static Type CompilePageType (PageParser pageParser)
  470. {
  471. PageCompiler compiler = new PageCompiler (pageParser);
  472. return compiler.GetCompiledType ();
  473. }
  474. }
  475. }