Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / whidbey / NetFxQFE / ndp / fx / src / xsp / System / Web / Compilation / TemplateControlCodeDomTreeGenerator.cs / 1 / TemplateControlCodeDomTreeGenerator.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- namespace System.Web.Compilation { using System; using System.Collections; using System.Reflection; using System.ComponentModel; using System.CodeDom; using System.CodeDom.Compiler; using System.Globalization; using System.Web.UI; using System.Web.Util; using Debug=System.Web.Util.Debug; internal abstract class TemplateControlCodeDomTreeGenerator : BaseTemplateCodeDomTreeGenerator { private const string stringResourcePointerName = "__stringResource"; private TemplateControlParser _tcParser; private TemplateControlParser Parser { get { return _tcParser; } } private const string literalMemoryBlockName = "__literals"; // This is used to detect incorrect base class in code beside scenarios. See usage for details. internal const int badBaseClassLineMarker = 912304; internal TemplateControlCodeDomTreeGenerator(TemplateControlParser tcParser) : base(tcParser) { _tcParser = tcParser; } /* * Build the default constructor */ protected override void BuildInitStatements(CodeStatementCollection trueStatements, CodeStatementCollection topLevelStatements) { base.BuildInitStatements(trueStatements, topLevelStatements); if (_stringResourceBuilder.HasStrings) { // e.g. private static object __stringResource; CodeMemberField stringResourcePointer = new CodeMemberField(typeof(Object), stringResourcePointerName); stringResourcePointer.Attributes |= MemberAttributes.Static; _sourceDataClass.Members.Add(stringResourcePointer); // e.g. __stringResource = TemplateControl.ReadStringResource(typeof(__GeneratedType)); CodeAssignStatement readResource = new CodeAssignStatement(); readResource.Left = new CodeFieldReferenceExpression(_classTypeExpr, stringResourcePointerName); CodeMethodInvokeExpression methCallExpression = new CodeMethodInvokeExpression(); methCallExpression.Method.TargetObject = new CodeThisReferenceExpression(); methCallExpression.Method.MethodName = "ReadStringResource"; readResource.Right = methCallExpression; trueStatements.Add(readResource); } // // Set the AppRelativeVirtualPath // e.g. ((System.Web.UI.Page)(this)).AppRelativeVirtualPath = "~/foo.aspx"; // Note that we generate an artificial cast to cause a compile error if the base class // is incorrect (see below). // // Make sure the BuildAppRelativeVirtualPathProperty property is app independent, since // in precompilation scenarios, we can't make an assumption on the app name. // Use global:: to resolve types to avoid naming conflicts when user uses a class name // in the global namespace that already exists, such as Login or ReportViewer (DevDiv 79336) CodeTypeReference classTypeRef = new CodeTypeReference(Parser.BaseType, CodeTypeReferenceOptions.GlobalReference); CodeAssignStatement setProp = new CodeAssignStatement( new CodePropertyReferenceExpression(new CodeCastExpression(classTypeRef, new CodeThisReferenceExpression()), "AppRelativeVirtualPath"), new CodePrimitiveExpression(Parser.CurrentVirtualPath.AppRelativeVirtualPathString)); // This line will fail to compile if the base class in the code beside is missing. Set // a special line number on it to improve error handling (VSWhidbey 376977/468830) if (!_designerMode && Parser.CodeFileVirtualPath != null) { setProp.LinePragma = CreateCodeLinePragmaHelper( Parser.CodeFileVirtualPath.VirtualPathString, badBaseClassLineMarker); } topLevelStatements.Add(setProp); } /* * Build various properties, fields, methods */ protected override void BuildMiscClassMembers() { base.BuildMiscClassMembers(); // Build the automatic event hookup code if (!_designerMode) BuildAutomaticEventHookup(); // Build the ApplicationInstance property BuildApplicationInstanceProperty(); BuildSourceDataTreeFromBuilder(Parser.RootBuilder, false /*fInTemplate*/, false /*topLevelTemplate*/, null /*pse*/); if (!_designerMode) BuildFrameworkInitializeMethod(); } /* * Build the strongly typed new property */ // e.g. public new {propertyType} Master { get { return ({propertyType})base.Master; } } internal void BuildStronglyTypedProperty(string propertyName, Type propertyType) { // VSWhidbey 321818. // overriding method with same name is not allowed using J#. if (_usingVJSCompiler) { return; } CodeMemberProperty prop = new CodeMemberProperty(); prop.Attributes &= ~MemberAttributes.AccessMask; prop.Attributes &= ~MemberAttributes.ScopeMask; prop.Attributes |= MemberAttributes.Final | MemberAttributes.New | MemberAttributes.Public; prop.Name = propertyName; prop.Type = new CodeTypeReference(propertyType); CodePropertyReferenceExpression propRef = new CodePropertyReferenceExpression( new CodeBaseReferenceExpression(), propertyName); prop.GetStatements.Add(new CodeMethodReturnStatement(new CodeCastExpression(propertyType, propRef))); _intermediateClass.Members.Add(prop); } /* * Build the data tree for the FrameworkInitialize method */ private void BuildFrameworkInitializeMethod() { // Skip if we're only generating the intermediate class if (_sourceDataClass == null) return; CodeMemberMethod method = new CodeMemberMethod(); AddDebuggerNonUserCodeAttribute(method); method.Attributes &= ~MemberAttributes.AccessMask; method.Attributes &= ~MemberAttributes.ScopeMask; method.Attributes |= MemberAttributes.Override | MemberAttributes.Family; method.Name = "FrameworkInitialize"; BuildFrameworkInitializeMethodContents(method); // This line will fail to compile if the base class in the code beside is incorrect. Set // a special line number on it to improve error handling (VSWhidbey 376977/468830) if (!_designerMode && Parser.CodeFileVirtualPath != null) { method.LinePragma = CreateCodeLinePragmaHelper( Parser.CodeFileVirtualPath.VirtualPathString, badBaseClassLineMarker); } _sourceDataClass.Members.Add(method); } /* * Build the contents of the FrameworkInitialize method */ protected virtual void BuildFrameworkInitializeMethodContents(CodeMemberMethod method) { // Call the base FrameworkInitialize CodeMethodInvokeExpression baseCallExpression = new CodeMethodInvokeExpression( new CodeBaseReferenceExpression(), method.Name); method.Statements.Add(new CodeExpressionStatement(baseCallExpression)); // No strings: don't do anything if (_stringResourceBuilder.HasStrings) { // e.g. SetStringResourcePointer(__stringResource, 0); CodeMethodInvokeExpression methCallExpression = new CodeMethodInvokeExpression( new CodeThisReferenceExpression(), "SetStringResourcePointer"); methCallExpression.Parameters.Add(new CodeFieldReferenceExpression( _classTypeExpr, stringResourcePointerName)); // Pass 0 for the maxResourceOffset, since it's being ignored methCallExpression.Parameters.Add(new CodePrimitiveExpression(0)); method.Statements.Add(new CodeExpressionStatement(methCallExpression)); } CodeMethodInvokeExpression call = new CodeMethodInvokeExpression(); call.Method.TargetObject = new CodeThisReferenceExpression(); call.Method.MethodName = "__BuildControlTree"; call.Parameters.Add(new CodeThisReferenceExpression()); method.Statements.Add(new CodeExpressionStatement(call)); } /* * Build the automatic event hookup code */ private void BuildAutomaticEventHookup() { // Skip if we're only generating the intermediate class if (_sourceDataClass == null) return; CodeMemberProperty prop; // If FAutoEventWireup is turned off, generate a SupportAutoEvents prop that // returns false. if (!Parser.FAutoEventWireup) { prop = new CodeMemberProperty(); prop.Attributes &= ~MemberAttributes.AccessMask; prop.Attributes &= ~MemberAttributes.ScopeMask; prop.Attributes |= MemberAttributes.Override | MemberAttributes.Family; prop.Name = "SupportAutoEvents"; prop.Type = new CodeTypeReference(typeof(bool)); prop.GetStatements.Add(new CodeMethodReturnStatement(new CodePrimitiveExpression(false))); _sourceDataClass.Members.Add(prop); return; } } /* * Build the ApplicationInstance property */ private void BuildApplicationInstanceProperty() { CodeMemberProperty prop; Type appType = BuildManager.GetGlobalAsaxType(); prop = new CodeMemberProperty(); prop.Attributes &= ~MemberAttributes.AccessMask; prop.Attributes &= ~MemberAttributes.ScopeMask; prop.Attributes |= MemberAttributes.Final | MemberAttributes.Family; if (_designerMode) { ApplyEditorBrowsableCustomAttribute(prop); } prop.Name = "ApplicationInstance"; prop.Type = new CodeTypeReference(appType); CodePropertyReferenceExpression propRef = new CodePropertyReferenceExpression( new CodeThisReferenceExpression(), "Context"); propRef = new CodePropertyReferenceExpression(propRef, "ApplicationInstance"); prop.GetStatements.Add(new CodeMethodReturnStatement(new CodeCastExpression( appType, propRef))); _intermediateClass.Members.Add(prop); } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- namespace System.Web.Compilation { using System; using System.Collections; using System.Reflection; using System.ComponentModel; using System.CodeDom; using System.CodeDom.Compiler; using System.Globalization; using System.Web.UI; using System.Web.Util; using Debug=System.Web.Util.Debug; internal abstract class TemplateControlCodeDomTreeGenerator : BaseTemplateCodeDomTreeGenerator { private const string stringResourcePointerName = "__stringResource"; private TemplateControlParser _tcParser; private TemplateControlParser Parser { get { return _tcParser; } } private const string literalMemoryBlockName = "__literals"; // This is used to detect incorrect base class in code beside scenarios. See usage for details. internal const int badBaseClassLineMarker = 912304; internal TemplateControlCodeDomTreeGenerator(TemplateControlParser tcParser) : base(tcParser) { _tcParser = tcParser; } /* * Build the default constructor */ protected override void BuildInitStatements(CodeStatementCollection trueStatements, CodeStatementCollection topLevelStatements) { base.BuildInitStatements(trueStatements, topLevelStatements); if (_stringResourceBuilder.HasStrings) { // e.g. private static object __stringResource; CodeMemberField stringResourcePointer = new CodeMemberField(typeof(Object), stringResourcePointerName); stringResourcePointer.Attributes |= MemberAttributes.Static; _sourceDataClass.Members.Add(stringResourcePointer); // e.g. __stringResource = TemplateControl.ReadStringResource(typeof(__GeneratedType)); CodeAssignStatement readResource = new CodeAssignStatement(); readResource.Left = new CodeFieldReferenceExpression(_classTypeExpr, stringResourcePointerName); CodeMethodInvokeExpression methCallExpression = new CodeMethodInvokeExpression(); methCallExpression.Method.TargetObject = new CodeThisReferenceExpression(); methCallExpression.Method.MethodName = "ReadStringResource"; readResource.Right = methCallExpression; trueStatements.Add(readResource); } // // Set the AppRelativeVirtualPath // e.g. ((System.Web.UI.Page)(this)).AppRelativeVirtualPath = "~/foo.aspx"; // Note that we generate an artificial cast to cause a compile error if the base class // is incorrect (see below). // // Make sure the BuildAppRelativeVirtualPathProperty property is app independent, since // in precompilation scenarios, we can't make an assumption on the app name. // Use global:: to resolve types to avoid naming conflicts when user uses a class name // in the global namespace that already exists, such as Login or ReportViewer (DevDiv 79336) CodeTypeReference classTypeRef = new CodeTypeReference(Parser.BaseType, CodeTypeReferenceOptions.GlobalReference); CodeAssignStatement setProp = new CodeAssignStatement( new CodePropertyReferenceExpression(new CodeCastExpression(classTypeRef, new CodeThisReferenceExpression()), "AppRelativeVirtualPath"), new CodePrimitiveExpression(Parser.CurrentVirtualPath.AppRelativeVirtualPathString)); // This line will fail to compile if the base class in the code beside is missing. Set // a special line number on it to improve error handling (VSWhidbey 376977/468830) if (!_designerMode && Parser.CodeFileVirtualPath != null) { setProp.LinePragma = CreateCodeLinePragmaHelper( Parser.CodeFileVirtualPath.VirtualPathString, badBaseClassLineMarker); } topLevelStatements.Add(setProp); } /* * Build various properties, fields, methods */ protected override void BuildMiscClassMembers() { base.BuildMiscClassMembers(); // Build the automatic event hookup code if (!_designerMode) BuildAutomaticEventHookup(); // Build the ApplicationInstance property BuildApplicationInstanceProperty(); BuildSourceDataTreeFromBuilder(Parser.RootBuilder, false /*fInTemplate*/, false /*topLevelTemplate*/, null /*pse*/); if (!_designerMode) BuildFrameworkInitializeMethod(); } /* * Build the strongly typed new property */ // e.g. public new {propertyType} Master { get { return ({propertyType})base.Master; } } internal void BuildStronglyTypedProperty(string propertyName, Type propertyType) { // VSWhidbey 321818. // overriding method with same name is not allowed using J#. if (_usingVJSCompiler) { return; } CodeMemberProperty prop = new CodeMemberProperty(); prop.Attributes &= ~MemberAttributes.AccessMask; prop.Attributes &= ~MemberAttributes.ScopeMask; prop.Attributes |= MemberAttributes.Final | MemberAttributes.New | MemberAttributes.Public; prop.Name = propertyName; prop.Type = new CodeTypeReference(propertyType); CodePropertyReferenceExpression propRef = new CodePropertyReferenceExpression( new CodeBaseReferenceExpression(), propertyName); prop.GetStatements.Add(new CodeMethodReturnStatement(new CodeCastExpression(propertyType, propRef))); _intermediateClass.Members.Add(prop); } /* * Build the data tree for the FrameworkInitialize method */ private void BuildFrameworkInitializeMethod() { // Skip if we're only generating the intermediate class if (_sourceDataClass == null) return; CodeMemberMethod method = new CodeMemberMethod(); AddDebuggerNonUserCodeAttribute(method); method.Attributes &= ~MemberAttributes.AccessMask; method.Attributes &= ~MemberAttributes.ScopeMask; method.Attributes |= MemberAttributes.Override | MemberAttributes.Family; method.Name = "FrameworkInitialize"; BuildFrameworkInitializeMethodContents(method); // This line will fail to compile if the base class in the code beside is incorrect. Set // a special line number on it to improve error handling (VSWhidbey 376977/468830) if (!_designerMode && Parser.CodeFileVirtualPath != null) { method.LinePragma = CreateCodeLinePragmaHelper( Parser.CodeFileVirtualPath.VirtualPathString, badBaseClassLineMarker); } _sourceDataClass.Members.Add(method); } /* * Build the contents of the FrameworkInitialize method */ protected virtual void BuildFrameworkInitializeMethodContents(CodeMemberMethod method) { // Call the base FrameworkInitialize CodeMethodInvokeExpression baseCallExpression = new CodeMethodInvokeExpression( new CodeBaseReferenceExpression(), method.Name); method.Statements.Add(new CodeExpressionStatement(baseCallExpression)); // No strings: don't do anything if (_stringResourceBuilder.HasStrings) { // e.g. SetStringResourcePointer(__stringResource, 0); CodeMethodInvokeExpression methCallExpression = new CodeMethodInvokeExpression( new CodeThisReferenceExpression(), "SetStringResourcePointer"); methCallExpression.Parameters.Add(new CodeFieldReferenceExpression( _classTypeExpr, stringResourcePointerName)); // Pass 0 for the maxResourceOffset, since it's being ignored methCallExpression.Parameters.Add(new CodePrimitiveExpression(0)); method.Statements.Add(new CodeExpressionStatement(methCallExpression)); } CodeMethodInvokeExpression call = new CodeMethodInvokeExpression(); call.Method.TargetObject = new CodeThisReferenceExpression(); call.Method.MethodName = "__BuildControlTree"; call.Parameters.Add(new CodeThisReferenceExpression()); method.Statements.Add(new CodeExpressionStatement(call)); } /* * Build the automatic event hookup code */ private void BuildAutomaticEventHookup() { // Skip if we're only generating the intermediate class if (_sourceDataClass == null) return; CodeMemberProperty prop; // If FAutoEventWireup is turned off, generate a SupportAutoEvents prop that // returns false. if (!Parser.FAutoEventWireup) { prop = new CodeMemberProperty(); prop.Attributes &= ~MemberAttributes.AccessMask; prop.Attributes &= ~MemberAttributes.ScopeMask; prop.Attributes |= MemberAttributes.Override | MemberAttributes.Family; prop.Name = "SupportAutoEvents"; prop.Type = new CodeTypeReference(typeof(bool)); prop.GetStatements.Add(new CodeMethodReturnStatement(new CodePrimitiveExpression(false))); _sourceDataClass.Members.Add(prop); return; } } /* * Build the ApplicationInstance property */ private void BuildApplicationInstanceProperty() { CodeMemberProperty prop; Type appType = BuildManager.GetGlobalAsaxType(); prop = new CodeMemberProperty(); prop.Attributes &= ~MemberAttributes.AccessMask; prop.Attributes &= ~MemberAttributes.ScopeMask; prop.Attributes |= MemberAttributes.Final | MemberAttributes.Family; if (_designerMode) { ApplyEditorBrowsableCustomAttribute(prop); } prop.Name = "ApplicationInstance"; prop.Type = new CodeTypeReference(appType); CodePropertyReferenceExpression propRef = new CodePropertyReferenceExpression( new CodeThisReferenceExpression(), "Context"); propRef = new CodePropertyReferenceExpression(propRef, "ApplicationInstance"); prop.GetStatements.Add(new CodeMethodReturnStatement(new CodeCastExpression( appType, propRef))); _intermediateClass.Members.Add(prop); } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- SystemBrushes.cs
- PrivilegeNotHeldException.cs
- EntityDataSourceDesignerHelper.cs
- RectValueSerializer.cs
- VisualBasicExpressionConverter.cs
- BitmapEffectInputData.cs
- DataControlField.cs
- GotoExpression.cs
- Overlapped.cs
- ItemContainerPattern.cs
- SHA256.cs
- TemplateEditingFrame.cs
- MimePart.cs
- BitmapEffect.cs
- GridViewSortEventArgs.cs
- PhysicalOps.cs
- PathGradientBrush.cs
- ToolStripRendererSwitcher.cs
- KeyPressEvent.cs
- LayoutTableCell.cs
- SqlMethodAttribute.cs
- TemplatedControlDesigner.cs
- Visual3DCollection.cs
- SmtpSection.cs
- VisualStyleRenderer.cs
- XhtmlConformanceSection.cs
- MessageEnumerator.cs
- ConfigXmlReader.cs
- SymLanguageType.cs
- ImageBrush.cs
- DynamicDataRoute.cs
- EdmTypeAttribute.cs
- SafeThemeHandle.cs
- DecimalFormatter.cs
- ProfileService.cs
- AsymmetricAlgorithm.cs
- WebPartCatalogCloseVerb.cs
- StringHelper.cs
- TiffBitmapEncoder.cs
- ItemContainerGenerator.cs
- ClientRuntimeConfig.cs
- DefinitionBase.cs
- ExternalException.cs
- CachedTypeface.cs
- SafeSystemMetrics.cs
- HtmlLink.cs
- QilInvokeLateBound.cs
- CannotUnloadAppDomainException.cs
- TypedColumnHandler.cs
- SortDescriptionCollection.cs
- TextDecorations.cs
- MultiView.cs
- ErrorRuntimeConfig.cs
- InkSerializer.cs
- GeometryCombineModeValidation.cs
- StylusLogic.cs
- ToolBarButton.cs
- EdmPropertyAttribute.cs
- BooleanToVisibilityConverter.cs
- ZipIOFileItemStream.cs
- ContractsBCL.cs
- NameSpaceExtractor.cs
- ClientData.cs
- XmlDataLoader.cs
- MD5CryptoServiceProvider.cs
- DataMisalignedException.cs
- dbdatarecord.cs
- recordstatescratchpad.cs
- WebServiceEnumData.cs
- JournalEntryListConverter.cs
- TextServicesContext.cs
- SelectionEditingBehavior.cs
- AudioException.cs
- Atom10FormatterFactory.cs
- XmlDataContract.cs
- WorkflowServiceNamespace.cs
- InputLanguageManager.cs
- ConnectivityStatus.cs
- IriParsingElement.cs
- EditorZoneBase.cs
- ToolStripButton.cs
- RC2CryptoServiceProvider.cs
- CheckedListBox.cs
- IdentityModelDictionary.cs
- GridViewRow.cs
- KeyMatchBuilder.cs
- SearchExpression.cs
- XmlDeclaration.cs
- RegistrationServices.cs
- ADConnectionHelper.cs
- CaseInsensitiveComparer.cs
- PublisherIdentityPermission.cs
- SecurityResources.cs
- ParsedAttributeCollection.cs
- TrustManagerMoreInformation.cs
- HelpExampleGenerator.cs
- Component.cs
- DrawingContext.cs
- CalendarDay.cs
- HttpConfigurationContext.cs