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);
        }
 public override void GenerateCode(AssemblyBuilder assemblyBuilder)
 {
     if (this.Parser.RequiresCompilation)
     {
         BaseCodeDomTreeGenerator generator = this.CreateCodeDomTreeGenerator(this._parser);
         CodeCompileUnit          ccu       = generator.GetCodeDomTree(assemblyBuilder.CodeDomProvider, assemblyBuilder.StringResourceBuilder, base.VirtualPathObject);
         if (ccu != null)
         {
             if (this._parser.AssemblyDependencies != null)
             {
                 foreach (Assembly assembly in (IEnumerable)this._parser.AssemblyDependencies)
                 {
                     assemblyBuilder.AddAssemblyReference(assembly, ccu);
                 }
             }
             assemblyBuilder.AddCodeCompileUnit(this, ccu);
         }
         this._instantiatableFullTypeName = generator.GetInstantiatableFullTypeName();
         if (this._instantiatableFullTypeName != null)
         {
             assemblyBuilder.GenerateTypeFactory(this._instantiatableFullTypeName);
         }
         this._intermediateFullTypeName = generator.GetIntermediateFullTypeName();
     }
 }
Beispiel #3
0
        protected internal override CodeCompileUnit GetCodeCompileUnit(out IDictionary linePragmasTable)
        {
            Debug.Assert(_parser != null);

            // Return the provider type and compiler params
            Type codeDomProviderType = _parser.CompilerType.CodeDomProviderType;

            // Create a code generator for the language
            CodeDomProvider codeDomProvider = CompilationUtil.CreateCodeDomProviderNonPublic(
                codeDomProviderType);

            // Create a designer mode codedom tree for the page
            BaseCodeDomTreeGenerator treeGenerator = CreateCodeDomTreeGenerator(_parser);

            treeGenerator.SetDesignerMode();
            CodeCompileUnit ccu = treeGenerator.GetCodeDomTree(codeDomProvider,
                                                               new StringResourceBuilder(), VirtualPathObject);

            linePragmasTable = treeGenerator.LinePragmasTable;

// This code is used to see the full generated code in the debugger.  Just uncomment and look at
// generatedCode in the debugger.  Don't check in with this code uncommented!
#if TESTCODE
            Stream       stream = new MemoryStream();
            StreamWriter writer = new StreamWriter(stream, System.Text.Encoding.Unicode);
            codeDomProvider.GenerateCodeFromCompileUnit(ccu, writer, null /*CodeGeneratorOptions*/);
            writer.Flush();
            stream.Seek(0, SeekOrigin.Begin);
            TextReader reader        = new StreamReader(stream);
            string     generatedCode = reader.ReadToEnd();
#endif

            return(ccu);
        }
Beispiel #4
0
 private void EnsureCodeCompileUnit()
 {
     if (this._snippetCompileUnit == null)
     {
         string str = Util.StringFromVirtualPath(base.VirtualPathObject);
         this._snippetCompileUnit            = new CodeSnippetCompileUnit(str);
         this._snippetCompileUnit.LinePragma = BaseCodeDomTreeGenerator.CreateCodeLinePragmaHelper(base.VirtualPath, 1);
     }
 }
        protected internal override CodeCompileUnit GetCodeCompileUnit(out IDictionary linePragmasTable)
        {
            CodeDomProvider          codeDomProvider = CompilationUtil.CreateCodeDomProviderNonPublic(this._parser.CompilerType.CodeDomProviderType);
            BaseCodeDomTreeGenerator generator       = this.CreateCodeDomTreeGenerator(this._parser);

            generator.SetDesignerMode();
            CodeCompileUnit unit = generator.GetCodeDomTree(codeDomProvider, new StringResourceBuilder(), base.VirtualPathObject);

            linePragmasTable = generator.LinePragmasTable;
            return(unit);
        }
Beispiel #6
0
 private void EnsureCodeCompileUnit()
 {
     if (_snippetCompileUnit == null)
     {
         // Read the contents of the file
         string sourceString = Util.StringFromVirtualPath(VirtualPathObject);
         _snippetCompileUnit            = new CodeSnippetCompileUnit(sourceString);
         _snippetCompileUnit.LinePragma = BaseCodeDomTreeGenerator.CreateCodeLinePragmaHelper(
             VirtualPath, 1);
     }
 }
 private void BuildFrameworkInitializeMethod()
 {
     if (base._sourceDataClass != null)
     {
         CodeMemberMethod method = new CodeMemberMethod();
         base.AddDebuggerNonUserCodeAttribute(method);
         method.Attributes &= ~MemberAttributes.AccessMask;
         method.Attributes &= ~MemberAttributes.ScopeMask;
         method.Attributes |= MemberAttributes.Family | MemberAttributes.Override;
         method.Name        = "FrameworkInitialize";
         this.BuildFrameworkInitializeMethodContents(method);
         if (!base._designerMode && (this.Parser.CodeFileVirtualPath != null))
         {
             method.LinePragma = BaseCodeDomTreeGenerator.CreateCodeLinePragmaHelper(this.Parser.CodeFileVirtualPath.VirtualPathString, 0xdebb0);
         }
         base._sourceDataClass.Members.Add(method);
     }
 }
Beispiel #8
0
        public override void GenerateCode(AssemblyBuilder assemblyBuilder)
        {
            // Don't generate any code for no-compile pages
            if (!Parser.RequiresCompilation)
            {
                return;
            }

            BaseCodeDomTreeGenerator treeGenerator = CreateCodeDomTreeGenerator(_parser);

            CodeCompileUnit ccu = treeGenerator.GetCodeDomTree(assemblyBuilder.CodeDomProvider,
                                                               assemblyBuilder.StringResourceBuilder, VirtualPathObject);

            if (ccu != null)
            {
                // Add all the assemblies
                if (_parser.AssemblyDependencies != null)
                {
                    foreach (Assembly assembly in _parser.AssemblyDependencies)
                    {
                        assemblyBuilder.AddAssemblyReference(assembly, ccu);
                    }
                }

                assemblyBuilder.AddCodeCompileUnit(this, ccu);
            }

            // Get the name of the generated type that can be instantiated.  It may be null
            // in updatable compilation scenarios.
            _instantiatableFullTypeName = treeGenerator.GetInstantiatableFullTypeName();

            // tell the assembly builder to generate a fast factory for this type
            if (_instantiatableFullTypeName != null)
            {
                assemblyBuilder.GenerateTypeFactory(_instantiatableFullTypeName);
            }

            _intermediateFullTypeName = treeGenerator.GetIntermediateFullTypeName();
        }