Esempio n. 1
0
 /// <summary>
 /// If the compilerVersion is anything other than "v3.5", return "v2.0".
 /// </summary>
 private static string ReplaceCompilerVersionFor20Or35(string compilerVersion)
 {
     if (CompilationUtil.IsCompilerVersion35(compilerVersion))
     {
         return(compilerVersion);
     }
     return("v2.0");
 }
Esempio n. 2
0
        private static void InitializeTargetFrameworkNameFor20Or35()
        {
            string compilerVersion = GetCompilerVersionFor20Or35();

            if (CompilationUtil.IsCompilerVersion35(compilerVersion))
            {
                s_targetFrameworkName = FrameworkNameV35;
            }
            else
            {
                if ((compilerVersion != "v2.0") && (compilerVersion != null))
                {
                    throw new ConfigurationErrorsException(System.Web.SR.GetString("Compiler_version_20_35_required", new object[] { s_configTargetFrameworkAttributeName }));
                }
                s_targetFrameworkName = FrameworkNameV30;
            }
        }
        public override void GenerateCode(AssemblyBuilder assemblyBuilder)
        {
            string      namespaceFromVirtualPath = Util.GetNamespaceFromVirtualPath(base.VirtualPathObject);
            XmlDocument document = new XmlDocument();

            using (Stream stream = base.OpenStream())
            {
                document.Load(stream);
            }
            string          outerXml    = document.OuterXml;
            CodeCompileUnit compileUnit = new CodeCompileUnit();
            CodeNamespace   namespace2  = new CodeNamespace(namespaceFromVirtualPath);

            compileUnit.Namespaces.Add(namespace2);
            if (CompilationUtil.IsCompilerVersion35OrAbove(assemblyBuilder.CodeDomProvider.GetType()))
            {
                TypedDataSetGenerator.GenerateOption none = TypedDataSetGenerator.GenerateOption.None;
                none |= TypedDataSetGenerator.GenerateOption.HierarchicalUpdate;
                none |= TypedDataSetGenerator.GenerateOption.LinqOverTypedDatasets;
                Hashtable customDBProviders = null;
                TypedDataSetGenerator.Generate(outerXml, compileUnit, namespace2, assemblyBuilder.CodeDomProvider, customDBProviders, none);
            }
            else
            {
                TypedDataSetGenerator.Generate(outerXml, compileUnit, namespace2, assemblyBuilder.CodeDomProvider);
            }
            if (TypedDataSetGenerator.ReferencedAssemblies != null)
            {
                bool flag2 = CompilationUtil.IsCompilerVersion35(assemblyBuilder.CodeDomProvider.GetType());
                foreach (Assembly assembly in TypedDataSetGenerator.ReferencedAssemblies)
                {
                    if (flag2)
                    {
                        AssemblyName name = assembly.GetName();
                        if (name.Name == "System.Data.DataSetExtensions")
                        {
                            name.Version = new Version(3, 5, 0, 0);
                            CompilationSection.RecordAssembly(name.FullName, assembly);
                        }
                    }
                    assemblyBuilder.AddAssemblyReference(assembly);
                }
            }
            assemblyBuilder.AddCodeCompileUnit(this, compileUnit);
        }
Esempio n. 4
0
        /// <summary>
        /// Checks codedom settings to determine whether we are targeting 2.0 or 3.5.
        /// </summary>
        private static void InitializeTargetFrameworkNameFor20Or35()
        {
            string compilerVersion = GetCompilerVersionFor20Or35();

            // Make sure the compiler version is either 2.0 or 3.5
            if (CompilationUtil.IsCompilerVersion35(compilerVersion))
            {
                s_targetFrameworkName = FrameworkNameV35;
            }
            else if (compilerVersion == "v2.0" || compilerVersion == null)
            {
                // If the compiler version is null, it means the user did not set it
                // in the codedom section.
                // We use 3.0 because it is not possible to distinguish between 2.0 and 3.0
                // by just looking at web.config.
                s_targetFrameworkName = FrameworkNameV30;
            }
            else
            {
                throw new ConfigurationErrorsException(SR.GetString(SR.Compiler_version_20_35_required, s_configTargetFrameworkAttributeName));
            }
        }
Esempio n. 5
0
        public override void GenerateCode(AssemblyBuilder assemblyBuilder)
        {
#if !FEATURE_PAL // FEATURE_PAL does not support System.Data.Design
            // Get the namespace that we will use
            string ns = Util.GetNamespaceFromVirtualPath(VirtualPathObject);

            // We need to use XmlDocument to parse the xsd file is order to open it with the
            // correct encoding (VSWhidbey 566286)
            XmlDocument doc = new XmlDocument();
            using (Stream stream = OpenStream()) {
                doc.Load(stream);
            }
            String content = doc.OuterXml;

            // Generate a CodeCompileUnit from the dataset
            CodeCompileUnit codeCompileUnit = new CodeCompileUnit();

            CodeNamespace codeNamespace = new CodeNamespace(ns);
            codeCompileUnit.Namespaces.Add(codeNamespace);

            // Devdiv 18365, Dev10

            bool isVer35OrAbove = CompilationUtil.IsCompilerVersion35OrAbove(assemblyBuilder.CodeDomProvider.GetType());

            if (isVer35OrAbove)
            {
                TypedDataSetGenerator.GenerateOption generateOptions = TypedDataSetGenerator.GenerateOption.None;
                generateOptions |= TypedDataSetGenerator.GenerateOption.HierarchicalUpdate;
                generateOptions |= TypedDataSetGenerator.GenerateOption.LinqOverTypedDatasets;
                Hashtable customDBProviders = null;
                TypedDataSetGenerator.Generate(content, codeCompileUnit, codeNamespace, assemblyBuilder.CodeDomProvider, customDBProviders, generateOptions);
            }
            else
            {
                TypedDataSetGenerator.Generate(content, codeCompileUnit, codeNamespace, assemblyBuilder.CodeDomProvider);
            }

            // Add all the assembly references needed by the generated code
            if (TypedDataSetGenerator.ReferencedAssemblies != null)
            {
                var isVer35 = CompilationUtil.IsCompilerVersion35(assemblyBuilder.CodeDomProvider.GetType());
                foreach (Assembly a in TypedDataSetGenerator.ReferencedAssemblies)
                {
                    if (isVer35)
                    {
                        var aName = a.GetName();
                        if (aName.Name == "System.Data.DataSetExtensions")
                        {
                            // Dev10

                            aName.Version = new Version(3, 5, 0, 0);
                            CompilationSection.RecordAssembly(aName.FullName, a);
                        }
                    }
                    assemblyBuilder.AddAssemblyReference(a);
                }
            }


            // Add the CodeCompileUnit to the compilation
            assemblyBuilder.AddCodeCompileUnit(this, codeCompileUnit);
#else // !FEATURE_PAL
            throw new NotImplementedException("System.Data.Design - ROTORTODO");
#endif // !FEATURE_PAL
        }