roslyn

Get exported semantic model for MetadataReference

孤街浪徒 提交于 2019-12-06 05:58:04
问题 Is it possible to get a collection of ITypeSymbol's for the types exported by an assembly that's been added to a compilation as a MetadataReference? I want to inspect the types available to the referencing project. 回答1: Call Compilation.GetAssemblyOrModuleSymbol() for each MetadataReference, cast to IAssemblySymbol , then look at the TypeNames property (which returns strings). To get the actual ITypeSymbol s for each type, fetch the assembly's GlobalNamespace , then recursively crawl through

Is there a way to setup a working directory for “r and ”load commands

て烟熏妆下的殇ゞ 提交于 2019-12-06 05:57:54
Quesiton is relative to References in Roslyn .rsp files Did install the Roslyn, playing with: C:\Users\name\Documents\Microsoft Codename Roslyn CTP - October 2011\CSharp\WpfSeedRepl Walkthrough: http://msdn.microsoft.com/ru-ru/hh543924 . I'm unable to load current DLL and csx: > #r "wpfseed.exe" (1,1): error CS0006: Metadata file 'wpfseed.exe' could not be found > #load "setup.csx" Specified file not found. Searched in directory: C:\Users\name > On other hand: > Console.WriteLine(Environment.CurrentDirectory); C:\Users\name\Documents\Microsoft Codename Roslyn CTP - October 2011\CSharp

How to see if a class has implemented the interface with Roslyn

徘徊边缘 提交于 2019-12-06 05:51:46
问题 I'm still new at Roslyn , so hopefully this isn't too stupid of a question. What I'm looking for is a way to see if a class has implemented all the methods of an interface and if not, the highlight the interface, just like the built in "Implement interface" does. So far I can see if the method name is implemented, but I haven't found a way to see if the right returntype is set on the method. 回答1: You can use ITypeSymbol.FindImplementationForInterfaceMember for this purpose. Basically what you

Unable to get method SyntaxTree.ParseFile in new nuget of Roslyn?

感情迁移 提交于 2019-12-06 04:51:50
问题 I have installed nuget for Roslyn with Install-Package Microsoft.CodeAnalysis -Pre but i'm still unable to get the method SyntaxTree.ParseFile as I want to pass code in a .cs file Any clue about why is it so ? How can I pass file here? 回答1: The API simply changed a little bit, one way to do it is : var path = @"C:\...\SomeFile.cs"; using(var stream = File.OpenRead(path)) { var syntaxTree = CSharpSyntaxTree.ParseText(SourceText.From(stream), path: path); } 来源: https://stackoverflow.com

`Add-Type` C# 6+ features throwing errors

杀马特。学长 韩版系。学妹 提交于 2019-12-06 04:39:12
I am trying to compile c# source code in powershell by using this command: Add-Type -ReferencedAssemblies $assemblies -TypeDefinition $source But c#-6.0 features are not working, for example: Add-Type : c:\Users\...\AppData\Local\Temp\2\d2q5hn5b.0.cs(101) : Unexpected character '$' For code: new Problem($"... ({identifier})", node) I am using powershell-v5.1 Is there a way to fix this? Patrick Hofman Powershell uses CodeDomProvider to compile their assemblies. The version provided with the framework just supports C# 5, so no new features are available by default. However, if you provide

.NET Roslyn : runtime configuration

筅森魡賤 提交于 2019-12-06 04:39:04
I am going to develop some rules with the Roslyn code analyzer. This rule is to control the access of a namespace. Example, the DAL can use only the core. If the View use the DAL, I want a warning. I use the template "Analyzer with Code Fix (NuGet + VSIX)" in 'Visual Studio 2015 Community Edition' to generate the plugin. I have made some test and it works fine. However the rule is written at hard in the code. I don't know how configure the rule in the runtime. The best will be a configuration file in the solution or the project. Can you give me some example? Thank. Resume of solution : Add the

Roslyn, passing values through hostObject

你离开我真会死。 提交于 2019-12-06 04:13:01
问题 I am trying to send one class through hostObject but apparently it doesn't want to work: using Roslyn.Compilers; using Roslyn.Compilers.CSharp; using Roslyn.Scripting; using Roslyn.Scripting.CSharp; public class ShippingService { public class ShippingDetails//class that I want to send { public decimal total { get; set; } public int quantity { get; set; } public string destination { get; set; } } public static string ShipingCost(decimal total, int quantity, string destination) { var details =

Getting node from line number in Roslyn

筅森魡賤 提交于 2019-12-06 03:58:17
问题 How can I get a SyntaxNode based on a line number? Else if its possible to get LineSpan of that line number then to node. 回答1: You can get the span of a line from the document text. From there, you can find all nodes that intersect with the span of the line. This will return multiple syntax nodes, which you can then use your criteria to pull out the one you are looking for: static void Main(string[] args) { var code = @" using System; namespace ConsoleApplication1 { class TypeName { public

Retrieve all Types with Roslyn within a solution

元气小坏坏 提交于 2019-12-06 03:38:06
Does anyone know how to retrieve all available types (the semantic) within a solution? The creation of the compilation out of several projects is easy. MSBuildWorkspace workspace = MSBuildWorkspace.Create(); var solution = await workspace.OpenSolutionAsync(solutionPath, cancellationToken); var compilations = await Task.WhenAll(solution.Projects.Select(x => x.GetCompilationAsync(cancellationToken))); Just iterating over all ClassDeclarations is not enough for me because I want all types and the connection between them. foreach (var tree in compilation.SyntaxTrees) { var source = tree.GetRoot

Roslyn embedd content into assembly

徘徊边缘 提交于 2019-12-06 03:18:52
Is it possiblem to embedd content into an assembly using roslyn? Embedding resources works great, but can't figure out how to add content. I add resources like this: foreach (string file in Directory.GetFiles(inputPath).Where(item => item.EndsWith(".xaml"))) { var resourceDescription = new ResourceDescription( Path.GetFileName(file.ToLower()), () => File.OpenRead(file.ToLower()), true); resourceDescriptions.Add(resourceDescription); } And than pass it when emitting: EmitResult result = compilation.Emit(ms, manifestResources: resourceDescriptions.ToArray()); But I don't now to add other type of