private static void ProcessBooleanProviderOption(string providerOptionName, string trueCompilerOption, string falseCompilerOption, IDictionary <string, string> providerOptions, CompilerParameters compilParams)
 {
     if ((providerOptions != null) && (compilParams != null))
     {
         string str = null;
         if (providerOptions.TryGetValue(providerOptionName, out str))
         {
             bool flag;
             if (string.IsNullOrEmpty(str))
             {
                 throw new ConfigurationErrorsException(System.Web.SR.GetString("Property_NullOrEmpty", new object[] { "system.codedom/compilers/compiler/ProviderOption/" + providerOptionName }));
             }
             if (!bool.TryParse(str, out flag))
             {
                 throw new ConfigurationErrorsException(System.Web.SR.GetString("Value_must_be_boolean", new object[] { "system.codedom/compilers/compiler/ProviderOption/" + providerOptionName }));
             }
             if (flag)
             {
                 CodeDomUtility.AppendCompilerOption(compilParams, trueCompilerOption);
             }
             else
             {
                 CodeDomUtility.AppendCompilerOption(compilParams, falseCompilerOption);
             }
         }
     }
 }
Example #2
0
        internal virtual void BuildExpression(BoundPropertyEntry bpe, ControlBuilder controlBuilder,
                                              CodeExpression controlReference, CodeStatementCollection methodStatements, CodeStatementCollection statements, CodeLinePragma linePragma, ref bool hasTempObject)
        {
            CodeExpression codeExpression = GetCodeExpression(bpe,
                                                              bpe.ParsedExpressionData, new ExpressionBuilderContext(controlBuilder.VirtualPath));

            CodeDomUtility.CreatePropertySetStatements(methodStatements, statements,
                                                       controlReference, bpe.Name, bpe.Type,
                                                       codeExpression,
                                                       linePragma);
        }
        /*
         * 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 = CodeDomUtility.BuildGlobalCodeTypeReference(Parser.BaseType);

            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);
        }
Example #4
0
        private static void BuildPropertySetExpression(CodeExpression expression, string propertyName,
                                                       Type propertyType, ControlBuilder controlBuilder, CodeStatementCollection methodStatements, CodeStatementCollection statements, CodeLinePragma linePragma, bool isEncoded, ref bool hasTempObject)
        {
            if (isEncoded)
            {
                expression = new CodeMethodInvokeExpression(
                    new CodeMethodReferenceExpression(
                        new CodeTypeReferenceExpression(typeof(HttpUtility)),
                        "HtmlEncode"),
                    expression);
            }

            CodeDomUtility.CreatePropertySetStatements(methodStatements, statements,
                                                       new CodeVariableReferenceExpression("dataBindingExpressionBuilderTarget"), propertyName, propertyType,
                                                       expression,
                                                       linePragma);
        }
 internal static void FixUpCompilerParameters(Type codeDomProviderType, CompilerParameters compilParams)
 {
     if (codeDomProviderType == typeof(CSharpCodeProvider))
     {
         CodeDomUtility.PrependCompilerOption(compilParams, "/nowarn:1659;1699;1701");
     }
     else if (codeDomProviderType == typeof(VBCodeProvider))
     {
         AddVBGlobalNamespaceImports(compilParams);
         AddVBMyFlags(compilParams);
         if (MultiTargetingUtil.TargetFrameworkVersion >= MultiTargetingUtil.Version35)
         {
             CodeDomUtility.PrependCompilerOption(compilParams, "/nowarn:41008");
         }
     }
     ProcessProviderOptions(codeDomProviderType, compilParams);
     FixTreatWarningsAsErrors(codeDomProviderType, compilParams);
     if (BuildManager.PrecompilingWithCodeAnalysisSymbol)
     {
         CodeDomUtility.PrependCompilerOption(compilParams, "/define:CODE_ANALYSIS");
     }
 }
        private bool BuildSourceDataTree()
        {
            this._compilParams    = this.Parser.CompilParams;
            this._codeCompileUnit = new CodeCompileUnit();
            this._codeCompileUnit.UserData["AllowLateBound"]             = !this.Parser.FStrict;
            this._codeCompileUnit.UserData["RequireVariableDeclaration"] = this.Parser.FExplicit;
            this._usingVJSCompiler    = this._codeDomProvider.FileExtension == ".jsl";
            this._sourceDataNamespace = new CodeNamespace(this.Parser.GeneratedNamespace);
            string generatedClassName = this.GetGeneratedClassName();

            if (this.Parser.BaseTypeName != null)
            {
                CodeNamespace namespace2 = new CodeNamespace(this.Parser.BaseTypeNamespace);
                this._codeCompileUnit.Namespaces.Add(namespace2);
                this._intermediateClass = new CodeTypeDeclaration(this.Parser.BaseTypeName);
                if (this._designerMode)
                {
                    this._intermediateClass.UserData["BaseClassDefinition"] = this.Parser.DefaultBaseType;
                }
                else
                {
                    this._intermediateClass.UserData["BaseClassDefinition"] = this.Parser.BaseType;
                }
                namespace2.Types.Add(this._intermediateClass);
                this._intermediateClass.IsPartial = true;
                if (!this.PrecompilingForUpdatableDeployment)
                {
                    this._sourceDataClass = new CodeTypeDeclaration(generatedClassName);
                    this._sourceDataClass.BaseTypes.Add(CodeDomUtility.BuildGlobalCodeTypeReference(Util.MakeFullTypeName(this.Parser.BaseTypeNamespace, this.Parser.BaseTypeName)));
                    this._sourceDataNamespace.Types.Add(this._sourceDataClass);
                }
            }
            else
            {
                this._intermediateClass = new CodeTypeDeclaration(generatedClassName);
                this._intermediateClass.BaseTypes.Add(CodeDomUtility.BuildGlobalCodeTypeReference(this.Parser.BaseType));
                this._sourceDataNamespace.Types.Add(this._intermediateClass);
                this._sourceDataClass = this._intermediateClass;
            }
            this._codeCompileUnit.Namespaces.Add(this._sourceDataNamespace);
            if (this.PrecompilingForUpdatableDeployment && (this.Parser.CodeFileVirtualPath == null))
            {
                return(false);
            }
            this.GenerateClassAttributes();
            if (this._codeDomProvider is VBCodeProvider)
            {
                this._sourceDataNamespace.Imports.Add(new CodeNamespaceImport("Microsoft.VisualBasic"));
            }
            if (this.Parser.NamespaceEntries != null)
            {
                foreach (NamespaceEntry entry in this.Parser.NamespaceEntries.Values)
                {
                    CodeLinePragma pragma;
                    if (entry.VirtualPath != null)
                    {
                        pragma = this.CreateCodeLinePragma(entry.VirtualPath, entry.Line);
                    }
                    else
                    {
                        pragma = null;
                    }
                    CodeNamespaceImport import = new CodeNamespaceImport(entry.Namespace)
                    {
                        LinePragma = pragma
                    };
                    this._sourceDataNamespace.Imports.Add(import);
                }
            }
            if (this._sourceDataClass != null)
            {
                CodeTypeReference type = CodeDomUtility.BuildGlobalCodeTypeReference(Util.MakeFullTypeName(this._sourceDataNamespace.Name, this._sourceDataClass.Name));
                this._classTypeExpr = new CodeTypeReferenceExpression(type);
            }
            this.GenerateInterfaces();
            this.BuildMiscClassMembers();
            if (!this._designerMode && (this._sourceDataClass != null))
            {
                this._ctor = new CodeConstructor();
                this.AddDebuggerNonUserCodeAttribute(this._ctor);
                this._sourceDataClass.Members.Add(this._ctor);
                this.BuildDefaultConstructor();
            }
            return(true);
        }
        protected override void BuildInitStatements(CodeStatementCollection trueStatements, CodeStatementCollection topLevelStatements)
        {
            base.BuildInitStatements(trueStatements, topLevelStatements);
            if (base._stringResourceBuilder.HasStrings)
            {
                CodeMemberField field;
                field = new CodeMemberField(typeof(object), "__stringResource")
                {
                    Attributes = field.Attributes | MemberAttributes.Static
                };
                base._sourceDataClass.Members.Add(field);
                CodeAssignStatement statement = new CodeAssignStatement {
                    Left = new CodeFieldReferenceExpression(base._classTypeExpr, "__stringResource")
                };
                CodeMethodInvokeExpression expression = new CodeMethodInvokeExpression {
                    Method = { TargetObject = new CodeThisReferenceExpression(), MethodName = "ReadStringResource" }
                };
                statement.Right = expression;
                trueStatements.Add(statement);
            }
            CodeAssignStatement statement2 = new CodeAssignStatement(new CodePropertyReferenceExpression(new CodeCastExpression(CodeDomUtility.BuildGlobalCodeTypeReference(this.Parser.BaseType), new CodeThisReferenceExpression()), "AppRelativeVirtualPath"), new CodePrimitiveExpression(this.Parser.CurrentVirtualPath.AppRelativeVirtualPathString));

            if (!base._designerMode && (this.Parser.CodeFileVirtualPath != null))
            {
                statement2.LinePragma = BaseCodeDomTreeGenerator.CreateCodeLinePragmaHelper(this.Parser.CodeFileVirtualPath.VirtualPathString, 0xdebb0);
            }
            topLevelStatements.Add(statement2);
        }
Example #8
0
 private static void BuildPropertySetExpression(CodeExpression expression, string propertyName, Type propertyType, ControlBuilder controlBuilder, CodeStatementCollection methodStatements, CodeStatementCollection statements, CodeLinePragma linePragma, ref bool hasTempObject)
 {
     CodeDomUtility.CreatePropertySetStatements(methodStatements, statements, new CodeVariableReferenceExpression("dataBindingExpressionBuilderTarget"), propertyName, propertyType, expression, linePragma);
 }
Example #9
0
        private bool BuildSourceDataTree()
        {
            _compilParams = Parser.CompilParams;

            _codeCompileUnit = new CodeCompileUnit();
            _codeCompileUnit.UserData["AllowLateBound"]             = !Parser.FStrict;
            _codeCompileUnit.UserData["RequireVariableDeclaration"] = Parser.FExplicit;

            // Set a flag indicating if we're using the VJS compiler.  See comment in BuildExtractMethod for more information.
            _usingVJSCompiler = (_codeDomProvider.FileExtension == ".jsl");

            _sourceDataNamespace = new CodeNamespace(Parser.GeneratedNamespace);

            string generatedClassName = GetGeneratedClassName();

            if (Parser.BaseTypeName != null)
            {
                Debug.Assert(Parser.CodeFileVirtualPath != null);

                // This is the case where the page has a CodeFile attribute

                CodeNamespace intermediateNamespace = new CodeNamespace(Parser.BaseTypeNamespace);
                _codeCompileUnit.Namespaces.Add(intermediateNamespace);
                _intermediateClass = new CodeTypeDeclaration(Parser.BaseTypeName);

                // Specify the base class in the UserData in case the CodeDom provider needs
                // to reflect on it when generating code from the CodeCompileUnit (VSWhidbey 475294)
                // In design mode, use the default base type (e.g. Page or UserControl) to avoid
                // ending up with a type that can't be serialized to the Venus domain (VSWhidbey 545535)
                if (_designerMode)
                {
                    _intermediateClass.UserData["BaseClassDefinition"] = Parser.DefaultBaseType;
                }
                else
                {
                    _intermediateClass.UserData["BaseClassDefinition"] = Parser.BaseType;
                }

                intermediateNamespace.Types.Add(_intermediateClass);

                // Generate a partial class
                _intermediateClass.IsPartial = true;

                // Unless we're precompiling for updatable deployment, create the derived class
                if (!PrecompilingForUpdatableDeployment)
                {
                    _sourceDataClass = new CodeTypeDeclaration(generatedClassName);
                    // VSWhidbey 411701. Always use global type reference for the baseType
                    // when codefile is present.
                    _sourceDataClass.BaseTypes.Add(CodeDomUtility.BuildGlobalCodeTypeReference(
                                                       Util.MakeFullTypeName(Parser.BaseTypeNamespace, Parser.BaseTypeName)));

                    _sourceDataNamespace.Types.Add(_sourceDataClass);
                }
            }
            else
            {
                // The page is not using code besides

                _intermediateClass = new CodeTypeDeclaration(generatedClassName);
                _intermediateClass.BaseTypes.Add(CodeDomUtility.BuildGlobalCodeTypeReference(Parser.BaseType));
                _sourceDataNamespace.Types.Add(_intermediateClass);

                // There is only one class, so make both fields point to the same thing
                _sourceDataClass = _intermediateClass;
            }

            // Add the derived class namespace after the base partial class so C# parser
            // can still parse the code correctly in case the derived class contains error.
            // VSWhidbey 397646
            _codeCompileUnit.Namespaces.Add(_sourceDataNamespace);

            // We don't generate any code during updatable precompilation of a single (inline) page,
            // except for global.asax
            if (PrecompilingForUpdatableDeployment && Parser.CodeFileVirtualPath == null)
            {
                return(false);
            }

            // Add metadata attributes to the class
            GenerateClassAttributes();

            // In VB, always import Microsoft.VisualBasic (VSWhidbey 256475)
            if (_codeDomProvider is Microsoft.VisualBasic.VBCodeProvider)
            {
                _sourceDataNamespace.Imports.Add(new CodeNamespaceImport("Microsoft.VisualBasic"));
            }

            // Add all the namespaces
            if (Parser.NamespaceEntries != null)
            {
                foreach (NamespaceEntry entry in Parser.NamespaceEntries.Values)
                {
                    // Create a line pragma if available
                    CodeLinePragma linePragma;
                    if (entry.VirtualPath != null)
                    {
                        linePragma = CreateCodeLinePragma(entry.VirtualPath, entry.Line);
                    }
                    else
                    {
                        linePragma = null;
                    }

                    CodeNamespaceImport nsi = new CodeNamespaceImport(entry.Namespace);
                    nsi.LinePragma = linePragma;

                    _sourceDataNamespace.Imports.Add(nsi);
                }
            }

            if (_sourceDataClass != null)
            {
                // We need to generate a global reference to avoid ambiguities (VSWhidbey 284936)
                string            fullClassName = Util.MakeFullTypeName(_sourceDataNamespace.Name, _sourceDataClass.Name);
                CodeTypeReference classTypeRef  = CodeDomUtility.BuildGlobalCodeTypeReference(fullClassName);

                // Since this is needed in several places, store it in a member variable
                _classTypeExpr = new CodeTypeReferenceExpression(classTypeRef);
            }

            // Add the implemented interfaces
            GenerateInterfaces();

            // Build various properties, fields, methods
            BuildMiscClassMembers();

            // Build the default constructors
            if (!_designerMode && _sourceDataClass != null)
            {
                _ctor = new CodeConstructor();
                AddDebuggerNonUserCodeAttribute(_ctor);
                _sourceDataClass.Members.Add(_ctor);
                _ctor.Attributes &= ~MemberAttributes.AccessMask;
                _ctor.Attributes |= MemberAttributes.Public;
                BuildDefaultConstructor();
            }

            return(true);
        }