本文整理汇总了C#中LanguageVersion类的典型用法代码示例。如果您正苦于以下问题:C# LanguageVersion类的具体用法?C# LanguageVersion怎么用?C# LanguageVersion使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
LanguageVersion类属于命名空间,在下文中一共展示了LanguageVersion类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: VerifyCSharpFixAsync
/// <summary>
/// Called to test a C# codefix when applied on the inputted string as a source
/// </summary>
/// <param name="oldSource">A class in the form of a string before the CodeFix was applied to it</param>
/// <param name="newSource">A class in the form of a string after the CodeFix was applied to it</param>
/// <param name="codeFixIndex">Index determining which codefix to apply if there are multiple</param>
/// <param name="allowNewCompilerDiagnostics">A bool controlling whether or not the test will fail if the CodeFix introduces other warnings after being applied</param>
/// <param name="formatBeforeCompare">Format the code before comparing, bot the old source and the new.</param>
/// <param name="codeFixProvider">The codefix to be applied to the code wherever the relevant Diagnostic is found</param>
/// <param name="languageVersionCSharp">C# language version used for compiling the test project, required unless you inform the VB language version.</param>
protected async Task VerifyCSharpFixAsync(string oldSource, string newSource, int? codeFixIndex = null, bool allowNewCompilerDiagnostics = false, bool formatBeforeCompare = true, CodeFixProvider codeFixProvider = null, LanguageVersion languageVersionCSharp = LanguageVersion.CSharp6)
{
if (formatBeforeCompare)
{
oldSource = await FormatSourceAsync(LanguageNames.CSharp, oldSource, languageVersionCSharp).ConfigureAwait(true);
newSource = await FormatSourceAsync(LanguageNames.CSharp, newSource, languageVersionCSharp).ConfigureAwait(true);
}
codeFixProvider = codeFixProvider ?? GetCodeFixProvider();
var diagnosticAnalyzer = GetDiagnosticAnalyzer();
if (diagnosticAnalyzer != null)
await VerifyFixAsync(LanguageNames.CSharp, diagnosticAnalyzer, codeFixProvider, oldSource, newSource, codeFixIndex, allowNewCompilerDiagnostics, languageVersionCSharp, Microsoft.CodeAnalysis.VisualBasic.LanguageVersion.VisualBasic14).ConfigureAwait(true);
else
await VerifyFixAsync(LanguageNames.CSharp, codeFixProvider.FixableDiagnosticIds, codeFixProvider, oldSource, newSource, codeFixIndex, allowNewCompilerDiagnostics, languageVersionCSharp, Microsoft.CodeAnalysis.VisualBasic.LanguageVersion.VisualBasic14).ConfigureAwait(true);
}
示例2: CSharpProject
public CSharpProject(string projectFile)
{
if (!File.Exists(projectFile))
throw new Exception(string.Format("project file not found \"{0}\"", projectFile));
WriteLine(1, "compile project \"{0}\"", projectFile);
_projectFile = projectFile;
_projectDirectory = Path.GetDirectoryName(projectFile);
_projectDocument = XDocument.Load(projectFile);
_frameworkDirectory = GetValue("FrameworkDirectory");
WriteLine(2, " framework directory : \"{0}\"", _frameworkDirectory);
_assemblyName = GetValue("AssemblyName");
WriteLine(2, " assembly name : \"{0}\"", _assemblyName);
string outputDirectory = PathCombine(_projectDirectory, GetValue("OutputDirectory"));
WriteLine(2, " output directory : \"{0}\"", outputDirectory);
_languageVersion = GetLanguageVersion(GetValue("LanguageVersion"));
WriteLine(2, " language version : \"{0}\"", _languageVersion);
_outputKind = GetOutputKind(GetValue("OutputKind"));
WriteLine(2, " output kind : \"{0}\"", _outputKind);
_optimizationLevel = GetOptimizationLevel(GetValue("OptimizationLevel"));
WriteLine(2, " optimization level : \"{0}\"", _optimizationLevel);
_platform = GetPlatform(GetValue("Platform"));
WriteLine(2, " platform : \"{0}\"", _platform);
_generalDiagnosticOption = ReportDiagnostic.Default;
WriteLine(2, " general diagnostic option : \"{0}\"", _generalDiagnosticOption);
_warningLevel = 4;
WriteLine(2, " warning level : \"{0}\"", _warningLevel);
_outputPath = PathCombine(outputDirectory, GetValue("OutputPath"));
WriteLine(2, " output path : \"{0}\"", _outputPath);
_pdbPath = PathCombine(outputDirectory, GetValue("PdbPath"));
WriteLine(2, " pdb path : \"{0}\"", _pdbPath);
_win32ResourceFile = PathCombine(_projectDirectory, GetValue("Win32ResourceFile"));
WriteLine(2, " win32 resource file : \"{0}\"", _win32ResourceFile);
_preprocessorSymbols = GetPreprocessorSymbols();
_sourceFiles = GetSources();
_resourceFiles = GetResourceFiles();
_assembliesFiles = GetAssembliesFiles();
}
示例3: Copy
public ParseOptions Copy(
CompatibilityMode? compatibility = null,
LanguageVersion? languageVersion = null,
IEnumerable<string> preprocessorSymbols = null,
bool? suppressDocumentationCommentParse = null,
SourceCodeKind? kind = SourceCodeKind.Regular)
{
return new ParseOptions(
compatibility ?? this.Compatibility,
languageVersion ?? this.LanguageVersion,
preprocessorSymbols ?? this.PreprocessorSymbols.AsEnumerable(),
suppressDocumentationCommentParse ?? this.SuppressDocumentationCommentParse,
kind ?? this.Kind
);
}
示例4: CompilerSettings
public CompilerSettings ()
{
StdLib = true;
Target = Target.Exe;
TargetExt = ".exe";
Platform = Platform.AnyCPU;
Version = LanguageVersion.Default;
VerifyClsCompliance = true;
Encoding = Encoding.UTF8;
LoadDefaultReferences = true;
StdLibRuntimeVersion = RuntimeVersion.v4;
WarningLevel = 4;
// Default to 1 or mdb files would be platform speficic
TabSize = 1;
AssemblyReferences = new List<string> ();
AssemblyReferencesAliases = new List<Tuple<string, string>> ();
Modules = new List<string> ();
ReferencesLookupPaths = new List<string> ();
conditional_symbols = new List<string> ();
//
// Add default mcs define
//
conditional_symbols.Add ("__MonoCS__");
source_files = new List<SourceFile> ();
}
示例5: Reset
public static void Reset(bool full)
{
impl_details_class = null;
helper_classes = null;
if (!full)
return;
EntryPoint = null;
Checked = false;
Unsafe = false;
StdLib = true;
StrongNameKeyFile = null;
StrongNameKeyContainer = null;
StrongNameDelaySign = false;
MainClass = null;
Target = Target.Exe;
TargetExt = ".exe";
Platform = Platform.AnyCPU;
Version = LanguageVersion.Default;
Documentation = null;
impl_details_class = null;
helper_classes = null;
#if NET_4_0
MetadataCompatibilityVersion = MetadataVersion.v4;
#else
MetadataCompatibilityVersion = MetadataVersion.v2;
#endif
//
// Setup default defines
//
AllDefines = new List<string> ();
AddConditional ("__MonoCS__");
}
示例6: GetSortedDiagnosticsAsync
/// <summary>
/// Given classes in the form of strings, their language, and an IDiagnosticAnlayzer to apply to it, return the diagnostics found in the string after converting it to a document.
/// </summary>
/// <param name="sources">Classes in the form of strings</param>
/// <param name="language">The language the soruce classes are in</param>
/// <param name="analyzer">The analyzer to be run on the sources</param>
/// <param name="languageVersionCSharp">C# language version used for compiling the test project, required unless you inform the VB language version.</param>
/// <param name="languageVersionVB">VB language version used for compiling the test project, required unless you inform the C# language version.</param>
/// <returns>An IEnumerable of Diagnostics that surfaced in teh source code, sorted by Location</returns>
private static async Task<Diagnostic[]> GetSortedDiagnosticsAsync(string[] sources, string language, DiagnosticAnalyzer analyzer, LanguageVersion languageVersionCSharp, Microsoft.CodeAnalysis.VisualBasic.LanguageVersion languageVersionVB) =>
await GetSortedDiagnosticsFromDocumentsAsync(analyzer, GetDocuments(sources, language, languageVersionCSharp, languageVersionVB)).ConfigureAwait(true);
示例7: CreateProject
/// <summary>
/// Create a project using the inputted strings as sources.
/// </summary>
/// <param name="sources">Classes in the form of strings</param>
/// <param name="language">The language the source code is in</param>
/// <param name="languageVersionCSharp">C# language version used for compiling the test project, required unless you inform the VB language version.</param>
/// <param name="languageVersionVB">VB language version used for compiling the test project, required unless you inform the C# language version.</param>
/// <returns>A Project created out of the Douments created from the source strings</returns>
public static Project CreateProject(string[] sources,
string language,
LanguageVersion languageVersionCSharp,
Microsoft.CodeAnalysis.VisualBasic.LanguageVersion languageVersionVB)
{
var fileNamePrefix = DefaultFilePathPrefix;
string fileExt;
ParseOptions parseOptions;
if (language == LanguageNames.CSharp)
{
fileExt = CSharpDefaultFileExt;
parseOptions = new CSharpParseOptions(languageVersionCSharp);
}
else
{
fileExt = VisualBasicDefaultExt;
parseOptions = new Microsoft.CodeAnalysis.VisualBasic.VisualBasicParseOptions(languageVersionVB);
}
var projectId = ProjectId.CreateNewId(debugName: TestProjectName);
#pragma warning disable CC0022
var workspace = new AdhocWorkspace();
#pragma warning restore CC0022
var projectInfo = ProjectInfo.Create(projectId, VersionStamp.Create(), TestProjectName,
TestProjectName, language,
parseOptions: parseOptions,
metadataReferences: ImmutableList.Create(
CorlibReference, SystemCoreReference, RegexReference,
CSharpSymbolsReference, CodeAnalysisReference, JsonNetReference));
workspace.AddProject(projectInfo);
var count = 0;
foreach (var source in sources)
{
var newFileName = fileNamePrefix + count + "." + fileExt;
workspace.AddDocument(projectId, newFileName, SourceText.From(source));
count++;
}
var project = workspace.CurrentSolution.GetProject(projectId);
var newCompilationOptions = project.CompilationOptions.WithSpecificDiagnosticOptions(diagOptions);
var newSolution = workspace.CurrentSolution.WithProjectCompilationOptions(projectId, newCompilationOptions);
var newProject = newSolution.GetProject(projectId);
return newProject;
}
示例8: GetDocuments
/// <summary>
/// Given an array of strings as soruces and a language, turn them into a project and return the documents and spans of it.
/// </summary>
/// <param name="sources">Classes in the form of strings</param>
/// <param name="language">The language the source code is in</param>
/// <param name="languageVersionCSharp">C# language version used for compiling the test project, required unless you inform the VB language version.</param>
/// <param name="languageVersionVB">VB language version used for compiling the test project, required unless you inform the C# language version.</param>
/// <returns>A Tuple containing the Documents produced from the sources and thier TextSpans if relevant</returns>
public static Document[] GetDocuments(string[] sources, string language, LanguageVersion languageVersionCSharp, Microsoft.CodeAnalysis.VisualBasic.LanguageVersion languageVersionVB)
{
if (language != LanguageNames.CSharp && language != LanguageNames.VisualBasic)
throw new ArgumentException("Unsupported Language");
for (int i = 0; i < sources.Length; i++)
{
var fileName = language == LanguageNames.CSharp ? nameof(Test) + i + ".cs" : nameof(Test) + i + ".vb";
}
var project = CreateProject(sources, language, languageVersionCSharp, languageVersionVB);
var documents = project.Documents.ToArray();
if (sources.Length != documents.Length)
{
throw new SystemException("Amount of sources did not match amount of Documents created");
}
return documents;
}
示例9: Reset
public static void Reset (bool full)
{
if (full)
root = null;
type_container_resolve_order = new ArrayList ();
EntryPoint = null;
Checked = false;
Unsafe = false;
StdLib = true;
StrongNameKeyFile = null;
StrongNameKeyContainer = null;
StrongNameDelaySign = false;
MainClass = null;
Target = Target.Exe;
TargetExt = ".exe";
#if GMCS_SOURCE
Platform = Platform.AnyCPU;
#endif
Version = LanguageVersion.Default;
Documentation = null;
impl_details_class = null;
helper_classes = null;
#if GMCS_SOURCE
MetadataCompatibilityVersion = MetadataVersion.v2;
#else
MetadataCompatibilityVersion = MetadataVersion.v1;
#endif
//
// Setup default defines
//
AllDefines = new ArrayList ();
AddConditional ("__MonoCS__");
}
示例10: Reset
public static void Reset (bool full)
{
if (!full)
return;
Checked = false;
Unsafe = false;
StdLib = true;
StrongNameKeyFile = null;
StrongNameKeyContainer = null;
StrongNameDelaySign = false;
MainClass = null;
OutputFile = null;
Target = Target.Exe;
SdkVersion = SdkVersion.v2;
TargetExt = ".exe";
Platform = Platform.AnyCPU;
Version = LanguageVersion.Default;
VerifyClsCompliance = true;
Optimize = true;
Encoding = Encoding.Default;
Documentation = null;
GenerateDebugInfo = false;
ParseOnly = false;
TokenizeOnly = false;
Win32IconFile = null;
Win32ResourceFile = null;
Resources = null;
LoadDefaultReferences = true;
AssemblyReferences = new List<string> ();
AssemblyReferencesAliases = new List<Tuple<string, string>> ();
Modules = new List<string> ();
ReferencesLookupPaths = new List<string> ();
StdLibRuntimeVersion = RuntimeVersion.v2;
//
// Setup default defines
//
AllDefines = new List<string> ();
AddConditional ("__MonoCS__");
}
示例11: CompilerSettings
public CompilerSettings ()
{
StdLib = true;
Target = Target.Exe;
TargetExt = ".exe";
Platform = Platform.AnyCPU;
Version = LanguageVersion.Default;
VerifyClsCompliance = true;
Optimize = true;
Encoding = Encoding.Default;
LoadDefaultReferences = true;
StdLibRuntimeVersion = RuntimeVersion.v4;
AssemblyReferences = new List<string> ();
AssemblyReferencesAliases = new List<Tuple<string, string>> ();
Modules = new List<string> ();
ReferencesLookupPaths = new List<string> ();
}
示例12: ParseOptions
//warnaserror[+|-]
//warnaserror[+|-]:<warn list>
//unsafe[+|-]
//warn:<n>
//nowarn:<warn list>
public ParseOptions(
CompatibilityMode compatibility = CompatibilityMode.None,
LanguageVersion languageVersion = CSharp.LanguageVersion.CSharp4,
IEnumerable<string> preprocessorSymbols = null,
bool suppressDocumentationCommentParse = false,
SourceCodeKind kind = SourceCodeKind.Regular)
{
if (!compatibility.IsValid())
{
throw new ArgumentOutOfRangeException("compatibility");
}
if (!languageVersion.IsValid())
{
throw new ArgumentOutOfRangeException("languageVersion");
}
if (!kind.IsValid())
{
throw new ArgumentOutOfRangeException("kind");
}
this.Compatibility = compatibility;
this.LanguageVersion = languageVersion;
this.PreprocessorSymbols = preprocessorSymbols.AsReadOnlyOrEmpty();
this.SuppressDocumentationCommentParse = suppressDocumentationCommentParse;
this.Kind = kind;
}
示例13: VerifyAsync
private async Task VerifyAsync(string codeWithMarker, string expectedResult, LanguageVersion langVersion = LanguageVersion.VisualBasic14)
{
var textSpans = (IList<TextSpan>)new List<TextSpan>();
MarkupTestFile.GetSpans(codeWithMarker, out var codeWithoutMarker, out textSpans);
var document = CreateDocument(codeWithoutMarker, LanguageNames.VisualBasic, langVersion);
var codeCleanups = CodeCleaner.GetDefaultProviders(document).Where(p => p.Name == PredefinedCodeCleanupProviderNames.RemoveUnnecessaryLineContinuation || p.Name == PredefinedCodeCleanupProviderNames.Format);
var cleanDocument = await CodeCleaner.CleanupAsync(document, textSpans[0], codeCleanups);
Assert.Equal(expectedResult, (await cleanDocument.GetSyntaxRootAsync()).ToFullString());
}
示例14: CreateDocument
private static Document CreateDocument(string code, string language, LanguageVersion langVersion)
{
var solution = new AdhocWorkspace().CurrentSolution;
var projectId = ProjectId.CreateNewId();
var project = solution
.AddProject(projectId, "Project", "Project.dll", language)
.GetProject(projectId);
var parseOptions = (VisualBasicParseOptions)project.ParseOptions;
parseOptions = parseOptions.WithLanguageVersion(langVersion);
project = project.WithParseOptions(parseOptions);
return project.AddDocument("Document", SourceText.From(code));
}
示例15: VerifyCSharpFixAllAsync
protected async Task VerifyCSharpFixAllAsync(string oldSource, string newSource, bool allowNewCompilerDiagnostics = false, bool formatBeforeCompare = true, CodeFixProvider codeFixProvider = null, LanguageVersion languageVersionCSharp = LanguageVersion.CSharp6, string equivalenceKey = null)
{
if (formatBeforeCompare)
{
oldSource = await FormatSourceAsync(LanguageNames.CSharp, oldSource, languageVersionCSharp).ConfigureAwait(true);
newSource = await FormatSourceAsync(LanguageNames.CSharp, newSource, languageVersionCSharp).ConfigureAwait(true);
}
codeFixProvider = codeFixProvider ?? GetCodeFixProvider();
await VerifyFixAllAsync(LanguageNames.CSharp, GetDiagnosticAnalyzer(), codeFixProvider, oldSource, newSource, allowNewCompilerDiagnostics, languageVersionCSharp, Microsoft.CodeAnalysis.VisualBasic.LanguageVersion.VisualBasic14, equivalenceKey).ConfigureAwait(true);
}