Files
mono/mcs/class/System.Web/System.Web.Compilation/UserControlCompiler.cs
T
Gonzalo Paniagua Javier 43d7f24f1c 2002-12-12 Gonzalo Paniagua Javier <[email protected]>
* list: Modified file.
	* System.Web/HttpRuntime.cs: avoid nulls and exception when getting
	resource format strings.

	* System.Web/StaticFileHandler.cs: added file name to error message.
	* System.Web.Compilation/AspElements.cs: new method Tag.GetElements
	used to parse the inner contents of a tag looking for data binding or
	code render tags.

	New property HtmlControlTag.ParseChildren allows
	differentiation of a couple of HtmlControls that has children as
	properties (namely HtmlTable and HtmlTableRow).

	* System.Web.Compilation/AspGenerator.cs: fixed container semantics to
	match BindingContainer one. Implemented Inherits attribute for page and
	control.

	Support HtmlControls that has ChildrenAsProperties.

	Generate code for data binding functions that matches the semantic of
	Container.

	Handle data bound and code render attribute values.

	Set proper value return for TemplateSourceDirectory. Should be relative
	to appPath.

	* System.Web.Compilation/BaseCompiler.cs: moved CompilerOptions and
	References handling here.

	* System.Web.Compilation/CachingCompiler.cs: copy result of compilation.

	* System.Web.Compilation/CompilationException.cs: simple ToString ()
	implementation.

	* System.Web.Compilation/CompilationResult.cs: implemented CopyFrom and
	ToString.

	* System.Web.Compilation/GlobalAsaxCompiler.cs:
	* System.Web.Compilation/PageCompiler.cs:
	* System.Web.Compilation/UserControlCompiler.cs: removed
	CompilerOptions as it's now handled in the base class. Get all the
	types in the generated assembly and look for one that derives from
	the correct Type.

	* System.Web.UI/Control.cs: implemented TemplateSourceDirectory.
	* System.Web.UI/TemplateControl.cs: implemented LoadControl and
	LoadTemplate.

	* System.Web.Util/PathUtil.cs: some path handling methods that are not
	available in Path.

svn path=/trunk/mcs/; revision=9583
2002-12-12 03:20:19 +00:00

115 lines
2.9 KiB
C#

//
// System.Web.Compilation.UserControlCompiler
//
// Authors:
// Gonzalo Paniagua Javier ([email protected])
//
// (C) 2002 Ximian, Inc (http://www.ximian.com)
//
using System;
using System.IO;
using System.Reflection;
using System.Web.UI;
using System.Web.Util;
namespace System.Web.Compilation
{
class UserControlCompiler : BaseCompiler
{
UserControlParser userControlParser;
string sourceFile;
string targetFile;
internal UserControlCompiler (UserControlParser userControlParser)
{
this.userControlParser = userControlParser;
}
public override Type GetCompiledType ()
{
string inputFile = userControlParser.InputFile;
sourceFile = GenerateSourceFile (userControlParser);
CachingCompiler compiler = new CachingCompiler (this);
CompilationResult result = new CompilationResult ();
if (compiler.Compile (result) == false)
throw new CompilationException (result);
if (result.Data is Type) {
targetFile = result.OutputFile;
return (Type) result.Data;
}
Assembly assembly = Assembly.LoadFrom (result.OutputFile);
Type [] types = assembly.GetTypes ();
foreach (Type t in types) {
if (t.IsSubclassOf (typeof (UserControl))) {
if (result.Data != null)
throw new CompilationException ("More that 1 user control!!!", result);
result.Data = t;
}
}
return result.Data as Type;
}
public override string Key {
get {
return userControlParser.InputFile;
}
}
public override string SourceFile {
get {
return sourceFile;
}
}
public override string TargetFile {
get {
if (targetFile == null)
targetFile = Path.ChangeExtension (sourceFile, ".dll");
return targetFile;
}
}
public static Type CompileUserControlType (UserControlParser userControlParser)
{
CompilationCacheItem item = CachingCompiler.GetCached (userControlParser.InputFile);
if (item != null && item.Result != null) {
if (item.Result != null)
return item.Result.Data as Type;
throw new CompilationException (item.Result);
}
UserControlCompiler pc = new UserControlCompiler (userControlParser);
return pc.GetCompiledType ();
}
string GenerateSourceFile (UserControlParser userControlParser)
{
string inputFile = userControlParser.InputFile;
Stream input = File.OpenRead (inputFile);
AspParser parser = new AspParser (inputFile, input);
parser.Parse ();
AspGenerator generator = new AspGenerator (inputFile, parser.Elements);
generator.BaseType = userControlParser.BaseType.ToString ();
generator.ProcessElements ();
userControlParser.Text = generator.GetCode ().ReadToEnd ();
options = generator.Options;
//FIXME: should get Tmp dir for this application
string csName = Path.GetTempFileName () + ".cs";
WebTrace.WriteLine ("Writing {0}", csName);
StreamWriter output = new StreamWriter (File.OpenWrite (csName));
output.Write (userControlParser.Text);
output.Close ();
return csName;
}
}
}