//
using System.Collections;
+using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.IO;
using System.Runtime.InteropServices;
using System.Security.Permissions;
+#pragma warning disable 618
+
namespace System.CodeDom.Compiler {
-#if NET_2_0
[ComVisible (true)]
-#endif
[ToolboxItem (false)]
public abstract class CodeDomProvider : Component
{
//
// Methods
//
-#if NET_2_0
[Obsolete ("ICodeCompiler is obsolete")]
-#endif
public abstract ICodeCompiler CreateCompiler();
-#if NET_2_0
[Obsolete ("ICodeGenerator is obsolete")]
-#endif
public abstract ICodeGenerator CreateGenerator();
public virtual ICodeGenerator CreateGenerator (string fileName)
return CreateGenerator();
}
-#if NET_2_0
[Obsolete ("ICodeParser is obsolete")]
-#endif
public virtual ICodeParser CreateParser()
{
return null;
return TypeDescriptor.GetConverter (type);
}
-#if NET_2_0
public virtual CompilerResults CompileAssemblyFromDom (CompilerParameters options, params CodeCompileUnit[] compilationUnits)
{
ICodeCompiler cc = CreateCompiler ();
if (cc == null)
- throw new NotImplementedException ();
+ throw GetNotImplemented ();
return cc.CompileAssemblyFromDomBatch (options, compilationUnits);
}
{
ICodeCompiler cc = CreateCompiler ();
if (cc == null)
- throw new NotImplementedException ();
+ throw GetNotImplemented ();
return cc.CompileAssemblyFromFileBatch (options, fileNames);
}
- public virtual CompilerResults CompileAssemblyFromSource (CompilerParameters options, params string[] fileNames)
+ public virtual CompilerResults CompileAssemblyFromSource (CompilerParameters options, params string[] sources)
{
ICodeCompiler cc = CreateCompiler ();
if (cc == null)
- throw new NotImplementedException ();
- return cc.CompileAssemblyFromSourceBatch (options, fileNames);
+ throw GetNotImplemented ();
+ return cc.CompileAssemblyFromSourceBatch (options, sources);
}
public virtual string CreateEscapedIdentifier (string value)
{
ICodeGenerator cg = CreateGenerator ();
if (cg == null)
- throw new NotImplementedException ();
+ throw GetNotImplemented ();
return cg.CreateEscapedIdentifier (value);
}
+#if CONFIGURATION_DEP
[ComVisible (false)]
[PermissionSet (SecurityAction.LinkDemand, Unrestricted = true)]
public static CodeDomProvider CreateProvider (string language)
CompilerInfo ci = GetCompilerInfo (language);
return (ci == null) ? null : ci.CreateProvider ();
}
+ [ComVisible (false)]
+ public static CodeDomProvider CreateProvider (string language, IDictionary<string, string> providerOptions)
+ {
+ CompilerInfo ci = GetCompilerInfo (language);
+ return ci == null ? null : ci.CreateProvider (providerOptions);
+ }
+#endif
public virtual string CreateValidIdentifier (string value)
{
ICodeGenerator cg = CreateGenerator ();
if (cg == null)
- throw new NotImplementedException ();
+ throw GetNotImplemented ();
return cg.CreateValidIdentifier (value);
}
{
ICodeGenerator cg = CreateGenerator ();
if (cg == null)
- throw new NotImplementedException ();
+ throw GetNotImplemented ();
cg.GenerateCodeFromCompileUnit (compileUnit, writer, options);
}
{
ICodeGenerator cg = CreateGenerator ();
if (cg == null)
- throw new NotImplementedException ();
+ throw GetNotImplemented ();
cg.GenerateCodeFromExpression (expression, writer, options);
}
public virtual void GenerateCodeFromMember (CodeTypeMember member, TextWriter writer, CodeGeneratorOptions options)
{
// Documented to always throw an exception (if not overriden)
- throw new NotImplementedException ();
+ throw GetNotImplemented ();
// Note: the pattern is different from other GenerateCodeFrom* because
// ICodeGenerator doesn't have a GenerateCodeFromMember member
}
{
ICodeGenerator cg = CreateGenerator ();
if (cg == null)
- throw new NotImplementedException ();
+ throw GetNotImplemented ();
cg.GenerateCodeFromNamespace (codeNamespace, writer, options);
}
{
ICodeGenerator cg = CreateGenerator ();
if (cg == null)
- throw new NotImplementedException ();
+ throw GetNotImplemented ();
cg.GenerateCodeFromStatement (statement, writer, options);
}
{
ICodeGenerator cg = CreateGenerator ();
if (cg == null)
- throw new NotImplementedException ();
+ throw GetNotImplemented ();
cg.GenerateCodeFromType (codeType, writer, options);
}
+#if CONFIGURATION_DEP
[ComVisible (false)]
[PermissionSet (SecurityAction.LinkDemand, Unrestricted = true)]
public static CompilerInfo[] GetAllCompilerInfo ()
{
- int n = 0;
- if ((Config != null) && (Config.Compilers != null))
- n = Config.Compilers.Hash.Count;
- CompilerInfo[] ci = new CompilerInfo [n];
- if (n > 0)
- Config.Compilers.Hash.Values.CopyTo (ci, 0);
- return ci;
+
+ return (Config == null) ? null : Config.CompilerInfos;
}
+
[ComVisible (false)]
[PermissionSet (SecurityAction.LinkDemand, Unrestricted = true)]
public static CompilerInfo GetCompilerInfo (string language)
{
if (language == null)
throw new ArgumentNullException ("language");
-
- return (Config == null) ? null : Config.GetCompilerInfo (language);
+ if (Config == null)
+ return null;
+ CompilerCollection cc = Config.Compilers;
+ return cc[language];
}
[ComVisible (false)]
if (extension == null)
throw new ArgumentNullException ("extension");
- if (Config != null) {
- foreach (DictionaryEntry de in Config.Compilers.Hash) {
- CompilerInfo c = (CompilerInfo) de.Value;
- if (Array.IndexOf (c.GetExtensions (), extension) != -1)
- return (string) de.Key;
- }
- }
+ if (Config != null)
+ return Config.Compilers.GetLanguageFromExtension (extension);
return null;
}
+#else
+ public static CompilerInfo[] GetAllCompilerInfo () { return null; }
+ public static CompilerInfo GetCompilerInfo (string language) { return null; }
+ public static string GetLanguageFromExtension (string extension) { return null; }
+#endif
public virtual string GetTypeOutput (CodeTypeReference type)
{
ICodeGenerator cg = CreateGenerator ();
if (cg == null)
- throw new NotImplementedException ();
+ throw GetNotImplemented ();
return cg.GetTypeOutput (type);
}
+#if CONFIGURATION_DEP
[ComVisible (false)]
[PermissionSet (SecurityAction.LinkDemand, Unrestricted = true)]
public static bool IsDefinedExtension (string extension)
if (extension == null)
throw new ArgumentNullException ("extension");
- if (Config != null) {
- foreach (CompilerInfo c in Config.Compilers.Hash.Values) {
- if (Array.IndexOf (c.GetExtensions (), extension) != -1)
- return true;
- }
- }
+ if (Config != null)
+ return (Config.Compilers.GetCompilerInfoForExtension (extension) != null);
+
return false;
}
if (language == null)
throw new ArgumentNullException ("language");
- if (Config == null)
- return false;
- return (Config.GetCompilerInfo (language) == null);
+ if (Config != null)
+ return (Config.Compilers.GetCompilerInfoForLanguage (language) != null);
+
+ return false;
}
+#endif
public virtual bool IsValidIdentifier (string value)
{
ICodeGenerator cg = CreateGenerator ();
if (cg == null)
- throw new NotImplementedException ();
+ throw GetNotImplemented ();
return cg.IsValidIdentifier (value);
}
{
ICodeParser cp = CreateParser ();
if (cp == null)
- throw new NotImplementedException ();
+ throw GetNotImplemented ();
return cp.Parse (codeStream);
}
{
ICodeGenerator cg = CreateGenerator ();
if (cg == null)
- throw new NotImplementedException ();
+ throw GetNotImplemented ();
return cg.Supports (supports);
}
- static CompilationConfiguration Config {
- get { return ConfigurationSettings.GetConfig ("system.codedom") as CompilationConfiguration; }
+#if CONFIGURATION_DEP
+ static CodeDomConfigurationHandler Config {
+ get { return ConfigurationManager.GetSection ("system.codedom") as CodeDomConfigurationHandler; }
}
#endif
+
+ //
+ // This is used to prevent confusing Moma about methods not implemented.
+ //
+ Exception GetNotImplemented ()
+ {
+ return new NotImplementedException ();
+ }
}
}
+
+#pragma warning restore 618
\ No newline at end of file