roslyn

Roslyn VisualBasic.ScriptEngine doesnt recognize hostObject written on C#

只谈情不闲聊 提交于 2019-12-22 08:37:56
问题 Our project need ability to have a simple business rules our customers can script in Visual basic. While our main program is written on C# The script which customers want to execut could be like this (I am considering the simpliest possible case) var vbCode = @" If (Row.Code = 12) Then Row.MappedCode = 1 End If"; So I created a RowData class in C# with Code and MappedCode properties namespace ScriptModel { public class RowData { public int Code { get; set; } public int MappedCode { get; set;

Is it possible to use Rosyln or Resharper to detect possible DivideByZero cases?

北城余情 提交于 2019-12-22 08:35:12
问题 I'm trying to determine if there's a programmatic way to check for possible DivideByZeroException in my codebase. My codebase includes a series of relatively simple to relatively complex formulas, approximately 1500 of them (and growing). When new formulas are written, care must be taken to ensure that division is done safely to avoid exceptions during processing of these formulas. E.g. decimal val1 = 1.1m; decimal val2 = 0m; var res = val1/val2; //bad var res = val2 == 0 ? 0 : val1/val2; /

Visual Studio 2017 not highlighting errors

安稳与你 提交于 2019-12-22 08:26:08
问题 I recently upgraded from Visual Studio 2012 to 2017 (updated to version 15.3.5) and have some issues with the IDE. In a certain project, I don't get error underlining. and in the Error List pane, "Build Only" actually shows more information than "Build + IntelliSense" Also, with "Build + IntelliSense" selected, I can only see the compiler error in the Output window. Here is the error list after a failed build but the output window has this: 3>------ Build started: Project: ..., Configuration:

Generating well-formatted syntax with Roslyn

你离开我真会死。 提交于 2019-12-22 06:55:52
问题 I am using Roslyn to modify the syntax of C# files. Using CSharpSyntaxRewriter, it is very easy to find and replace nodes in the syntax tree. However, the generated code is very ugly and won't even parse in all cases because the syntax nodes I create (using SyntaxFactory) lack even a minimal amount of whitespace trivia. Does Roslyn provide some basic formatting functionality to avoid this or do I have to add trivia manually to each node I create? 回答1: Yes - it is possible, using Microsoft

Where to find Roslyn Project Templates for VS 2015?

天涯浪子 提交于 2019-12-22 06:49:30
问题 I found this question but the accepted answer provide two no working links. If you click on them you will see something like: This item is not yet published. If you are the owner of this project, please sign in with the appropriate account. So my question is. Where to find the installers for Roslyn Project Templates for VS 2015? 回答1: I believe you're looking for the .Net Compiler Platform SDK: https://visualstudiogallery.msdn.microsoft.com/2ddb7240-5249-4c8c-969e-5d05823bcb89 You may also

Generate C# code with Roslyn and .NET Core

一笑奈何 提交于 2019-12-22 05:42:15
问题 Is there a way to generate C# code using Roslyn with .NET Core. I've tried using the SyntaxFactory from the package Microsoft.CodeAnalysis.CSharp. The problem I'm currently stuck with is getting proper formatted code as text from it. All the samples I've seen so far use something like var ws = new CustomWorkspace(); ws.Options.WithChangedOption (CSharpFormattingOptions.IndentBraces, true); var code = Formatter.Format (item, ws); The problem here is, that they all use the package Microsoft

How do I programmatically add an assembly reference to a project?

自闭症网瘾萝莉.ら 提交于 2019-12-22 04:55:11
问题 I have been trying to use Roslyn to parse a solution file and programmatically add a custom assembly reference to each project in the solution. I tried using the following code snippet to do the same: //The name of the DLL is customLib.dll var reference = MetadataReference.CreateAssemblyReference("customLib"); project = project.AddMetadataReference(reference); However, it encounters a FileNotFoundException while creating the MetadataReference. So, my question is : How do I specify the path at

call instead of callvirt in case of the new c# 6 “?” null check

微笑、不失礼 提交于 2019-12-22 03:16:07
问题 Given the two methods: static void M1(Person p) { if (p != null) { var p1 = p.Name; } } static void M2(Person p) { var p1 = p?.Name; } Why the M1 IL code use callvirt : IL_0007: brfalse.s IL_0012 IL_0009: nop IL_000a: ldarg.0 IL_000b: callvirt instance string ConsoleApplication4.Person::get_Name() and the M2 IL use call : brtrue.s IL_0007 IL_0004: ldnull IL_0005: br.s IL_000d IL_0007: ldarg.0 IL_0008: call instance string ConsoleApplication4.Person::get_Name() I just can guess that it because

call instead of callvirt in case of the new c# 6 “?” null check

孤人 提交于 2019-12-22 03:16:01
问题 Given the two methods: static void M1(Person p) { if (p != null) { var p1 = p.Name; } } static void M2(Person p) { var p1 = p?.Name; } Why the M1 IL code use callvirt : IL_0007: brfalse.s IL_0012 IL_0009: nop IL_000a: ldarg.0 IL_000b: callvirt instance string ConsoleApplication4.Person::get_Name() and the M2 IL use call : brtrue.s IL_0007 IL_0004: ldnull IL_0005: br.s IL_000d IL_0007: ldarg.0 IL_0008: call instance string ConsoleApplication4.Person::get_Name() I just can guess that it because

What is the experimental feature “indexed members”?

杀马特。学长 韩版系。学妹 提交于 2019-12-22 02:00:13
问题 On the new Roslyn Preview site it mentions being able to try out potential language features, and lists three such features. The first two I've heard of before (for example here), but I can't figure out from the code sample what "indexed members" are. Can anyone explain what these are, either based on another source or the code sample? (It's worth nothing $x is not a valid identifier in C# 5.) UPDATE - According to the Roslyn Feature Status page, this feature has been withdrawn. 回答1: .$foobar