1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
|
//------------------------------------------------------------------------------
// <copyright file="SimpleHandlerBuildProvider.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
namespace System.Web.Compilation {
using System;
using System.IO;
using System.Collections;
using System.Reflection;
using System.CodeDom;
using System.CodeDom.Compiler;
using System.Web.Configuration;
using System.Web.Util;
using System.Web.UI;
[BuildProviderAppliesTo(BuildProviderAppliesTo.Web)]
internal abstract class SimpleHandlerBuildProvider: InternalBuildProvider {
private SimpleWebHandlerParser _parser;
internal override IAssemblyDependencyParser AssemblyDependencyParser {
get { return _parser; }
}
protected abstract SimpleWebHandlerParser CreateParser();
public override CompilerType CodeCompilerType {
get {
Debug.Assert(_parser == null);
_parser = CreateParser();
_parser.SetBuildProvider(this);
_parser.IgnoreParseErrors = IgnoreParseErrors;
_parser.Parse(ReferencedAssemblies);
return _parser.CompilerType;
}
}
protected internal override CodeCompileUnit GetCodeCompileUnit(out IDictionary linePragmasTable) {
Debug.Assert(_parser != null);
CodeCompileUnit ccu = _parser.GetCodeModel();
linePragmasTable = _parser.GetLinePragmasTable();
return ccu;
}
public override void GenerateCode(AssemblyBuilder assemblyBuilder) {
CodeCompileUnit codeCompileUnit = _parser.GetCodeModel();
// Bail if we have nothing we need to compile
if (codeCompileUnit == null)
return;
assemblyBuilder.AddCodeCompileUnit(this, codeCompileUnit);
// Add all the assemblies
if (_parser.AssemblyDependencies != null) {
foreach (Assembly assembly in _parser.AssemblyDependencies) {
assemblyBuilder.AddAssemblyReference(assembly, codeCompileUnit);
}
}
// NOTE: we can't actually generate the fast factory because it would give
// a really bad error if the user specifies a classname which doesn't match
// the actual class they define. A bit unfortunate, but not that big a deal...
// tell the host to generate a fast factory for this type (if any)
//string generatedTypeName = _parser.GeneratedTypeName;
//if (generatedTypeName != null)
// assemblyBuilder.GenerateTypeFactory(generatedTypeName);
}
public override Type GetGeneratedType(CompilerResults results) {
Type t;
if (_parser.HasInlineCode) {
// This is the case where the asmx/ashx has code in the file, and it
// has been compiled.
Debug.Assert(results != null);
t = _parser.GetTypeToCache(results.CompiledAssembly);
}
else {
// This is the case where the asmx/ashx has no code and is simply
// pointing to an existing assembly. Set the UsesExistingAssembly
// flag accordingly.
t = _parser.GetTypeToCache(null);
}
return t;
}
public override ICollection VirtualPathDependencies {
get {
return _parser.SourceDependencies;
}
}
internal CompilerType GetDefaultCompilerTypeForLanguageInternal(string language) {
return GetDefaultCompilerTypeForLanguage(language);
}
internal CompilerType GetDefaultCompilerTypeInternal() {
return GetDefaultCompilerType();
}
internal TextReader OpenReaderInternal() {
return OpenReader();
}
internal override ICollection GetGeneratedTypeNames() {
// Note that _parser.TypeName does not necessarily point to the type defined in the handler file,
// it could be any type that can be referenced at runtime, App_Code for example.
return new SingleObjectCollection(_parser.TypeName);
}
}
internal class WebServiceBuildProvider: SimpleHandlerBuildProvider {
protected override SimpleWebHandlerParser CreateParser() {
return new WebServiceParser(VirtualPath);
}
}
internal class WebHandlerBuildProvider: SimpleHandlerBuildProvider {
protected override SimpleWebHandlerParser CreateParser() {
return new WebHandlerParser(VirtualPath);
}
}
}
|