本文整理汇总了C#中System.CodeDom.Compiler.CompilerErrorCollection.AddRange方法的典型用法代码示例。如果您正苦于以下问题:C# CompilerErrorCollection.AddRange方法的具体用法?C# CompilerErrorCollection.AddRange怎么用?C# CompilerErrorCollection.AddRange使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.CodeDom.Compiler.CompilerErrorCollection
的用法示例。
在下文中一共展示了CompilerErrorCollection.AddRange方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Constructor0_Deny_Unrestricted
public void Constructor0_Deny_Unrestricted ()
{
CompilerErrorCollection coll = new CompilerErrorCollection ();
Assert.AreEqual (0, coll.Add (ce), "Add");
Assert.AreSame (ce, coll[0], "this[int]");
coll[0] = ce;
coll.CopyTo (array, 0);
coll.AddRange (array);
coll.AddRange (coll);
Assert.IsTrue (coll.Contains (ce), "Contains");
Assert.AreEqual (0, coll.IndexOf (ce), "IndexOf");
coll.Insert (0, ce);
coll.Remove (ce);
ce.IsWarning = false;
Assert.IsTrue (coll.HasErrors, "HasErrors");
Assert.IsFalse (coll.HasWarnings, "HasWarnings");
}
示例2: CompileInternal
private static Assembly CompileInternal(String outputAssembly, IEnumerable<String> references, CodeDomProvider provider, CompilerErrorCollection Errors, Template tmp)
{
var options = new CompilerParameters();
foreach (var str in references)
{
options.ReferencedAssemblies.Add(str);
}
options.WarningLevel = 4;
CompilerResults results = null;
if (Debug)
{
#region 调试状态,把生成的类文件和最终dll输出到XTemp目录下
var tempPath = XTrace.TempPath;
//if (!String.IsNullOrEmpty(outputAssembly)) tempPath = Path.Combine(tempPath, Path.GetFileNameWithoutExtension(outputAssembly));
if (!String.IsNullOrEmpty(outputAssembly) && !outputAssembly.Equals(".dll")) tempPath = Path.Combine(tempPath, Path.GetFileNameWithoutExtension(outputAssembly));
if (!String.IsNullOrEmpty(tempPath) && !Directory.Exists(tempPath)) Directory.CreateDirectory(tempPath);
var files = new List<String>();
foreach (var item in tmp.Templates)
{
if (item.Included) continue;
String name = item.Name.EndsWith(".cs", StringComparison.OrdinalIgnoreCase) ? item.Name : item.ClassName;
// 猜测后缀
Int32 p = name.LastIndexOf("_");
if (p > 0 && name.Length - p <= 5)
name = name.Substring(0, p) + "." + name.Substring(p + 1, name.Length - p - 1);
else if (!name.EndsWith(".cs", StringComparison.OrdinalIgnoreCase))
name += ".cs";
name = Path.Combine(tempPath, name);
File.WriteAllText(name, item.Source, Encoding.UTF8);
files.Add(name);
}
#endregion
if (!String.IsNullOrEmpty(outputAssembly) && !outputAssembly.Equals(".dll"))
{
options.TempFiles = new TempFileCollection(tempPath, false);
options.OutputAssembly = Path.Combine(tempPath, outputAssembly);
options.GenerateInMemory = true;
options.IncludeDebugInformation = true;
}
results = provider.CompileAssemblyFromFile(options, files.ToArray());
}
else
{
List<String> sources = new List<String>();
foreach (var item in tmp.Templates)
{
sources.Add(item.Source);
}
options.GenerateInMemory = true;
results = provider.CompileAssemblyFromSource(options, sources.ToArray());
}
#region 编译错误处理
if (results.Errors.Count > 0)
{
Errors.AddRange(results.Errors);
var sb = new StringBuilder();
CompilerError err = null;
foreach (CompilerError error in results.Errors)
{
error.ErrorText = error.ErrorText;
//if (String.IsNullOrEmpty(error.FileName)) error.FileName = inputFile;
if (!error.IsWarning)
{
String msg = error.ToString();
if (sb.Length < 1)
{
String code = null;
// 屏蔽因为计算错误行而导致的二次错误
try
{
code = tmp.FindBlockCode(error.FileName, error.Line);
}
catch { }
if (code != null)
{
msg += Environment.NewLine;
msg += code;
}
err = error;
}
else
sb.AppendLine();
sb.Append(msg);
}
}
if (sb.Length > 0)
{
//.........这里部分代码省略.........