File: Compiler.cs

package info (click to toggle)
mono 6.14.1%2Bds2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,282,732 kB
  • sloc: cs: 11,182,461; xml: 2,850,281; ansic: 699,123; cpp: 122,919; perl: 58,604; javascript: 30,841; asm: 21,845; makefile: 19,602; sh: 10,973; python: 4,772; pascal: 925; sql: 859; sed: 16; php: 1
file content (171 lines) | stat: -rw-r--r-- 6,787 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
//------------------------------------------------------------------------------
// <copyright file="Compiler.cs" company="Microsoft">
//     Copyright (c) Microsoft Corporation.  All rights reserved.
// </copyright>
//------------------------------------------------------------------------------

namespace System.Web.Configuration {
    using System;
    using System.Xml;
    using System.Configuration;
    using System.Collections.Specialized;
    using System.Collections;
    using System.Globalization;
    using System.IO;
    using System.Text;
    using System.Web.Compilation;
    using System.Reflection;
    using System.Web.Hosting;
    using System.Web.UI;
    using System.CodeDom.Compiler;
    using System.Web.Util;
    using System.ComponentModel;
    using System.Security.Permissions;

    // CompilerCollection
    public sealed class Compiler : ConfigurationElement {
        private const string compilerOptionsAttribName = "compilerOptions";

        private static ConfigurationPropertyCollection _properties;
        private static readonly ConfigurationProperty _propLanguage =
            new ConfigurationProperty("language", typeof(string), String.Empty, ConfigurationPropertyOptions.None );
        private static readonly ConfigurationProperty _propExtension =
            new ConfigurationProperty("extension", typeof(string), String.Empty, ConfigurationPropertyOptions.None);
        private static readonly ConfigurationProperty _propType =
            new ConfigurationProperty("type", typeof(string), String.Empty, ConfigurationPropertyOptions.IsRequired | ConfigurationPropertyOptions.IsTypeStringTransformationRequired);
        private static readonly ConfigurationProperty _propWarningLevel =
            new ConfigurationProperty("warningLevel",
                                        typeof(int),
                                        0,
                                        null,
                                        new IntegerValidator(0, 4),
                                        ConfigurationPropertyOptions.None);
        private static readonly ConfigurationProperty _propCompilerOptions =
            new ConfigurationProperty(compilerOptionsAttribName, typeof(string), String.Empty, ConfigurationPropertyOptions.None);

        private CompilerType _compilerType;

        static Compiler() {
            // Property initialization
            _properties = new ConfigurationPropertyCollection();
            _properties.Add(_propLanguage);
            _properties.Add(_propExtension);
            _properties.Add(_propType);
            _properties.Add(_propWarningLevel);
            _properties.Add(_propCompilerOptions);
        }

        internal Compiler() {
        }

        public Compiler(String compilerOptions, String extension, String language, String type, int warningLevel)
            : this() {
            base[_propCompilerOptions] = compilerOptions;
            base[_propExtension] = extension;
            base[_propLanguage] = language;
            base[_propType] = type;
            base[_propWarningLevel] = warningLevel;
        }

        protected override ConfigurationPropertyCollection Properties {
            get {
                return _properties;
            }
        }

        [ConfigurationProperty("language", DefaultValue = "", IsRequired = true, IsKey = true)]
        public string Language {
            get {
                return (string)base[_propLanguage];
            }
            // Remove to satisfy defect number 178343
            //set
            //{
            //    base[_propLanguage] = value;
            //}
        }

        [ConfigurationProperty("extension", DefaultValue = "")]
        public string Extension {
            get {
                return (string)base[_propExtension];
            }
            // Remove to satisfy defect number 178343
            //set
            //{
            //    base[_propExtension] = value;
            //}
        }

        [ConfigurationProperty("type", IsRequired = true, DefaultValue = "")]
        public string Type {
            get {
                return (string)base[_propType];
            }
            // Remove to satisfy defect number 178343
            //set
            //{
            //    base[_propType] = value;
            //}
        }

        internal CompilerType CompilerTypeInternal {
            get {
                if (_compilerType == null) {
                    lock (this) {
                        if (_compilerType == null) {
                            Type codeDomProviderType = CompilationUtil.LoadTypeWithChecks(
                            Type, typeof(CodeDomProvider), null, this, "type");

                            System.CodeDom.Compiler.CompilerParameters compilParams = new CompilerParameters();
                            compilParams.WarningLevel = WarningLevel;

                            // Need to be false if the warning level is 0
                            compilParams.TreatWarningsAsErrors = (WarningLevel > 0);

                            // Only allow the use of compilerOptions when we have UnmanagedCode access (ASURT 73678)
                            string compilerOptions = CompilerOptions;

                            // Only allow the use of compilerOptions when we have UnmanagedCode access (ASURT 73678)
                            CompilationUtil.CheckCompilerOptionsAllowed(compilerOptions, true /*config*/,
                                ElementInformation.Properties[compilerOptionsAttribName].Source,
                                ElementInformation.Properties[compilerOptionsAttribName].LineNumber);

                            compilParams.CompilerOptions = compilerOptions;

                            _compilerType = new CompilerType(codeDomProviderType, compilParams);
                        }
                    }
                }

                return _compilerType;
            }
        }

        [ConfigurationProperty("warningLevel", DefaultValue = 0)]
        [IntegerValidator(MinValue = 0, MaxValue = 4)]
        public int WarningLevel {
            get {
                return (int)base[_propWarningLevel];
            }
            // Remove to satisfy defect number 178343
            //set
            //{
            //    base[_propWarningLevel] = value;
            //}
        }

        [ConfigurationProperty(compilerOptionsAttribName, DefaultValue = "")]
        public string CompilerOptions {
            get {
                return (string)base[_propCompilerOptions];
            }
            // Remove to satisfy defect number 178343
            //set
            //{
            //    base[_propCompilerOptions] = value;
            //}
        }

    } // class Compiler
}