Inside ASP.NET 2.0- ASP.NET 1.1 2. 理念 讀 了 了 度 讀 了
理 類 來 來說 流 了 來 來 來 來 理 來 不 讀 不 不 力 來參 流 讀
了 異 行
來了 錄 行 不 了 來 了 來 行 論說 了 更 不 例 來了 力 行 樂 不 說 兩 例 利 來 了 來 樂 了 了 令 讀 來 不 不 來 了
不 旅行 令 錄 錄 來 了 例 來 利 來 ManagerProvide 不 讀
什 來 讀 來 不 來 來 了 度 不 兩 來 來 來說 不 說 BuildProvider 契 BuildProvider 了 BuildProvider BuildManager 不
BuildManager 錄.compiled.compiled Assembly 連.aspx 不 了 BuildManager 來 了 BuildProviders BuildManager 不 BuildProvider 錄 Cache 了 了 BuildProvider 不 Custom Build Provider ASP.NET 2.0 Beta Build Provider 不 2 說 2 <configuration> <system.web> <compilation>. <buildproviders> <buildprovider extension=".mafx" type="buildprovidertype, BuildProviderAssembly" /> </buildproviders> </compilation> </system.web> </configuration> Build Provider ASP.NET 2.0 Build Provider 不 了 不 更 了 不 buildprovider 不 3 3
extension BuildProvider type BuildProvider Assembly Type appliesto Code Resource Web(.aspx.ascx All 類 BuildProvider 讀 Visual Studio 2005 Beta Visual C# Express Class Library Wizard Command Line 例了 4 BuildProvider 例 4 #region Using directives using System; using System.Collections.Generic; using System.Text; using System.IO; using System.CodeDom; using System.CodeDom.Compiler; using System.Web.Compilation; #endregion namespace TestBuildProvider public class MyCSharpBuilder:BuildProvider public override void GenerateCode(AssemblyBuilder assemblybuilder) TextReader reader = base.openreader(); string scriptstring = reader.readline(); CodeCompileUnit unit = new CodeCompileUnit(); unit.namespaces.add(new CodeNamespace("TEST")); CodeTypeDeclaration class1 = new CodeTypeDeclaration("HelloClass"); class1.isclass = true; CodeMemberMethod method1 = new CodeMemberMethod(); method1.name = "SayHello"; method1.returntype = new CodeTypeReference("System.String"); method1.statements.add(new CodeMethodReturnStatement( new CodePrimitiveExpression(scriptString))); method1.attributes = MemberAttributes.Public; class1.members.add(method1); unit.namespaces[0].types.add(class1); assemblybuilder.addcodecompileunit(this, unit);
例 CodeDom HelloClass 類 SayHello 串 OpenReader TextReader 讀 來 OpenReader TextReader 來 理 例 class1.ppp( 錄 bin 錄 錄 bin 錄 行 web.config 5 5 立 class1.ppp 6 6 錄 Code 錄 Code 錄 來 BuildProvdier Default.aspx Button 7 7 Type FindType() Assembly[] assems = AppDomain.CurrentDomain.GetAssemblies(); foreach(assembly assem in assems) Type t = assem.gettype("test.helloclass"); if (t!= null) return t; return null; void Button2_Click(object sender, EventArgs e) Type t = FindType(); if (t!= null)
object obj = Activator.CreateInstance(t); string s = (string)obj.gettype().invokemember("sayhello", BindingFlags.InvokeMethod BindingFlags.Instance BindingFlags.Public, null, obj, new object[]); Button2.Text = s; FindType 了 HelloClass Type 行 BuildProvider Assemblys 裡 class1.ppp 來 Assembly HelloClass 了 FindType 來 Assemblys 來 HelloClass 連 Assembly 了 來 立 了 Reflection 了 利 Reflection 來 立 HelloClass SayHello 來 class1.ppp 不 來 不 例 易 串 source1.connectionstring = ConnectionStringsExpressionBuilder.GetConnectionString("AppConnectionString1"); 行 數 了 不行 例 #region Using directives using System; using System.Collections.Generic; using System.Text; using System.Web.Compilation;
using System.Reflection; using System.ComponentModel; using System.CodeDom; #endregion namespace TestExpressionBuilder public class MyExpressionBuilder:ExpressionBuilder public override System.CodeDom.CodeExpression GetCodeExpression(System.Web.UI.BoundPropertyEntry entry, object parseddata, ExpressionBuilderContext context) return new CodePrimitiveExpression(entry.Expression); public MyExpressionBuilder() 了 類 串 來 理 不 不 識
. 讀 NET Framework 2.0 Beta 數 Build Provider Expression Builder 了 Microsoft 不