BaseCompiler.cs 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681
  1. //
  2. // System.Web.Compilation.BaseCompiler
  3. //
  4. // Authors:
  5. // Gonzalo Paniagua Javier ([email protected])
  6. //
  7. // (c) Copyright 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.CodeDom.Compiler;
  32. using System.Collections;
  33. using System.Collections.Specialized;
  34. using System.Reflection;
  35. using System.Text;
  36. using System.Web.UI;
  37. using System.Web.Configuration;
  38. using System.IO;
  39. namespace System.Web.Compilation
  40. {
  41. abstract class BaseCompiler
  42. {
  43. #if NET_2_0
  44. static BindingFlags replaceableFlags = BindingFlags.Public | BindingFlags.NonPublic |
  45. BindingFlags.Instance;
  46. #endif
  47. TemplateParser parser;
  48. CodeDomProvider provider;
  49. ICodeCompiler compiler;
  50. CodeCompileUnit unit;
  51. CodeNamespace mainNS;
  52. CompilerParameters compilerParameters;
  53. #if NET_2_0
  54. bool isRebuilding = false;
  55. protected Hashtable partialNameOverride = new Hashtable();
  56. protected CodeTypeDeclaration partialClass;
  57. protected CodeTypeReferenceExpression partialClassExpr;
  58. #endif
  59. protected CodeTypeDeclaration mainClass;
  60. protected CodeTypeReferenceExpression mainClassExpr;
  61. protected static CodeThisReferenceExpression thisRef = new CodeThisReferenceExpression ();
  62. protected BaseCompiler (TemplateParser parser)
  63. {
  64. this.parser = parser;
  65. }
  66. void Init ()
  67. {
  68. unit = new CodeCompileUnit ();
  69. #if NET_2_0
  70. if (parser.IsPartial) {
  71. string partialns = null;
  72. string partialclasstype = parser.PartialClassName;
  73. int partialdot = partialclasstype.LastIndexOf ('.');
  74. if (partialdot != -1) {
  75. partialns = partialclasstype.Substring (0, partialdot);
  76. partialclasstype = partialclasstype.Substring (partialdot + 1);
  77. }
  78. CodeNamespace partialNS = new CodeNamespace (partialns);
  79. partialClass = new CodeTypeDeclaration (partialclasstype);
  80. partialClass.IsPartial = true;
  81. partialClassExpr = new CodeTypeReferenceExpression (parser.PartialClassName);
  82. unit.Namespaces.Add (partialNS);
  83. partialClass.TypeAttributes = TypeAttributes.Public;
  84. partialNS.Types.Add (partialClass);
  85. }
  86. #endif
  87. string mainclasstype = parser.ClassName;
  88. string mainns = "ASP";
  89. #if NET_2_0
  90. int maindot = mainclasstype.LastIndexOf ('.');
  91. if (maindot != -1) {
  92. mainns = mainclasstype.Substring (0, maindot);
  93. mainclasstype = mainclasstype.Substring (maindot + 1);
  94. }
  95. #endif
  96. mainNS = new CodeNamespace (mainns);
  97. mainClass = new CodeTypeDeclaration (mainclasstype);
  98. CodeTypeReference baseTypeRef;
  99. #if NET_2_0
  100. if (partialClass != null) {
  101. baseTypeRef = new CodeTypeReference (parser.PartialClassName);
  102. baseTypeRef.Options |= CodeTypeReferenceOptions.GlobalReference;
  103. } else {
  104. baseTypeRef = new CodeTypeReference (parser.BaseType.FullName);
  105. if (parser.BaseTypeIsGlobal)
  106. baseTypeRef.Options |= CodeTypeReferenceOptions.GlobalReference;
  107. }
  108. #else
  109. baseTypeRef = new CodeTypeReference (parser.BaseType.FullName);
  110. #endif
  111. mainClass.BaseTypes.Add (baseTypeRef);
  112. mainClassExpr = new CodeTypeReferenceExpression (mainns + "." + mainclasstype);
  113. unit.Namespaces.Add (mainNS);
  114. mainClass.TypeAttributes = TypeAttributes.Public;
  115. mainNS.Types.Add (mainClass);
  116. foreach (object o in parser.Imports) {
  117. if (o is string)
  118. mainNS.Imports.Add (new CodeNamespaceImport ((string) o));
  119. }
  120. // StringCollection.Contains has O(n) complexity, but
  121. // considering the number of comparisons we make on
  122. // average and the fact that using an intermediate array
  123. // would be even more costly, this is fine here.
  124. StringCollection refAsm = unit.ReferencedAssemblies;
  125. string asmName;
  126. if (parser.Assemblies != null) {
  127. foreach (object o in parser.Assemblies) {
  128. asmName = o as string;
  129. if (asmName != null && !refAsm.Contains (asmName))
  130. refAsm.Add (asmName);
  131. }
  132. }
  133. #if NET_2_0
  134. ArrayList al = WebConfigurationManager.ExtraAssemblies;
  135. if (al != null && al.Count > 0) {
  136. foreach (object o in al) {
  137. asmName = o as string;
  138. if (asmName != null && !refAsm.Contains (asmName))
  139. refAsm.Add (asmName);
  140. }
  141. }
  142. IList list = BuildManager.CodeAssemblies;
  143. if (list != null && list.Count > 0) {
  144. Assembly asm;
  145. foreach (object o in list) {
  146. asm = o as Assembly;
  147. if (o == null)
  148. continue;
  149. asmName = asm.Location;
  150. if (asmName != null && !refAsm.Contains (asmName))
  151. refAsm.Add (asmName);
  152. }
  153. }
  154. #endif
  155. // Late-bound generators specifics (as for MonoBASIC/VB.NET)
  156. unit.UserData["RequireVariableDeclaration"] = parser.ExplicitOn;
  157. unit.UserData["AllowLateBound"] = !parser.StrictOn;
  158. AddInterfaces ();
  159. AddClassAttributes ();
  160. CreateStaticFields ();
  161. AddApplicationAndSessionObjects ();
  162. AddScripts ();
  163. CreateMethods ();
  164. CreateConstructor (null, null);
  165. }
  166. protected virtual void CreateStaticFields ()
  167. {
  168. CodeMemberField fld = new CodeMemberField (typeof (bool), "__initialized");
  169. fld.Attributes = MemberAttributes.Private | MemberAttributes.Static;
  170. fld.InitExpression = new CodePrimitiveExpression (false);
  171. mainClass.Members.Add (fld);
  172. }
  173. #if NET_2_0
  174. void AssignAppRelativeVirtualPath (CodeConstructor ctor)
  175. {
  176. Type baseType = parser.CodeFileBaseClassType;
  177. if (baseType == null)
  178. baseType = parser.BaseType;
  179. if (baseType == null)
  180. return;
  181. if (!baseType.IsSubclassOf (typeof (System.Web.UI.TemplateControl)))
  182. return;
  183. string arvp = Path.Combine (parser.BaseVirtualDir, Path.GetFileName (parser.InputFile));
  184. if (VirtualPathUtility.IsAbsolute (arvp))
  185. arvp = "~" + arvp;
  186. CodeTypeReference baseTypeRef = new CodeTypeReference (baseType.FullName);
  187. if (parser.BaseTypeIsGlobal)
  188. baseTypeRef.Options |= CodeTypeReferenceOptions.GlobalReference;
  189. CodeExpression cast = new CodeCastExpression (baseTypeRef, new CodeThisReferenceExpression ());
  190. CodePropertyReferenceExpression arvpProp = new CodePropertyReferenceExpression (cast, "AppRelativeVirtualPath");
  191. CodeAssignStatement arvpAssign = new CodeAssignStatement ();
  192. arvpAssign.Left = arvpProp;
  193. arvpAssign.Right = new CodePrimitiveExpression (VirtualPathUtility.RemoveTrailingSlash (arvp));
  194. ctor.Statements.Add (arvpAssign);
  195. }
  196. #endif
  197. protected virtual void CreateConstructor (CodeStatementCollection localVars,
  198. CodeStatementCollection trueStmt)
  199. {
  200. CodeConstructor ctor = new CodeConstructor ();
  201. ctor.Attributes = MemberAttributes.Public;
  202. mainClass.Members.Add (ctor);
  203. #if NET_2_0
  204. AssignAppRelativeVirtualPath (ctor);
  205. #endif
  206. if (localVars != null)
  207. ctor.Statements.AddRange (localVars);
  208. CodeTypeReferenceExpression r;
  209. #if NET_2_0
  210. if (parser.IsPartial)
  211. r = new CodeTypeReferenceExpression (mainClass.Name);
  212. else
  213. #endif
  214. r = new CodeTypeReferenceExpression (mainNS.Name + "." + mainClass.Name);
  215. CodeFieldReferenceExpression initialized;
  216. initialized = new CodeFieldReferenceExpression (r, "__initialized");
  217. CodeBinaryOperatorExpression bin;
  218. bin = new CodeBinaryOperatorExpression (initialized,
  219. CodeBinaryOperatorType.ValueEquality,
  220. new CodePrimitiveExpression (false));
  221. CodeAssignStatement assign = new CodeAssignStatement (initialized,
  222. new CodePrimitiveExpression (true));
  223. CodeConditionStatement cond = new CodeConditionStatement (bin, assign);
  224. if (trueStmt != null)
  225. cond.TrueStatements.AddRange (trueStmt);
  226. ctor.Statements.Add (cond);
  227. }
  228. void AddScripts ()
  229. {
  230. if (parser.Scripts == null || parser.Scripts.Count == 0)
  231. return;
  232. foreach (object o in parser.Scripts) {
  233. if (o is string)
  234. mainClass.Members.Add (new CodeSnippetTypeMember ((string) o));
  235. }
  236. }
  237. protected internal virtual void CreateMethods ()
  238. {
  239. }
  240. #if NET_2_0
  241. void InternalCreatePageProperty (string retType, string name, string contextProperty)
  242. {
  243. CodeMemberProperty property = new CodeMemberProperty ();
  244. property.Name = name;
  245. property.Type = new CodeTypeReference (retType);
  246. property.Attributes = MemberAttributes.Family | MemberAttributes.Final;
  247. CodeMethodReturnStatement ret = new CodeMethodReturnStatement ();
  248. CodeCastExpression cast = new CodeCastExpression ();
  249. ret.Expression = cast;
  250. CodePropertyReferenceExpression refexp = new CodePropertyReferenceExpression ();
  251. refexp.TargetObject = new CodePropertyReferenceExpression (new CodeThisReferenceExpression (), "Context");
  252. refexp.PropertyName = contextProperty;
  253. cast.TargetType = new CodeTypeReference (retType);
  254. cast.Expression = refexp;
  255. property.GetStatements.Add (ret);
  256. if (partialClass == null)
  257. mainClass.Members.Add (property);
  258. else
  259. partialClass.Members.Add (property);
  260. }
  261. protected void CreateProfileProperty ()
  262. {
  263. string retType;
  264. if (AppCodeCompiler.HaveCustomProfile (WebConfigurationManager.GetSection ("system.web/profile") as ProfileSection))
  265. retType = "ProfileCommon";
  266. else
  267. retType = "System.Web.Profile.DefaultProfile";
  268. InternalCreatePageProperty (retType, "Profile", "Profile");
  269. }
  270. #endif
  271. protected virtual void AddInterfaces ()
  272. {
  273. if (parser.Interfaces == null)
  274. return;
  275. foreach (object o in parser.Interfaces) {
  276. if (o is string)
  277. mainClass.BaseTypes.Add (new CodeTypeReference ((string) o));
  278. }
  279. }
  280. protected virtual void AddClassAttributes ()
  281. {
  282. }
  283. protected virtual void AddApplicationAndSessionObjects ()
  284. {
  285. }
  286. /* Utility methods for <object> stuff */
  287. protected void CreateApplicationOrSessionPropertyForObject (Type type,
  288. string propName,
  289. bool isApplication,
  290. bool isPublic)
  291. {
  292. /* if isApplication this generates (the 'cachedapp' field is created earlier):
  293. private MyNS.MyClass app {
  294. get {
  295. if ((this.cachedapp == null)) {
  296. this.cachedapp = ((MyNS.MyClass)
  297. (this.Application.StaticObjects.GetObject("app")));
  298. }
  299. return this.cachedapp;
  300. }
  301. }
  302. else, this is for Session:
  303. private MyNS.MyClass ses {
  304. get {
  305. return ((MyNS.MyClass) (this.Session.StaticObjects.GetObject("ses")));
  306. }
  307. }
  308. */
  309. CodeExpression result = null;
  310. CodeMemberProperty prop = new CodeMemberProperty ();
  311. prop.Type = new CodeTypeReference (type);
  312. prop.Name = propName;
  313. if (isPublic)
  314. prop.Attributes = MemberAttributes.Public | MemberAttributes.Final;
  315. else
  316. prop.Attributes = MemberAttributes.Private | MemberAttributes.Final;
  317. CodePropertyReferenceExpression p1;
  318. if (isApplication)
  319. p1 = new CodePropertyReferenceExpression (thisRef, "Application");
  320. else
  321. p1 = new CodePropertyReferenceExpression (thisRef, "Session");
  322. CodePropertyReferenceExpression p2;
  323. p2 = new CodePropertyReferenceExpression (p1, "StaticObjects");
  324. CodeMethodReferenceExpression getobject;
  325. getobject = new CodeMethodReferenceExpression (p2, "GetObject");
  326. CodeMethodInvokeExpression invoker;
  327. invoker = new CodeMethodInvokeExpression (getobject,
  328. new CodePrimitiveExpression (propName));
  329. CodeCastExpression cast = new CodeCastExpression (prop.Type, invoker);
  330. if (isApplication) {
  331. CodeFieldReferenceExpression field;
  332. field = new CodeFieldReferenceExpression (thisRef, "cached" + propName);
  333. CodeConditionStatement stmt = new CodeConditionStatement();
  334. stmt.Condition = new CodeBinaryOperatorExpression (field,
  335. CodeBinaryOperatorType.IdentityEquality,
  336. new CodePrimitiveExpression (null));
  337. CodeAssignStatement assign = new CodeAssignStatement ();
  338. assign.Left = field;
  339. assign.Right = cast;
  340. stmt.TrueStatements.Add (assign);
  341. prop.GetStatements.Add (stmt);
  342. result = field;
  343. } else {
  344. result = cast;
  345. }
  346. prop.GetStatements.Add (new CodeMethodReturnStatement (result));
  347. mainClass.Members.Add (prop);
  348. }
  349. protected string CreateFieldForObject (Type type, string name)
  350. {
  351. string fieldName = "cached" + name;
  352. CodeMemberField f = new CodeMemberField (type, fieldName);
  353. f.Attributes = MemberAttributes.Private;
  354. mainClass.Members.Add (f);
  355. return fieldName;
  356. }
  357. protected void CreatePropertyForObject (Type type, string propName, string fieldName, bool isPublic)
  358. {
  359. CodeFieldReferenceExpression field = new CodeFieldReferenceExpression (thisRef, fieldName);
  360. CodeMemberProperty prop = new CodeMemberProperty ();
  361. prop.Type = new CodeTypeReference (type);
  362. prop.Name = propName;
  363. if (isPublic)
  364. prop.Attributes = MemberAttributes.Public | MemberAttributes.Final;
  365. else
  366. prop.Attributes = MemberAttributes.Private | MemberAttributes.Final;
  367. CodeConditionStatement stmt = new CodeConditionStatement();
  368. stmt.Condition = new CodeBinaryOperatorExpression (field,
  369. CodeBinaryOperatorType.IdentityEquality,
  370. new CodePrimitiveExpression (null));
  371. CodeObjectCreateExpression create = new CodeObjectCreateExpression (prop.Type);
  372. stmt.TrueStatements.Add (new CodeAssignStatement (field, create));
  373. prop.GetStatements.Add (stmt);
  374. prop.GetStatements.Add (new CodeMethodReturnStatement (field));
  375. mainClass.Members.Add (prop);
  376. }
  377. /******/
  378. void CheckCompilerErrors (CompilerResults results)
  379. {
  380. if (results.NativeCompilerReturnValue == 0)
  381. return;
  382. string fileText = null;
  383. CompilerErrorCollection errors = results.Errors;
  384. CompilerError ce = (errors != null && errors.Count > 0) ? errors [0] : null;
  385. string inFile = (ce != null) ? ce.FileName : null;
  386. if (inFile != null && File.Exists (inFile)) {
  387. using (StreamReader sr = File.OpenText (inFile)) {
  388. fileText = sr.ReadToEnd ();
  389. }
  390. } else {
  391. StringWriter writer = new StringWriter();
  392. provider.CreateGenerator().GenerateCodeFromCompileUnit (unit, writer, null);
  393. fileText = writer.ToString ();
  394. }
  395. throw new CompilationException (parser.InputFile, errors, fileText);
  396. }
  397. protected string DynamicDir ()
  398. {
  399. return AppDomain.CurrentDomain.SetupInformation.DynamicBase;
  400. }
  401. internal static CodeDomProvider CreateProvider (string lang, out string compilerOptions, out int warningLevel, out string tempdir)
  402. {
  403. return CreateProvider (HttpContext.Current, lang, out compilerOptions, out warningLevel, out tempdir);
  404. }
  405. internal static CodeDomProvider CreateProvider (HttpContext context, string lang, out string compilerOptions, out int warningLevel, out string tempdir)
  406. {
  407. CodeDomProvider ret = null;
  408. #if NET_2_0
  409. CompilationSection config = (CompilationSection) WebConfigurationManager.GetSection ("system.web/compilation");
  410. Compiler comp = config.Compilers[lang];
  411. if (comp == null) {
  412. CompilerInfo info = CodeDomProvider.GetCompilerInfo (lang);
  413. if (info != null && info.IsCodeDomProviderTypeValid) {
  414. ret = info.CreateProvider ();
  415. CompilerParameters cp = info.CreateDefaultCompilerParameters ();
  416. compilerOptions = cp.CompilerOptions;
  417. warningLevel = cp.WarningLevel;
  418. } else {
  419. compilerOptions = String.Empty;
  420. warningLevel = 2;
  421. }
  422. } else {
  423. Type t = HttpApplication.LoadType (comp.Type, true);
  424. ret = Activator.CreateInstance (t) as CodeDomProvider;
  425. compilerOptions = comp.CompilerOptions;
  426. warningLevel = comp.WarningLevel;
  427. }
  428. #else
  429. CompilationConfiguration config;
  430. config = CompilationConfiguration.GetInstance (context);
  431. ret = config.GetProvider (lang);
  432. compilerOptions = config.GetCompilerOptions (lang);
  433. warningLevel = config.GetWarningLevel (lang);
  434. #endif
  435. tempdir = config.TempDirectory;
  436. return ret;
  437. }
  438. [MonoTODO ("find out how to extract the warningLevel and compilerOptions in the <system.codedom> case")]
  439. public virtual Type GetCompiledType ()
  440. {
  441. Type type = CachingCompiler.GetTypeFromCache (parser.InputFile);
  442. if (type != null)
  443. return type;
  444. Init ();
  445. string lang = parser.Language;
  446. string tempdir;
  447. string compilerOptions;
  448. int warningLevel;
  449. Provider = CreateProvider (parser.Context, lang, out compilerOptions, out warningLevel, out tempdir);
  450. if (Provider == null)
  451. throw new HttpException ("Configuration error. Language not supported: " +
  452. lang, 500);
  453. #if !NET_2_0
  454. compiler = provider.CreateCompiler ();
  455. #endif
  456. CompilerParameters parameters = CompilerParameters;
  457. parameters.IncludeDebugInformation = parser.Debug;
  458. parameters.CompilerOptions = compilerOptions + " " + parser.CompilerOptions;
  459. parameters.WarningLevel = warningLevel;
  460. bool keepFiles = (Environment.GetEnvironmentVariable ("MONO_ASPNET_NODELETE") != null);
  461. if (tempdir == null || tempdir == "")
  462. tempdir = DynamicDir ();
  463. TempFileCollection tempcoll = new TempFileCollection (tempdir, keepFiles);
  464. parameters.TempFiles = tempcoll;
  465. string dllfilename = Path.GetFileName (tempcoll.AddExtension ("dll", true));
  466. parameters.OutputAssembly = Path.Combine (DynamicDir (), dllfilename);
  467. CompilerResults results = CachingCompiler.Compile (this);
  468. CheckCompilerErrors (results);
  469. Assembly assembly = results.CompiledAssembly;
  470. if (assembly == null) {
  471. if (!File.Exists (parameters.OutputAssembly)) {
  472. results.TempFiles.Delete ();
  473. throw new CompilationException (parser.InputFile, results.Errors,
  474. "No assembly returned after compilation!?");
  475. }
  476. assembly = Assembly.LoadFrom (parameters.OutputAssembly);
  477. }
  478. results.TempFiles.Delete ();
  479. Type mainClassType = assembly.GetType (mainClassExpr.Type.BaseType, true);
  480. #if NET_2_0
  481. if (parser.IsPartial) {
  482. // With the partial classes, we need to make sure we
  483. // don't have any methods that should have not been
  484. // created (because they are accessible from the base
  485. // types). We cannot do this normally because the
  486. // codebehind file is actually a partial class and we
  487. // have no way of identifying the partial class' base
  488. // type until now.
  489. if (!isRebuilding && CheckPartialBaseType (mainClassType)) {
  490. isRebuilding = true;
  491. parser.RootBuilder.ResetState ();
  492. return GetCompiledType ();
  493. }
  494. }
  495. #endif
  496. return mainClassType;
  497. }
  498. #if NET_2_0
  499. internal bool IsRebuildingPartial
  500. {
  501. get { return isRebuilding; }
  502. }
  503. internal bool CheckPartialBaseType (Type type)
  504. {
  505. // Get the base type. If we don't have any (bad thing), we
  506. // don't need to replace ourselves. Also check for the
  507. // core file, since that won't have any either.
  508. Type baseType = type.BaseType;
  509. if (baseType == null || baseType == typeof(System.Web.UI.Page))
  510. return false;
  511. bool rebuild = false;
  512. if (CheckPartialBaseFields (type, baseType))
  513. rebuild = true;
  514. if (CheckPartialBaseProperties (type, baseType))
  515. rebuild = true;
  516. return rebuild;
  517. }
  518. internal bool CheckPartialBaseFields (Type type, Type baseType)
  519. {
  520. bool rebuild = false;
  521. foreach (FieldInfo baseInfo in baseType.GetFields (replaceableFlags)) {
  522. if (baseInfo.IsPrivate)
  523. continue;
  524. FieldInfo typeInfo = type.GetField (baseInfo.Name, replaceableFlags);
  525. if (typeInfo != null && typeInfo.DeclaringType == type) {
  526. partialNameOverride [typeInfo.Name] = true;
  527. rebuild = true;
  528. }
  529. }
  530. return rebuild;
  531. }
  532. internal bool CheckPartialBaseProperties (Type type, Type baseType)
  533. {
  534. bool rebuild = false;
  535. foreach (PropertyInfo baseInfo in baseType.GetProperties ()) {
  536. PropertyInfo typeInfo = type.GetProperty (baseInfo.Name);
  537. if (typeInfo != null && typeInfo.DeclaringType == type) {
  538. partialNameOverride [typeInfo.Name] = true;
  539. rebuild = true;
  540. }
  541. }
  542. return rebuild;
  543. }
  544. #endif
  545. internal CodeDomProvider Provider {
  546. get { return provider; }
  547. set { provider = value; }
  548. }
  549. internal ICodeCompiler Compiler {
  550. get { return compiler; }
  551. set { compiler = value; }
  552. }
  553. internal CompilerParameters CompilerParameters {
  554. get {
  555. if (compilerParameters == null)
  556. compilerParameters = new CompilerParameters ();
  557. return compilerParameters;
  558. }
  559. set { compilerParameters = value; }
  560. }
  561. internal CodeCompileUnit CompileUnit {
  562. get { return unit; }
  563. }
  564. internal TemplateParser Parser {
  565. get { return parser; }
  566. }
  567. }
  568. }