Esempio n. 1
0
        protected override void CreateConstructor(CodeStatementCollection localVars,
                                                  CodeStatementCollection trueStmt)
        {
#if NET_2_0
            if (!String.IsNullOrEmpty(pageParser.MasterPageFile))
            {
                // This is here just to trigger master page build, so that its type
                // is available when compiling the page itself.
                BuildManager.GetCompiledType(pageParser.MasterPageFile);
            }
#endif
            if (pageParser.ClientTarget != null)
            {
                CodeExpression prop;
                prop = new CodePropertyReferenceExpression(thisRef, "ClientTarget");
                CodeExpression ct = new CodePrimitiveExpression(pageParser.ClientTarget);
                if (localVars == null)
                {
                    localVars = new CodeStatementCollection();
                }
                localVars.Add(new CodeAssignStatement(prop, ct));
            }

            ArrayList deps      = pageParser.Dependencies;
            int       depsCount = deps != null ? deps.Count : 0;

            if (depsCount > 0)
            {
                if (localVars == null)
                {
                    localVars = new CodeStatementCollection();
                }
                if (trueStmt == null)
                {
                    trueStmt = new CodeStatementCollection();
                }

                CodeAssignStatement assign;
#if NET_2_0
                localVars.Add(
                    new CodeVariableDeclarationStatement(
                        typeof(string[]),
                        "dependencies")
                    );

                CodeVariableReferenceExpression dependencies = new CodeVariableReferenceExpression("dependencies");
                trueStmt.Add(
                    new CodeAssignStatement(dependencies, new CodeArrayCreateExpression(typeof(string), depsCount))
                    );

                CodeArrayIndexerExpression arrayIndex;
                object o;

                for (int i = 0; i < depsCount; i++)
                {
                    o          = deps [i];
                    arrayIndex = new CodeArrayIndexerExpression(dependencies, new CodeExpression[] { new CodePrimitiveExpression(i) });
                    assign     = new CodeAssignStatement(arrayIndex, new CodePrimitiveExpression(o));
                    trueStmt.Add(assign);
                }

                CodeMethodInvokeExpression getDepsCall = new CodeMethodInvokeExpression(
                    thisRef,
                    "GetWrappedFileDependencies",
                    new CodeExpression[] { dependencies }
                    );
                assign = new CodeAssignStatement(GetMainClassFieldReferenceExpression("__fileDependencies"), getDepsCall);
#else
                localVars.Add(new CodeVariableDeclarationStatement(
                                  typeof(ArrayList),
                                  "dependencies")
                              );

                CodeVariableReferenceExpression dependencies = new CodeVariableReferenceExpression("dependencies");
                trueStmt.Add(
                    new CodeAssignStatement(dependencies, new CodeObjectCreateExpression(typeof(ArrayList), new CodeExpression[] { new CodePrimitiveExpression(depsCount) }))
                    );

                CodeMethodInvokeExpression invoke;
                for (int i = 0; i < depsCount; i++)
                {
                    invoke = new CodeMethodInvokeExpression(dependencies, "Add", new CodeExpression[] { new CodePrimitiveExpression(deps [i]) });
                    trueStmt.Add(invoke);
                }
                assign = new CodeAssignStatement(GetMainClassFieldReferenceExpression("__fileDependencies"), dependencies);
#endif

                trueStmt.Add(assign);
            }

            base.CreateConstructor(localVars, trueStmt);
        }
        protected override void CreateConstructor(CodeStatementCollection localVars,
                                                  CodeStatementCollection trueStmt)
        {
            MainDirectiveAttribute <string> masterPageFile = pageParser.MasterPageFile;

            if (masterPageFile != null && !masterPageFile.IsExpression)
            {
                // This is here just to trigger master page build, so that its type
                // is available when compiling the page itself.
                BuildManager.GetCompiledType(masterPageFile.Value);
            }

            MainDirectiveAttribute <string> clientTarget;

            clientTarget = pageParser.ClientTarget;
            if (clientTarget != null)
            {
                CodeExpression prop;
                prop = new CodePropertyReferenceExpression(thisRef, "ClientTarget");
                CodeExpression ct = null;

                if (clientTarget.IsExpression)
                {
                    var pi = GetFieldOrProperty(typeof(Page), "ClientTarget") as PropertyInfo;
                    if (pi != null)
                    {
                        ct = CompileExpression(pi, pi.PropertyType, clientTarget.UnparsedValue, false);
                    }
                }

                if (ct == null)
                {
                    ct = new CodePrimitiveExpression(clientTarget.Value);
                }
                if (localVars == null)
                {
                    localVars = new CodeStatementCollection();
                }
                localVars.Add(new CodeAssignStatement(prop, ct));
            }

            List <string> deps      = pageParser.Dependencies;
            int           depsCount = deps != null ? deps.Count : 0;

            if (depsCount > 0)
            {
                if (localVars == null)
                {
                    localVars = new CodeStatementCollection();
                }
                if (trueStmt == null)
                {
                    trueStmt = new CodeStatementCollection();
                }

                CodeAssignStatement assign;
                localVars.Add(
                    new CodeVariableDeclarationStatement(
                        typeof(string[]),
                        "dependencies")
                    );

                CodeVariableReferenceExpression dependencies = new CodeVariableReferenceExpression("dependencies");
                trueStmt.Add(
                    new CodeAssignStatement(dependencies, new CodeArrayCreateExpression(typeof(string), depsCount))
                    );

                CodeArrayIndexerExpression arrayIndex;
                object o;

                for (int i = 0; i < depsCount; i++)
                {
                    o          = deps [i];
                    arrayIndex = new CodeArrayIndexerExpression(dependencies, new CodeExpression[] { new CodePrimitiveExpression(i) });
                    assign     = new CodeAssignStatement(arrayIndex, new CodePrimitiveExpression(o));
                    trueStmt.Add(assign);
                }

                CodeMethodInvokeExpression getDepsCall = new CodeMethodInvokeExpression(
                    thisRef,
                    "GetWrappedFileDependencies",
                    new CodeExpression[] { dependencies }
                    );
                assign = new CodeAssignStatement(GetMainClassFieldReferenceExpression("__fileDependencies"), getDepsCall);

                trueStmt.Add(assign);
            }

            base.CreateConstructor(localVars, trueStmt);
        }