roslyn

Roslyn: Convert C# to VB

别等时光非礼了梦想. 提交于 2020-01-13 03:34:12
问题 I have the case wherein I need to convert a C#- to a VB.NET project. (I want to automate this, so I cannot use an online tool or something similar) There is a "Paste as C#/VB" sample visual studio extension which seemed to be able to do this. I tried converting this class: namespace TestApplication { class Class1 { /// <summary> /// Lorem /// </summary> public void Lorem() { } } } But it ended up with this: Namespace TestApplication Class Class1 ''' <summary> Lorem </summary> Public Sub Lorem

Run Roslyn Code Analyzers on Build Server

邮差的信 提交于 2020-01-12 18:34:33
问题 I'm trying to create custom static analysis rules against my code base such that compiler errors will be generated if a developer fails to follow my companies coding convention. It seems with Visual Studio 2015, Roslyn Code Analyzers are the way to accomplish this. The MSDN articles I've read indicate Code Analyzers are packaged up as NuGet or VSIX packages. That's great for adding red squiggles in Visual Studio, but I want to make sure the compiler errors are also generated on my Jenkins

C# Static Analysis, possible values for a variable/parameter

拥有回忆 提交于 2020-01-12 03:24:07
问题 In code similar to each of the following examples, I would like to be able to statically analyze code to determine the list of possible values that are passed into SpecialFunction(). SpecialFunction(5); // A int x = 5; SpecialFunction(x); // B int x = 5; x = condition ? 3 : 19; SpecialFunction(x); // C I can already parse the C# into an abstract syntax tree and I can already handle cases like A, and I guess I could keep track of initial assignments of values to guess case B, but cases as easy

In which language is the C# compiler written?

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-11 14:48:50
问题 I looked at the source code at http://referencesource.microsoft.com/, and it appears all the source code is in C#. I also looked at the source code for the new C# compiler platform (Roslyn), and it is also in C#. How is that possible? Is C# language compiler written in C#? Or am I missing something obvious? If C# compiler is written in C# then how does it work? 回答1: The original C# compiler wasn't written in C#, it was in C and C++. The new Roslyn compiler was written in C#, but was initially

Asp.net MVC Razor view - CS1525: Invalid expression term '.'

六月ゝ 毕业季﹏ 提交于 2020-01-11 04:47:05
问题 I have two identical ASP.Net 4.6 MVC project, project 1 is using roslyn complier within the site which is working fine. c:\windows\system32\inetsrv>C:\Websites1\bin\roslyn\csc.exe Microsoft (R) Visual C# Compiler version 1.2.0.60325 With the second project I'm getting the error below, it's using the complier from .Net framework. c:\windows\system32\inetsrv> "C:\Windows\Microsoft.NET\Framework64\v4.0.30319\csc.exe" Microsoft (R) Visual C# Compiler version 4.6.1590.0 Line 6: @if (!Model?.Item?

How to get a Roslyn FieldSymbol from a FieldDeclarationSyntax node?

孤人 提交于 2020-01-09 05:20:49
问题 I'm trying to use Roslyn to determine the publically-exposed API of a project (and then do some further processing using this information, so I can't just use reflection). I'm using a SyntaxWalker to visit declaration syntax nodes, and calling IModel.GetDeclaredSymbol for each. This seems to work well for Methods, Properties, and Types, but it doesn't seem to work on fields. My question is, how do I get the FieldSymbol for a FieldDeclarationSyntax node? Here's the code I'm working with:

How can I obtain return type from method passed as an argument in another method with Roslyn?

好久不见. 提交于 2020-01-06 04:50:08
问题 Lets say that I have a code: public class Test { private readonly IFactory _factory; private readonly ISomeClass _someClass; public Test(IFactory factory, ISomeClass someClass) { _factory = factory; _someClass = someClass; } .... public void TestMethod() { _someClass.Do(_factory.CreateSomeObject()); } } public class Factory { public SomeObject CreateSomeObject() { return new SomeObject(); } } public class SomeClass { public void Do(SomeObject obj){ .... } } I would like to get return type of

Getting the System.Type from an assembly loaded at runtime

夙愿已清 提交于 2020-01-06 03:30:13
问题 As a followup to this question I have now come to the problem of being able to get the Type of a type that is defined by the user in his own solution. Using the standard mscorlib types, everything works. The question is very easy: how can I get this type from an assembly that I will only know at runtime? As described in the comments here: Also, what do you mean by "extracting the type"? You mean getting the Reflection type? There's no good helper, partly because (typically) you can never

Getting the System.Type from an assembly loaded at runtime

大兔子大兔子 提交于 2020-01-06 03:30:04
问题 As a followup to this question I have now come to the problem of being able to get the Type of a type that is defined by the user in his own solution. Using the standard mscorlib types, everything works. The question is very easy: how can I get this type from an assembly that I will only know at runtime? As described in the comments here: Also, what do you mean by "extracting the type"? You mean getting the Reflection type? There's no good helper, partly because (typically) you can never

TextTransform on MSBuild only when file modified? (or an alternate route of doing this)

无人久伴 提交于 2020-01-05 13:09:31
问题 I have a project that integrates TextTransform with MSBuild, but I am now at the point that the files are too many and it is slowing down development time. The process that I have is, I have a POCO.cs; I use Roslyn to Parse the .cs file to gather some metadata; hand the metadata to a .tt file that will then generate a [Implementation].cs Here is part of the .csproj file that pertains to my question: <PropertyGroup> <_CommonProgramFiles>$([System.Environment]::GetEnvironmentVariable(