Imported Upstream version 4.0.0~alpha1

Former-commit-id: 806294f5ded97629b74c85c09952f2a74fe182d9
This commit is contained in:
Jo Shields
2015-04-07 09:35:12 +01:00
parent 283343f570
commit 3c1f479b9d
22469 changed files with 2931443 additions and 869343 deletions

View File

@@ -0,0 +1,53 @@
//------------------------------------------------------------------------------
// <copyright file="ApplicationFileParser.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
/*
* Implements the ASP.NET template parser
*
* Copyright (c) 1998 Microsoft Corporation
*/
namespace System.Web.UI {
using System;
using System.Collections;
using System.IO;
using System.Web.Util;
using System.Web.Compilation;
using Debug=System.Web.Util.Debug;
/*
* Parser for global.asax files
*/
internal sealed class ApplicationFileParser : TemplateParser {
internal ApplicationFileParser() {}
internal override Type DefaultBaseType { get { return PageParser.DefaultApplicationBaseType ?? typeof(System.Web.HttpApplication); } }
internal override bool FApplicationFile { get { return true; } }
internal const string defaultDirectiveName = "application";
internal override string DefaultDirectiveName {
get { return defaultDirectiveName; }
}
internal override void CheckObjectTagScope(ref ObjectTagScope scope) {
// Map the default scope to AppInstance
if (scope == ObjectTagScope.Default)
scope = ObjectTagScope.AppInstance;
// Check for invalid scopes
if (scope == ObjectTagScope.Page) {
throw new HttpException(
SR.GetString(SR.Page_scope_in_global_asax));
}
}
}
}

View File

@@ -0,0 +1,218 @@
//------------------------------------------------------------------------------
// <copyright file="AttributeCollection.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
/*
* AttributeCollection.cs
*
* Copyright (c) 2000 Microsoft Corporation
*/
namespace System.Web.UI {
using System.IO;
using System.Collections;
using System.Reflection;
using System.Web.UI;
using System.Globalization;
using System.Security.Permissions;
using System.Web.Util;
/*
* The AttributeCollection represents Attributes on an Html control.
*/
/// <devdoc>
/// <para>
/// The <see langword='AttributeCollection'/> class provides object-model access
/// to all attributes declared on an HTML server control element.
/// </para>
/// </devdoc>
public sealed class AttributeCollection {
private StateBag _bag;
private CssStyleCollection _styleColl;
/*
* Constructs an AttributeCollection given a StateBag.
*/
/// <devdoc>
/// </devdoc>
public AttributeCollection(StateBag bag) {
_bag = bag;
}
/*
* Automatically adds new keys.
*/
/// <devdoc>
/// <para>
/// Gets or sets a specified attribute value.
/// </para>
/// </devdoc>
public string this[string key]
{
get {
if (_styleColl != null && StringUtil.EqualsIgnoreCase(key, "style"))
return _styleColl.Value;
else
return _bag[key] as string;
}
set {
Add(key, value);
}
}
/*
* Returns a collection of keys.
*/
/// <devdoc>
/// <para>
/// Gets a collection of keys to all the attributes in the
/// <see langword='AttributeCollection'/>.
/// </para>
/// </devdoc>
public ICollection Keys {
get {
return _bag.Keys;
}
}
/// <devdoc>
/// <para>
/// Gets the number of items in the <see langword='AttributeCollection'/>.
/// </para>
/// </devdoc>
public int Count {
get {
return _bag.Count;
}
}
/// <devdoc>
/// </devdoc>
public CssStyleCollection CssStyle {
get {
if (_styleColl == null) {
_styleColl = new CssStyleCollection(_bag);
}
return _styleColl;
}
}
/// <devdoc>
/// <para>
/// Adds an item to the <see langword='AttributeCollection'/>.
/// </para>
/// </devdoc>
public void Add(string key, string value) {
if (_styleColl != null && StringUtil.EqualsIgnoreCase(key, "style"))
_styleColl.Value = value;
else
_bag[key] = value;
}
public override bool Equals(object o) {
// This implementation of Equals relies on mutable properties and is therefore broken,
// but we shipped it this way in V1 so it will be a breaking change to fix it.
AttributeCollection attrs = o as AttributeCollection;
if (attrs != null) {
if (attrs.Count != _bag.Count) {
return false;
}
foreach (DictionaryEntry attr in _bag) {
if (this[(string)attr.Key] != attrs[(string)attr.Key]) {
return false;
}
}
return true;
}
return false;
}
public override int GetHashCode() {
// This implementation of GetHashCode uses mutable properties but matches the V1 implementation
// of Equals.
HashCodeCombiner hashCodeCombiner = new HashCodeCombiner();
foreach (DictionaryEntry attr in _bag) {
hashCodeCombiner.AddObject(attr.Key);
hashCodeCombiner.AddObject(attr.Value);
}
return hashCodeCombiner.CombinedHash32;
}
/// <devdoc>
/// <para>
/// Removes an attribute from the <see langword='AttributeCollection'/>.
/// </para>
/// </devdoc>
public void Remove(string key) {
if (_styleColl != null && StringUtil.EqualsIgnoreCase(key, "style"))
_styleColl.Clear();
else
_bag.Remove(key);
}
/// <devdoc>
/// <para>
/// Removes all attributes from the <see langword='AttributeCollection'/>.
/// </para>
/// </devdoc>
public void Clear() {
_bag.Clear();
if (_styleColl != null)
_styleColl.Clear();
}
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public void Render(HtmlTextWriter writer) {
if (_bag.Count > 0) {
IDictionaryEnumerator e = _bag.GetEnumerator();
while (e.MoveNext()) {
StateItem item = e.Value as StateItem;
if (item != null) {
string value = item.Value as string;
string key = e.Key as string;
if (key != null && value != null) {
writer.WriteAttribute(key, value, true /*fEncode*/);
}
}
}
}
}
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public void AddAttributes(HtmlTextWriter writer) {
if (_bag.Count > 0) {
IDictionaryEnumerator e = _bag.GetEnumerator();
while (e.MoveNext()) {
StateItem item = e.Value as StateItem;
if (item != null) {
string value = item.Value as string;
string key = e.Key as string;
if (key != null && value != null) {
writer.AddAttribute(key, value, true /*fEncode*/);
}
}
}
}
}
}
}

View File

@@ -0,0 +1,133 @@
//------------------------------------------------------------------------------
// <copyright file="BaseParser.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
/*
* Implements the ASP.NET template parser
*
* Copyright (c) 1998 Microsoft Corporation
*/
/*********************************
Class hierarchy
BaseParser
DependencyParser
TemplateControlDependencyParser
PageDependencyParser
UserControlDependencyParser
MasterPageDependencyParser
TemplateParser
BaseTemplateParser
TemplateControlParser
PageParser
UserControlParser
MasterPageParser
PageThemeParser
ApplicationFileParser
**********************************/
namespace System.Web.UI {
using System;
using System.Collections;
using System.Reflection;
using System.Web.Compilation;
using System.Web.Hosting;
using System.Web.Util;
using System.Text.RegularExpressions;
using System.Web.RegularExpressions;
using System.Security.Permissions;
// Internal interface for Parser that have exteranl assembly dependency.
internal interface IAssemblyDependencyParser {
ICollection AssemblyDependencies { get; }
}
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public class BaseParser {
// The directory used for relative path calculations
private VirtualPath _baseVirtualDir;
internal VirtualPath BaseVirtualDir {
get { return _baseVirtualDir; }
}
// The virtual path to the file currently being processed
private VirtualPath _currentVirtualPath;
internal VirtualPath CurrentVirtualPath {
get { return _currentVirtualPath; }
set {
_currentVirtualPath = value;
// Can happen in the designer
if (value == null) return;
_baseVirtualDir = value.Parent;
}
}
internal string CurrentVirtualPathString {
get { return System.Web.VirtualPath.GetVirtualPathString(CurrentVirtualPath); }
}
private Regex _tagRegex;
// The 3.5 regex is used only when targeting 2.0/3.5 for backward compatibility (Dev10 bug 830783).
private readonly static Regex tagRegex35 = new TagRegex35();
// The 4.0 regex is used for web sites targeting 4.0 and above.
private readonly static Regex tagRegex40 = new TagRegex();
internal readonly static Regex directiveRegex = new DirectiveRegex();
internal readonly static Regex endtagRegex = new EndTagRegex();
internal readonly static Regex aspCodeRegex = new AspCodeRegex();
internal readonly static Regex aspExprRegex = new AspExprRegex();
internal readonly static Regex aspEncodedExprRegex = new AspEncodedExprRegex();
internal readonly static Regex databindExprRegex = new DatabindExprRegex();
internal readonly static Regex commentRegex = new CommentRegex();
internal readonly static Regex includeRegex = new IncludeRegex();
internal readonly static Regex textRegex = new TextRegex();
// Regexes used in DetectSpecialServerTagError
internal readonly static Regex gtRegex = new GTRegex();
internal readonly static Regex ltRegex = new LTRegex();
internal readonly static Regex serverTagsRegex = new ServerTagsRegex();
internal readonly static Regex runatServerRegex = new RunatServerRegex();
/*
* Turns relative virtual path into absolute ones
*/
internal VirtualPath ResolveVirtualPath(VirtualPath virtualPath) {
return VirtualPathProvider.CombineVirtualPathsInternal(CurrentVirtualPath, virtualPath);
}
private bool IsVersion40OrAbove() {
if (HostingEnvironment.IsHosted) {
// If we are running in a hosted environment, then we can simply check the target version.
return MultiTargetingUtil.IsTargetFramework40OrAbove;
}
else {
// Otherwise, we are in the designer, and thus should check using the type description provider.
// The new type TagRegex35 only exists when targeting 4.0 and above.
return TargetFrameworkUtil.IsSupportedType(typeof(TagRegex35));
}
}
internal Regex TagRegex {
get {
if (_tagRegex == null) {
_tagRegex = IsVersion40OrAbove() ? tagRegex40 : tagRegex35;
}
return _tagRegex;
}
}
}
}

View File

@@ -0,0 +1,355 @@
//------------------------------------------------------------------------------
// <copyright file="BaseTemplateParser.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
/*
* Implements the ASP.NET template parser
*
* Copyright (c) 1998 Microsoft Corporation
*/
namespace System.Web.UI {
using System.Text;
using System;
using System.IO;
using System.Collections;
using System.Collections.Specialized;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Reflection;
using System.Configuration;
using System.Web.Caching;
using System.Web.Util;
using System.Web.Hosting;
using System.Web.Compilation;
using HttpException = System.Web.HttpException;
using System.Text.RegularExpressions;
using System.Globalization;
using System.Security.Permissions;
/*
* Parser for Template Files (TemplateControls and PageTheme)
*/
/// <internalonly/>
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public abstract class BaseTemplateParser : TemplateParser {
private const string _sourceString = "src";
private const string _namespaceString = "namespace";
private const string _tagnameString = "tagname";
internal Type GetDesignTimeUserControlType(string tagPrefix, string tagName) {
Debug.Assert(FInDesigner);
Type type = typeof(UserControl);
IDesignerHost host = DesignerHost;
if (host != null) {
IUserControlTypeResolutionService ucTypeResService =
(IUserControlTypeResolutionService)host.GetService(typeof(IUserControlTypeResolutionService));
if (ucTypeResService != null) {
try {
type = ucTypeResService.GetType(tagPrefix, tagName);
}
catch {
}
}
}
return type;
}
/*
* Compile a nested .ascx file (a User Control) and return its Type
*/
protected internal Type GetUserControlType(string virtualPath) {
return GetUserControlType(VirtualPath.Create(virtualPath));
}
internal Type GetUserControlType(VirtualPath virtualPath) {
Type t = GetReferencedType(virtualPath, false /*allowNoCompile*/);
// Fail if it's a no compile uc, since it doesn't have a Type we can use
if (t == null) {
// First, check whether there is a PageParserFilter that can give us a type
if (_pageParserFilter != null)
t = _pageParserFilter.GetNoCompileUserControlType();
if (t == null)
ProcessError(SR.GetString(SR.Cant_use_nocompile_uc, virtualPath));
}
else {
// Make sure it has the correct base type
Util.CheckAssignableType(typeof(UserControl), t);
}
return t;
}
/*
* Compile a .aspx/.ascx file and return its Type
*/
protected Type GetReferencedType(string virtualPath) {
return GetReferencedType(VirtualPath.Create(virtualPath));
}
internal Type GetReferencedType(VirtualPath virtualPath) {
return GetReferencedType(virtualPath, true /*allowNoCompile*/);
}
internal Type GetReferencedType(VirtualPath virtualPath, bool allowNoCompile) {
virtualPath = ResolveVirtualPath(virtualPath);
// If we have a page parser filter, make sure the reference is allowed
if (_pageParserFilter != null && !_pageParserFilter.AllowVirtualReference(CompConfig, virtualPath)) {
ProcessError(SR.GetString(SR.Reference_not_allowed, virtualPath));
}
BuildResult result = null;
Type t = null;
try {
result = BuildManager.GetVPathBuildResult(virtualPath);
}
catch (HttpCompileException e) {
// Add the path depdencies properly so we know when
// to invalidate the cached result.
if (e.VirtualPathDependencies != null) {
foreach (string vPath in e.VirtualPathDependencies) {
AddSourceDependency(VirtualPath.Create(vPath));
}
}
throw;
}
catch {
// Add the virtualPath to the dependency so that
// we know when to check again. This could happen if the
// virtualPath points to a file not created yet.
// This only affects designtime code path since we do want to return
// partial result even if there is an error, and that result is
// cached. VSWhidbey 372585
if (IgnoreParseErrors) {
AddSourceDependency(virtualPath);
}
throw;
}
// Is it a no-compile page/uc
BuildResultNoCompileTemplateControl noCompileResult = result as BuildResultNoCompileTemplateControl;
if (noCompileResult != null) {
// If no-compile is not acceptable, return null
if (!allowNoCompile)
return null;
// In the no-compile case, use the base type, since we don't compile a type
t = noCompileResult.BaseType;
}
else if (result is BuildResultCompiledType) {
BuildResultCompiledType compiledResult = (BuildResultCompiledType) result;
Debug.Assert(compiledResult != null);
t = compiledResult.ResultType;
}
else {
throw new HttpException(SR.GetString(SR.Invalid_typeless_reference, _sourceString));
}
Debug.Assert(t != null);
// Add a dependency on the Type
AddTypeDependency(t);
// Add a dependency on the BuildResult
AddBuildResultDependency(result);
return t;
}
internal override void ProcessDirective(string directiveName, IDictionary directive) {
if (StringUtil.EqualsIgnoreCase(directiveName, "register")) {
// Register directive
// Get the tagprefix, which is required
string tagPrefix = Util.GetAndRemoveNonEmptyIdentifierAttribute(directive,
"tagprefix", true /*required*/);
string tagName = Util.GetAndRemoveNonEmptyIdentifierAttribute(directive,
_tagnameString, false /*required*/);
VirtualPath src = Util.GetAndRemoveVirtualPathAttribute(directive,
_sourceString, false /*required*/);
string ns = Util.GetAndRemoveNonEmptyNoSpaceAttribute(directive,
_namespaceString, false /*required*/);
// An Assembly can optionally be specified (ASURT 61326/VSWhidbey 87050)
string assemblyName = Util.GetAndRemoveNonEmptyAttribute(directive, "assembly",
false /*required*/);
RegisterDirectiveEntry registerEntry;
if (tagName != null) {
// It's a user control registration
// 'src' is required
if (src == null) {
throw new HttpException(SR.GetString(SR.Missing_attr, _sourceString));
}
// 'namespace' is not allowed
if (ns != null) {
throw new HttpException(
SR.GetString(SR.Invalid_attr, _namespaceString, "tagname"));
}
// 'assembly' is not allowed
if (assemblyName != null) {
throw new HttpException(
SR.GetString(SR.Invalid_attr, "assembly", "tagname"));
}
UserControlRegisterEntry ucRegisterEntry = new UserControlRegisterEntry(tagPrefix, tagName);
ucRegisterEntry.UserControlSource = src;
registerEntry = ucRegisterEntry;
TypeMapper.ProcessUserControlRegistration(ucRegisterEntry);
}
else if (src != null) {
// It's missing the tagname attribute.
throw new HttpException(SR.GetString(SR.Missing_attr, _tagnameString));
}
else {
// It's a namespace prefix registration
// 'namespace' is required
if (ns == null) {
throw new HttpException(SR.GetString(SR.Missing_attr, _namespaceString));
}
TagNamespaceRegisterEntry nsRegisterEntry = new TagNamespaceRegisterEntry(tagPrefix, ns, assemblyName);
registerEntry = nsRegisterEntry;
TypeMapper.ProcessTagNamespaceRegistration(nsRegisterEntry);
}
registerEntry.Line = _lineNumber;
registerEntry.VirtualPath = CurrentVirtualPathString;
// If there are some attributes left, fail
Util.CheckUnknownDirectiveAttributes(directiveName, directive);
}
else {
base.ProcessDirective(directiveName, directive);
}
}
}
/*
* Entry representing a register directive
* e.g. <%@ Register tagprefix="tagprefix" Namespace="namespace" Assembly="assembly" %> OR
* e.g. <%@ Register tagprefix="tagprefix" Tagname="tagname" Src="pathname" %>
*/
internal abstract class RegisterDirectiveEntry: SourceLineInfo {
internal RegisterDirectiveEntry(string tagPrefix) {
_tagPrefix = tagPrefix;
}
private string _tagPrefix;
internal string TagPrefix {
get { return _tagPrefix;}
}
}
/*
* Entry representing the registration of a tag namespace
* e.g. <%@ Register tagprefix="tagprefix" Namespace="namespace" Assembly="assembly" %>
*/
internal class TagNamespaceRegisterEntry: RegisterDirectiveEntry {
internal TagNamespaceRegisterEntry(string tagPrefix, string namespaceName, string assemblyName) : base(tagPrefix) {
_ns = namespaceName;
_assemblyName = assemblyName;
}
private string _ns;
internal string Namespace {
get { return _ns;}
}
private string _assemblyName;
internal string AssemblyName {
get { return _assemblyName;}
}
#if DONT_COMPILE
internal string Key {
get {
return TagPrefix + ":" + _ns + ":" + (_assemblyName == null ? String.Empty : _assemblyName);
}
}
#endif
}
/*
* Entry representing the registration of a user control
* e.g. <%@ Register tagprefix="tagprefix" Tagname="tagname" Src="pathname" %>
*/
internal class UserControlRegisterEntry: RegisterDirectiveEntry {
internal UserControlRegisterEntry(string tagPrefix, string tagName) : base(tagPrefix) {
_tagName = tagName;
}
private string _tagName;
internal string TagName {
get { return _tagName;}
}
private VirtualPath _source;
internal VirtualPath UserControlSource {
get { return _source;}
set { _source = value;}
}
private bool _comesFromConfig;
internal bool ComesFromConfig {
get { return _comesFromConfig;}
set { _comesFromConfig = value;}
}
internal string Key {
get {
return TagPrefix + ":" + _tagName;
}
}
}
internal class TagNamespaceRegisterEntryTable : Hashtable {
public TagNamespaceRegisterEntryTable() : base(StringComparer.OrdinalIgnoreCase) {
}
public override object Clone() {
// We override clone to perform a deep copy of the hashtable contents but a shallow copy of
// the contained arraylist itself
TagNamespaceRegisterEntryTable newTable = new TagNamespaceRegisterEntryTable();
foreach (DictionaryEntry entry in this) {
newTable[entry.Key] = ((ArrayList)entry.Value).Clone();
}
return newTable;
}
}
}

View File

@@ -0,0 +1,395 @@
//------------------------------------------------------------------------------
// <copyright file="BatchParser.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
namespace System.Web.UI {
using System;
using System.IO;
using System.Web.Configuration;
using System.Collections;
using System.Collections.Specialized;
using System.Threading;
using System.Globalization;
using System.Web.Hosting;
using System.Web.Caching;
using System.Web.Util;
using System.Web.Compilation;
using HttpException = System.Web.HttpException;
using Debug=System.Web.Util.Debug;
using System.Text.RegularExpressions;
internal abstract class DependencyParser : BaseParser {
private VirtualPath _virtualPath;
private StringSet _virtualPathDependencies;
// Used to detect circular references
private StringSet _circularReferenceChecker = new CaseInsensitiveStringSet();
// The <pages> config section
private PagesSection _pagesConfig;
protected PagesSection PagesConfig {
get { return _pagesConfig; }
}
internal void Init(VirtualPath virtualPath) {
CurrentVirtualPath = virtualPath;
_virtualPath = virtualPath;
_pagesConfig = MTConfigUtil.GetPagesConfig(virtualPath);
}
internal ICollection GetVirtualPathDependencies() {
// Always set the culture to Invariant when parsing (ASURT 99071)
Thread currentThread = Thread.CurrentThread;
CultureInfo prevCulture = currentThread.CurrentCulture;
HttpRuntime.SetCurrentThreadCultureWithAssert(CultureInfo.InvariantCulture);
try {
try {
PrepareParse();
ParseFile();
}
finally {
// Restore the previous culture
HttpRuntime.SetCurrentThreadCultureWithAssert(prevCulture);
}
}
catch { throw; } // Prevent Exception Filter Security Issue (ASURT 122835)
return _virtualPathDependencies;
}
protected void AddDependency(VirtualPath virtualPath) {
virtualPath = ResolveVirtualPath(virtualPath);
Debug.Trace("Template", "Parsed dependency: " + _virtualPath + " depends on " + virtualPath);
if (_virtualPathDependencies == null)
_virtualPathDependencies = new CaseInsensitiveStringSet();
_virtualPathDependencies.Add(virtualPath.VirtualPathString);
}
internal abstract string DefaultDirectiveName { get; }
protected virtual void PrepareParse() {}
private void ParseFile() {
ParseFile(null /*physicalPath*/, _virtualPath);
}
private void ParseFile(string physicalPath, VirtualPath virtualPath) {
// Determine the file used for the circular references checker. Normally,
// we use the virtualPath, but we use the physical path if it specified,
// as is the case for <!-- #include file="foo.inc" -->
string fileToReferenceCheck = physicalPath != null ? physicalPath : virtualPath.VirtualPathString;
// Check for circular references of include files
if (_circularReferenceChecker.Contains(fileToReferenceCheck)) {
throw new HttpException(
SR.GetString(SR.Circular_include));
}
// Add the current file to the circular references checker.
_circularReferenceChecker.Add(fileToReferenceCheck);
try {
// Open a TextReader either from the physical or virtual path
TextReader reader;
if (physicalPath != null) {
using (reader = Util.ReaderFromFile(physicalPath, virtualPath)) {
ParseReader(reader);
}
}
else {
using (Stream stream = virtualPath.OpenFile()) {
reader = Util.ReaderFromStream(stream, virtualPath);
ParseReader(reader);
}
}
}
finally {
// Remove the current file from the circular references checker
_circularReferenceChecker.Remove(fileToReferenceCheck);
}
}
private void ParseReader(TextReader input) {
ParseString(input.ReadToEnd());
}
private void ParseString(string text) {
int textPos = 0;
for (;;) {
Match match;
// 1: scan for text up to the next tag.
if ((match = textRegex.Match(text, textPos)).Success) {
textPos = match.Index + match.Length;
}
// we might be done now
if (textPos == text.Length)
break;
// 2: handle constructs that start with <
// Check to see if it's a directive (i.e. <%@ %> block)
if ((match = directiveRegex.Match(text, textPos)).Success) {
IDictionary directive = CollectionsUtil.CreateCaseInsensitiveSortedList();
string directiveName = ProcessAttributes(match, directive);
ProcessDirective(directiveName, directive);
textPos = match.Index + match.Length;
}
else if ((match = includeRegex.Match(text, textPos)).Success) {
ProcessServerInclude(match);
textPos = match.Index + match.Length;
}
else if ((match = commentRegex.Match(text, textPos)).Success) {
// Just skip it
textPos = match.Index + match.Length;
}
else {
int newPos = text.IndexOf("<%@", textPos, StringComparison.Ordinal);
// 2nd condition is used to catch invalid directives, e.g. <%@ attr="value_without_end_quote >
if (newPos == -1 || newPos == textPos) {
return;
}
textPos = newPos;
}
// we might be done now
if (textPos == text.Length)
return;
}
}
/*
* Process a server side include. e.g. <!-- #include file="foo.inc" -->
*/
private void ProcessServerInclude(Match match) {
string pathType = match.Groups["pathtype"].Value;
string filename = match.Groups["filename"].Value;
if (filename.Length == 0) return;
VirtualPath newVirtualPath;
string newPhysicalPath = null;
if (StringUtil.EqualsIgnoreCase(pathType, "file")) {
if (UrlPath.IsAbsolutePhysicalPath(filename)) {
// If it's an absolute physical path, use it as is
newPhysicalPath = filename;
// Reuse the current virtual path
newVirtualPath = CurrentVirtualPath;
}
else {
// If it's relative, just treat it as virtual
newVirtualPath = ResolveVirtualPath(VirtualPath.Create(filename));
}
}
else if (StringUtil.EqualsIgnoreCase(pathType, "virtual")) {
newVirtualPath = ResolveVirtualPath(VirtualPath.Create(filename));
}
else {
// Unknown #include type: ignore it
return;
}
VirtualPath prevVirtualPath = _virtualPath;
try {
_virtualPath = newVirtualPath;
// Parse the included file recursively
ParseFile(newPhysicalPath, newVirtualPath);
}
finally {
// Restore the paths
_virtualPath = prevVirtualPath;
}
}
/*
* Process a <%@ %> block
*/
internal virtual void ProcessDirective(string directiveName, IDictionary directive) {
// Get all the directives into a bag
// Check for the main directive (e.g. "page" for an aspx)
if (directiveName == null ||
StringUtil.EqualsIgnoreCase(directiveName, DefaultDirectiveName) ) {
ProcessMainDirective(directive);
}
else if (StringUtil.EqualsIgnoreCase(directiveName, "register")) {
VirtualPath src = Util.GetAndRemoveVirtualPathAttribute(directive, "src");
if (src != null) {
AddDependency(src);
}
}
else if (StringUtil.EqualsIgnoreCase(directiveName, "reference")) {
VirtualPath virtualPath = Util.GetAndRemoveVirtualPathAttribute(directive, "virtualpath");
if (virtualPath != null)
AddDependency(virtualPath);
VirtualPath page = Util.GetAndRemoveVirtualPathAttribute(directive, "page");
if (page != null)
AddDependency(page);
VirtualPath control = Util.GetAndRemoveVirtualPathAttribute(directive, "control");
if (control != null)
AddDependency(control);
}
else if (StringUtil.EqualsIgnoreCase(directiveName, "assembly")) {
VirtualPath src = Util.GetAndRemoveVirtualPathAttribute(directive, "src");
if (src != null)
AddDependency(src);
}
}
private void ProcessMainDirective(IDictionary mainDirective) {
// Go through all the attributes on the directive
foreach (DictionaryEntry entry in mainDirective) {
string attribName = ((string)entry.Key).ToLower(CultureInfo.InvariantCulture);
// Parse out the device name, if any
string name;
string deviceName = Util.ParsePropertyDeviceFilter(attribName, out name);
// Process the attribute
ProcessMainDirectiveAttribute(deviceName, name, (string) entry.Value);
}
}
internal virtual void ProcessMainDirectiveAttribute(string deviceName, string name,
string value) {
// A "src" attribute is equivalent to an imported source file
if (name == "src") {
string src = Util.GetNonEmptyAttribute(name, value);
AddDependency(VirtualPath.Create(src));
}
}
/*
* Adds attributes and their values to the attribs
*/
private string ProcessAttributes(Match match, IDictionary attribs) {
string ret = null;
CaptureCollection attrnames = match.Groups["attrname"].Captures;
CaptureCollection attrvalues = match.Groups["attrval"].Captures;
CaptureCollection equalsign = match.Groups["equal"].Captures;
for (int i = 0; i < attrnames.Count; i++) {
string attribName = attrnames[i].ToString();
string attribValue = attrvalues[i].ToString();
bool fHasEqual = (equalsign[i].ToString().Length > 0);
if (attribName != null && !fHasEqual && ret == null) {
ret = attribName;
continue;
}
try {
if (attribs != null)
attribs.Add(attribName, attribValue);
}
catch (ArgumentException) {}
}
return ret;
}
}
internal abstract class TemplateControlDependencyParser : DependencyParser {
internal override void ProcessMainDirectiveAttribute(string deviceName, string name,
string value) {
switch (name) {
case "masterpagefile":
value = value.Trim();
if (value.Length > 0) {
// Add a dependency on the master, whether it has a device filter or not
AddDependency(VirtualPath.Create(value));
}
break;
default:
// We didn't handle the attribute. Try the base class
base.ProcessMainDirectiveAttribute(deviceName, name, value);
break;
}
}
}
internal class PageDependencyParser : TemplateControlDependencyParser {
internal override string DefaultDirectiveName {
get { return PageParser.defaultDirectiveName; }
}
protected override void PrepareParse() {
if (PagesConfig != null) {
if (PagesConfig.MasterPageFileInternal != null && PagesConfig.MasterPageFileInternal.Length != 0)
AddDependency(VirtualPath.Create(PagesConfig.MasterPageFileInternal));
}
}
internal override void ProcessDirective(string directiveName, IDictionary directive) {
base.ProcessDirective(directiveName, directive);
if (StringUtil.EqualsIgnoreCase(directiveName, "previousPageType") ||
StringUtil.EqualsIgnoreCase(directiveName, "masterType")) {
VirtualPath virtualPath = Util.GetAndRemoveVirtualPathAttribute(directive, "virtualPath");
if (virtualPath != null)
AddDependency(virtualPath);
}
}
}
internal class UserControlDependencyParser : TemplateControlDependencyParser {
internal override string DefaultDirectiveName {
get { return UserControlParser.defaultDirectiveName; }
}
}
internal class MasterPageDependencyParser : UserControlDependencyParser {
internal override string DefaultDirectiveName {
get { return MasterPageParser.defaultDirectiveName; }
}
internal override void ProcessDirective(string directiveName, IDictionary directive) {
base.ProcessDirective(directiveName, directive);
if (StringUtil.EqualsIgnoreCase(directiveName, "masterType")) {
VirtualPath virtualPath = Util.GetAndRemoveVirtualPathAttribute(directive, "virtualPath");
if (virtualPath != null)
AddDependency(virtualPath);
}
}
}
}

View File

@@ -0,0 +1,195 @@
//------------------------------------------------------------------------------
// <copyright file="BindableTemplateBuilder.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
/*
* Classes related to templated control support
*
* Copyright (c) 1999 Microsoft Corporation
*/
namespace System.Web.UI {
using System;
using System.Collections;
using System.Collections.Specialized;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Globalization;
using System.Reflection;
using System.Security.Permissions;
using System.Web.Util;
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public sealed class BindableTemplateBuilder : TemplateBuilder, IBindableTemplate {
private ExtractTemplateValuesMethod _extractTemplateValuesMethod;
/*
* No-compile delegate handler for ExtractValues.
*/
private IOrderedDictionary ExtractTemplateValuesMethod(Control container) {
/*System.Web.UI.OrderedDictionary @__table;
System.Web.UI.WebControls.DropDownList ddl2;
@__table = new System.Web.UI.OrderedDictionary();
ddl2 = ((System.Web.UI.WebControls.DropDownList)(@__container.FindControl("ddl2")));
if ((ddl2 != null)) {
@__table["FavVegetable"] = ddl2.SelectedValue;
}
return @__table;*/
BindableTemplateBuilder bindableTemplateBuilder = this as BindableTemplateBuilder;
Debug.Assert(bindableTemplateBuilder != null, "ExtractTemplateValuesMethod called on non-BindableTemplateBuilder.");
OrderedDictionary table = new OrderedDictionary();
if (bindableTemplateBuilder != null) {
ExtractTemplateValuesRecursive(bindableTemplateBuilder.SubBuilders, table, container);
}
return table;
}
private void ExtractTemplateValuesRecursive(ArrayList subBuilders, OrderedDictionary table, Control container) {
foreach (object subBuilderObject in subBuilders) {
ControlBuilder subBuilderControlBuilder = subBuilderObject as ControlBuilder;
if (subBuilderControlBuilder != null) {
ICollection entries;
// filter out device filtered bound entries that don't apply to this device
if (!subBuilderControlBuilder.HasFilteredBoundEntries) {
entries = subBuilderControlBuilder.BoundPropertyEntries;
}
else {
Debug.Assert(subBuilderControlBuilder.ServiceProvider == null);
Debug.Assert(subBuilderControlBuilder.TemplateControl != null, "TemplateControl should not be null in no-compile pages. We need it for the FilterResolutionService.");
ServiceContainer serviceContainer = new ServiceContainer();
serviceContainer.AddService(typeof(IFilterResolutionService), subBuilderControlBuilder.TemplateControl);
try {
subBuilderControlBuilder.SetServiceProvider(serviceContainer);
entries = subBuilderControlBuilder.GetFilteredPropertyEntrySet(subBuilderControlBuilder.BoundPropertyEntries);
}
finally {
subBuilderControlBuilder.SetServiceProvider(null);
}
}
string previousControlName = null;
bool newControl = true;
Control control = null;
foreach (BoundPropertyEntry entry in entries) {
// Skip all entries that are not two-way
if (!entry.TwoWayBound)
continue;
// Reset the "previous" Property Entry if we're not looking at the same control.
// If we don't do this, Two controls that have conditionals on the same named property will have
// their conditionals incorrectly merged.
if (String.Compare(previousControlName, entry.ControlID, StringComparison.Ordinal) != 0) {
newControl = true;
}
else {
newControl = false;
}
previousControlName = entry.ControlID;
if (newControl) {
control = container.FindControl(entry.ControlID);
if (control == null || !entry.ControlType.IsInstanceOfType(control)) {
Debug.Assert(false, "BoundPropertyEntry is of wrong control type or couldn't be found. Expected " + entry.ControlType.Name);
continue;
}
}
string propertyName;
// map the property in case it's a complex property
object targetObject = PropertyMapper.LocatePropertyObject(control, entry.Name, out propertyName, InDesigner);
// FastPropertyAccessor uses ReflectEmit for lightning speed
table[entry.FieldName] = FastPropertyAccessor.GetProperty(targetObject, propertyName, InDesigner);
}
ExtractTemplateValuesRecursive(subBuilderControlBuilder.SubBuilders, table, container);
}
}
}
/*
* IBindableTemplate implementation
* This implementation of ITemplate is used in the designer and no-compile.
*/
public IOrderedDictionary ExtractValues(Control container) {
if (_extractTemplateValuesMethod != null && !InDesigner) {
return _extractTemplateValuesMethod(container);
}
return new OrderedDictionary();
}
public override void OnAppendToParentBuilder(ControlBuilder parentBuilder) {
base.OnAppendToParentBuilder(parentBuilder);
if (HasTwoWayBoundProperties) {
_extractTemplateValuesMethod = new ExtractTemplateValuesMethod(ExtractTemplateValuesMethod);
}
}
}
// Delegates used for the compiled template and no-compile Bind
/// <internalonly/>
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public delegate IOrderedDictionary ExtractTemplateValuesMethod(Control control);
/*
* This class is the ITemplate implementation that is called from the
* generated page class code. It just passes the Initialize call on to a
* delegate.
*/
/// <internalonly/>
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public sealed class CompiledBindableTemplateBuilder : IBindableTemplate {
private BuildTemplateMethod _buildTemplateMethod;
private ExtractTemplateValuesMethod _extractTemplateValuesMethod;
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public CompiledBindableTemplateBuilder(BuildTemplateMethod buildTemplateMethod, ExtractTemplateValuesMethod extractTemplateValuesMethod) {
_buildTemplateMethod = buildTemplateMethod;
_extractTemplateValuesMethod = extractTemplateValuesMethod;
}
// IBindableTemplate::ExtractValues
/// <devdoc>
/// <para>Calls the ExtractTemplateValuesMethod delegate, which will return a dictionary of values.</para>
/// </devdoc>
public IOrderedDictionary ExtractValues(Control container) {
if (_extractTemplateValuesMethod != null) {
return _extractTemplateValuesMethod(container);
}
return new OrderedDictionary();
}
// ITemplate::InstantiateIn
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public void InstantiateIn(Control container) {
_buildTemplateMethod(container);
}
}
}

View File

@@ -0,0 +1,203 @@
//------------------------------------------------------------------------------
// <copyright file="BoundPropertyEntry.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
namespace System.Web.UI {
using System.Reflection;
using System.Web.Util;
using System.Web.Compilation;
using System.ComponentModel.Design;
using System.Security.Permissions;
/// <devdoc>
/// PropertyEntry for any bound properties
/// </devdoc>
public class BoundPropertyEntry : PropertyEntry {
private string _expression;
private ExpressionBuilder _expressionBuilder;
private string _expressionPrefix;
private bool _useSetAttribute;
private object _parsedExpressionData;
private bool _generated;
private string _fieldName;
private string _formatString;
private string _controlID;
private Type _controlType;
private bool _readOnlyProperty;
private bool _twoWayBound;
internal BoundPropertyEntry() {
}
/// <devdoc>
/// The id of the control that contains this binding.
/// </devdoc>
public string ControlID {
get {
return _controlID;
}
set {
_controlID = value;
}
}
/// <devdoc>
/// The type of the control which is being bound to a runtime value.
/// </devdoc>
public Type ControlType {
get {
return _controlType;
}
set {
_controlType = value;
}
}
/// <devdoc>
/// </devdoc>
public string Expression {
get {
return _expression;
}
set {
_expression = value;
}
}
public ExpressionBuilder ExpressionBuilder {
get {
return _expressionBuilder;
}
set {
_expressionBuilder = value;
}
}
public string ExpressionPrefix {
get {
return _expressionPrefix;
}
set {
_expressionPrefix = value;
}
}
/// <devdoc>
/// The name of the data field that is being bound to.
/// </devdoc>
public string FieldName {
get {
return _fieldName;
}
set {
_fieldName = value;
}
}
/// <devdoc>
/// The format string applied to the field for display.
/// </devdoc>
public string FormatString {
get {
return _formatString;
}
set {
_formatString = value;
}
}
internal bool IsDataBindingEntry {
// Empty prefix means it's a databinding expression (i.e. <%# ... %>)
get { return String.IsNullOrEmpty(ExpressionPrefix); }
}
/// <summary>
/// This represents the column value where the property value begins.
/// Currently only calculated for data bound property entries, for other type
/// of Bound Properties it has default value which is 0.
/// </summary>
internal int Column {
get;
set;
}
/// <summary>
/// This represents the line value where the property value is present.
/// Currently only calculated for data bound property entries, for other type
/// of Bound Properties it has default value which is 0.
/// </summary>
internal int Line {
get;
set;
}
public bool Generated {
get {
return _generated;
}
set {
_generated = value;
}
}
public object ParsedExpressionData {
get {
return _parsedExpressionData;
}
set {
_parsedExpressionData = value;
}
}
/// <devdoc>
/// Indicates whether the two way statement is set and get, or just get but not set.
/// </devdoc>
public bool ReadOnlyProperty {
get {
return _readOnlyProperty;
}
set {
_readOnlyProperty = value;
}
}
public bool TwoWayBound {
get {
return _twoWayBound;
}
set {
_twoWayBound = value;
}
}
/// <devdoc>
/// </devdoc>
public bool UseSetAttribute {
get {
return _useSetAttribute;
}
set {
_useSetAttribute = value;
}
}
public bool IsEncoded {
get;
set;
}
// Parse the expression, and store the resulting object
internal void ParseExpression(ExpressionBuilderContext context) {
if (Expression == null || ExpressionPrefix == null || ExpressionBuilder == null)
return;
_parsedExpressionData = ExpressionBuilder.ParseExpression(Expression, Type, context);
}
}
}

View File

@@ -0,0 +1,31 @@
//------------------------------------------------------------------------------
// <copyright file="BuilderPropertyEntry.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
namespace System.Web.UI {
/// <devdoc>
/// Abstract base class for all property entries that require a ControlBuilder
/// </devdoc>
public abstract class BuilderPropertyEntry : PropertyEntry {
private ControlBuilder _builder;
internal BuilderPropertyEntry() {
}
/// <devdoc>
/// </devdoc>
public ControlBuilder Builder {
get {
return _builder;
}
set {
_builder = value;
}
}
}
}

View File

@@ -0,0 +1,193 @@
//------------------------------------------------------------------------------
// <copyright file="ChtmlTextWriter.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
// ChtmlTextWriter.cs
//
namespace System.Web.UI {
using System;
using System.Collections;
using System.Collections.Specialized;
using System.IO;
using System.Text;
using System.Web.UI.WebControls;
using System.Web.Util;
using System.Globalization;
using System.Security.Permissions;
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public class ChtmlTextWriter : Html32TextWriter {
private Hashtable _recognizedAttributes = new Hashtable(StringComparer.CurrentCultureIgnoreCase);
private Hashtable _suppressedAttributes = new Hashtable(StringComparer.CurrentCultureIgnoreCase);
private Hashtable _globalSuppressedAttributes = new Hashtable(StringComparer.CurrentCultureIgnoreCase);
public ChtmlTextWriter(TextWriter writer) : this(writer, DefaultTabString) {
}
public ChtmlTextWriter(TextWriter writer, string tabString) : base(writer, tabString) {
_globalSuppressedAttributes["onclick"] = true;
_globalSuppressedAttributes["ondblclick"] = true;
_globalSuppressedAttributes["onmousedown"] = true;
_globalSuppressedAttributes["onmouseup"] = true;
_globalSuppressedAttributes["onmouseover"] = true;
_globalSuppressedAttributes["onmousemove"] = true;
_globalSuppressedAttributes["onmouseout"] = true;
_globalSuppressedAttributes["onkeypress"] = true;
_globalSuppressedAttributes["onkeydown"] = true;
_globalSuppressedAttributes["onkeyup"] = true;
// Supress certain element attribute pairs that can happen when Html32TextWriter performs the div table
// substitution.
RemoveRecognizedAttributeInternal("div", "accesskey"); // VSWhidbey 270254
RemoveRecognizedAttributeInternal("div", "cellspacing");
RemoveRecognizedAttributeInternal("div", "cellpadding");
RemoveRecognizedAttributeInternal("div", "gridlines");
RemoveRecognizedAttributeInternal("div", "rules");
RemoveRecognizedAttributeInternal("span", "cellspacing");
RemoveRecognizedAttributeInternal("span", "cellpadding");
RemoveRecognizedAttributeInternal("span", "gridlines");
RemoveRecognizedAttributeInternal("span", "rules");
}
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public virtual void AddRecognizedAttribute(string elementName, string attributeName) {
Hashtable eltAttributes = (Hashtable) _recognizedAttributes[elementName];
if (eltAttributes == null) {
eltAttributes = new Hashtable(StringComparer.CurrentCultureIgnoreCase);
_recognizedAttributes[elementName] = eltAttributes;
}
eltAttributes.Add(attributeName, true);
}
/// <devdoc>
/// Override to filter out unnecessary attributes
/// </devdoc>
protected override bool OnAttributeRender(string name, string value, HtmlTextWriterAttribute key) {
Hashtable elementRecognizedAttributes = (Hashtable)_recognizedAttributes[TagName];
if (elementRecognizedAttributes != null && elementRecognizedAttributes[name] != null) {
return true;
}
if (_globalSuppressedAttributes[name] != null) {
return false;
}
Hashtable elementSuppressedAttributes = (Hashtable)_suppressedAttributes[TagName];
if (elementSuppressedAttributes != null && elementSuppressedAttributes[name] != null) {
return false;
}
return true;
}
protected override bool OnStyleAttributeRender(string name,string value, HtmlTextWriterStyle key) {
if (key == HtmlTextWriterStyle.TextDecoration) {
if (StringUtil.EqualsIgnoreCase("line-through", value)) {
return false;
}
}
return base.OnStyleAttributeRender(name, value, key);
}
protected override bool OnTagRender(string name, HtmlTextWriterTag key) {
return base.OnTagRender(name, key) && key != HtmlTextWriterTag.Span;
}
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public virtual void RemoveRecognizedAttribute(string elementName, string attributeName) {
RemoveRecognizedAttributeInternal(elementName, attributeName);
}
private void RemoveRecognizedAttributeInternal(string elementName, string attributeName) {
// Since recognized attributes have precedence, we need to do two operations: add this attribute
// to the suppressed list, and remove it from the recognized list.
Hashtable eltAttributes = (Hashtable) _suppressedAttributes[elementName];
if (eltAttributes == null) {
eltAttributes = new Hashtable(StringComparer.CurrentCultureIgnoreCase);
_suppressedAttributes[elementName] = eltAttributes;
}
eltAttributes.Add(attributeName, true);
eltAttributes = (Hashtable)_recognizedAttributes[elementName];
if (eltAttributes == null) {
eltAttributes = new Hashtable(StringComparer.CurrentCultureIgnoreCase);
_recognizedAttributes[elementName] = eltAttributes;
}
// Note: Hashtable::Remove silently continues if the key does not exist.
eltAttributes.Remove(attributeName);
}
public override void WriteBreak() {
Write("<br>");
}
public override void WriteEncodedText(String text) {
if (null == text || text.Length == 0) {
return;
}
int length = text.Length;
int start = -1;
for(int pos = 0; pos < length; pos++) {
int ch = text[pos];
if(ch > 160 && ch < 256) {
if(start != -1) {
base.WriteEncodedText(text.Substring(start, pos - start));
start = -1;
}
base.Write(text[pos]);
}
else {
if(start == -1) {
start = pos;
}
}
}
if(start != -1) {
if(start == 0) {
base.WriteEncodedText(text);
}
else {
base.WriteEncodedText(text.Substring(start, length - start));
}
}
}
protected Hashtable RecognizedAttributes {
get {
return _recognizedAttributes;
}
}
protected Hashtable SuppressedAttributes {
get {
return _suppressedAttributes;
}
}
protected Hashtable GlobalSuppressedAttributes {
get {
return _globalSuppressedAttributes;
}
}
}
}

View File

@@ -0,0 +1,25 @@
//------------------------------------------------------------------------------
// <copyright file="ClientIDModes.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
namespace System.Web.UI {
using System;
using System.Diagnostics.CodeAnalysis;
[SuppressMessage("Microsoft.Naming", "CA1706:ShortAcronymsShouldBeUppercase")]
public enum ClientIDMode {
Inherit = 0,
[SuppressMessage("Microsoft.Naming", "CA1706:ShortAcronymsShouldBeUppercase")]
AutoID = 1,
Predictable = 2,
Static = 3,
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,67 @@
//------------------------------------------------------------------------------
// <copyright file="CodeBlockBuilder.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
/*
* Handle <%= ... %>, <% ... %>, <%# ... %>, <%: ... %>, <%#: ... %> blocks
*
* Copyright (c) 1998 Microsoft Corporation
*/
namespace System.Web.UI {
using System;
using System.IO;
internal class CodeBlockBuilder : ControlBuilder, ICodeBlockTypeAccessor {
protected CodeBlockType _blockType;
protected string _content;
private int _column;
internal CodeBlockBuilder(CodeBlockType blockType, string content, int lineNumber, int column, VirtualPath virtualPath, bool encode) {
_content = content;
_blockType = blockType;
_column = column;
IsEncoded = encode;
Line = lineNumber;
VirtualPath = virtualPath;
}
internal CodeBlockBuilder(CodeBlockType blockType, string content, int lineNumber, int column, VirtualPath virtualPath)
: this(blockType, content, lineNumber, column, virtualPath, false) {
}
public override object BuildObject() {
return null;
}
internal /*public*/ string Content {
get {
return _content;
}
}
public CodeBlockType BlockType {
get { return _blockType;}
}
internal int Column { get { return _column; } }
// This is used by only DataBinding CodeBlockType.
internal bool IsEncoded {
get;
private set;
}
}
public enum CodeBlockType {
Code, // <% ... %>
Expression, // <%= ... %>
DataBinding, // <%# ... %>
EncodedExpression // <%: ... %>
}
}

View File

@@ -0,0 +1,21 @@
//------------------------------------------------------------------------------
// <copyright file="CodeStatementBuilder.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
namespace System.Web.UI {
using System.CodeDom;
/// <summary>
/// A ControlBuilder implementation that generates Code DOM statements
/// </summary>
public abstract class CodeStatementBuilder : ControlBuilder {
/// <summary>
/// Build a CodeStatement for a generated Render method.
/// </summary>
public abstract CodeStatement BuildStatement(CodeArgumentReferenceExpression writerReferenceExpression);
}
}

View File

@@ -0,0 +1,129 @@
//------------------------------------------------------------------------------
// <copyright file="CollectionBuilder.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
/*
* Classes related to complex property support.
*
* Copyright (c) 1999 Microsoft Corporation
*/
namespace System.Web.UI {
using System;
using System.Collections;
using System.Reflection;
using System.Web.Util;
[AttributeUsage(AttributeTargets.Property)]
internal sealed class IgnoreUnknownContentAttribute : Attribute {
internal IgnoreUnknownContentAttribute() {}
}
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
internal sealed class CollectionBuilder : ControlBuilder {
private Type _itemType;
private bool _ignoreUnknownContent;
internal CollectionBuilder(bool ignoreUnknownContent) { _ignoreUnknownContent = ignoreUnknownContent; }
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public override void Init(TemplateParser parser, ControlBuilder parentBuilder,
Type type, string tagName, string ID, IDictionary attribs) {
base.Init(parser, parentBuilder, type /*type*/, tagName, ID, attribs);
//
PropertyInfo propInfo = TargetFrameworkUtil.GetProperty(parentBuilder.ControlType,
tagName, BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static | BindingFlags.IgnoreCase);
SetControlType(propInfo.PropertyType);
Debug.Assert(ControlType != null, "ControlType != null");
BindingFlags bindingFlags = BindingFlags.Public | BindingFlags.Instance;
// Look for an "item" property on the collection that takes in an integer index
// (similar to IList::Item)
propInfo = TargetFrameworkUtil.GetProperty(ControlType, "Item", bindingFlags, types: new Type[] { typeof(int) });
if (propInfo == null) {
// fall-back on finding a non-specific Item property
// a type with overloaded indexed properties will result in an exception however
propInfo = TargetFrameworkUtil.GetProperty(ControlType, "Item", bindingFlags);
}
// If we got one, use it to determine the type of the items
if (propInfo != null)
_itemType = propInfo.PropertyType;
}
// This code is only executed when used from the desiger
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public override object BuildObject() {
return this;
}
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public override Type GetChildControlType(string tagName, IDictionary attribs) {
Type childType = Parser.MapStringToType(tagName, attribs);
// If possible, check if the item is of the required type
if (_itemType != null) {
if (!_itemType.IsAssignableFrom(childType)) {
if (_ignoreUnknownContent)
return null;
string controlTypeName = String.Empty;
if (ControlType != null) {
controlTypeName = ControlType.FullName;
}
else {
controlTypeName = TagName;
}
throw new HttpException(SR.GetString(SR.Invalid_collection_item_type, new String[] { controlTypeName,
_itemType.FullName,
tagName,
childType.FullName}));
}
}
return childType;
}
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public override void AppendLiteralString(string s) {
if (_ignoreUnknownContent)
return;
// Don't allow non-whitespace literal content
if (!Util.IsWhiteSpaceString(s)) {
throw new HttpException(SR.GetString(SR.Literal_content_not_allowed, ControlType.FullName, s.Trim()));
}
}
}
}

View File

@@ -0,0 +1,48 @@
//------------------------------------------------------------------------------
// <copyright file="ComplexPropertyEntry.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
namespace System.Web.UI {
using System.Security.Permissions;
/// <devdoc>
/// PropertyEntry for read/write and readonly complex properties
/// </devdoc>
public class ComplexPropertyEntry : BuilderPropertyEntry {
private bool _readOnly;
private bool _isCollectionItem;
internal ComplexPropertyEntry() {
}
internal ComplexPropertyEntry(bool isCollectionItem) {
_isCollectionItem = isCollectionItem;
}
/// <devdoc>
/// Indicates whether the property is a collection property.
/// </devdoc>
public bool IsCollectionItem {
get {
return _isCollectionItem;
}
}
/// <devdoc>
/// </devdoc>
public bool ReadOnly {
get {
return _readOnly;
}
set {
_readOnly = value;
}
}
}
}

View File

@@ -0,0 +1,26 @@
//------------------------------------------------------------------------------
// <copyright file="ConflictOptions.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
namespace System.Web.UI {
using System;
/// <devdoc>
/// Specifies a conflict resolution mode.
/// </devdoc>
public enum ConflictOptions {
/// <devdoc>
/// Specifies that only the new values and the keys will be passed to the update or delete query
/// </devdoc>
OverwriteChanges = 0,
/// <devdoc>
/// Specifies that the old values will also be passed to the update or delete query
/// </devdoc>
CompareAllValues = 1
}
}

View File

@@ -0,0 +1,49 @@
//------------------------------------------------------------------------------
// <copyright file="ConstructorNeedsTagAttribute.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
/*
*/
namespace System.Web.UI {
using System;
using System.ComponentModel;
using System.Security.Permissions;
/// <devdoc>
/// <para> Allows a control to specify that it needs a
/// tag name in its constructor.</para>
/// </devdoc>
[AttributeUsage(AttributeTargets.Class)]
public sealed class ConstructorNeedsTagAttribute: Attribute {
bool needsTag = false;
/// <devdoc>
/// <para>Initializes a new instance of the <see cref='System.Web.UI.ConstructorNeedsTagAttribute'/> class.</para>
/// </devdoc>
public ConstructorNeedsTagAttribute() {
}
/// <devdoc>
/// <para>Initializes a new instance of the <see cref='System.Web.UI.ConstructorNeedsTagAttribute'/> class.</para>
/// </devdoc>
public ConstructorNeedsTagAttribute(bool needsTag) {
this.needsTag = needsTag;
}
/// <devdoc>
/// <para>Indicates whether a control needs a tag in its contstructor. This property is read-only.</para>
/// </devdoc>
public bool NeedsTag {
get {
return needsTag;
}
}
}
}

View File

@@ -0,0 +1 @@
1a9686a27e5ed415605485f8f16e5724c00e1b37

View File

@@ -0,0 +1,136 @@
//How to set the _control
//------------------------------------------------------------------------------
// <copyright file="ControlAdapter.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
namespace System.Web.UI.Adapters {
using System;
using System.ComponentModel;
using System.Security.Permissions;
/* Defines the properties, methods, and events shared by all server control
* adapters in the Web Forms page framework.
*/
public abstract class ControlAdapter {
private HttpBrowserCapabilities _browser = null;
internal Control _control; //control associated with this adapter
[
Browsable(false),
DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden),
]
protected Control Control {
get {
return _control;
}
}
/* Indicates the page on which the associated control resides.
*/
[
Browsable(false),
DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden),
]
protected Page Page {
get {
if(Control != null)
return Control.Page;
return null;
}
}
[
Browsable(false),
DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden),
]
protected PageAdapter PageAdapter {
get {
if(Control != null && Control.Page != null)
return Control.Page.PageAdapter;
return null;
}
}
protected HttpBrowserCapabilities Browser {
get {
if (_browser == null) {
if (Page.RequestInternal != null) {
_browser = Page.RequestInternal.Browser;
}
else {
/* VSWhidbey 83667: In post-cache substitution, Page.Request
* would not be available. Then we try to
* use the more expensive way to access the current
* context and get the request handle.
*/
HttpContext context = HttpContext.Current;
if (context != null && context.Request != null) {
_browser = context.Request.Browser;
}
}
}
return _browser;
}
}
protected internal virtual void OnInit(EventArgs e) {
Control.OnInit(e);
}
protected internal virtual void OnLoad(EventArgs e) {
Control.OnLoad(e);
}
protected internal virtual void OnPreRender(EventArgs e) {
Control.OnPreRender(e);
}
protected internal virtual void Render(HtmlTextWriter writer) {
//
if(_control != null) {
_control.Render(writer);
}
}
protected virtual void RenderChildren(HtmlTextWriter writer) {
if(_control != null) {
_control.RenderChildren(writer);
}
}
protected internal virtual void OnUnload(EventArgs e) {
Control.OnUnload(e);
}
protected internal virtual void BeginRender(HtmlTextWriter writer) {
writer.BeginRender();
}
protected internal virtual void CreateChildControls() {
Control.CreateChildControls();
}
protected internal virtual void EndRender(HtmlTextWriter writer) {
writer.EndRender();
}
protected internal virtual void LoadAdapterControlState(object state) {
}
protected internal virtual void LoadAdapterViewState(object state) {
}
protected internal virtual object SaveAdapterControlState() {
return null;
}
protected internal virtual object SaveAdapterViewState() {
return null;
}
}
}

View File

@@ -0,0 +1 @@
6a5c0117707b381e70bcf74ba10f69b536e64bbd

Some files were not shown because too many files have changed in this diff Show More