roslyn

How to find type of the field with specific name in Roslyn

馋奶兔 提交于 2020-01-02 07:27:30
问题 Need to find TypeSyntax or essentially Type of a specific filed in class by using Roslyn. Something like this: rootSyntaxNode .DescendantNodes() .OfType<FieldDeclarationSyntax>() .First(x => x.Identifier="fieldName") .GivemeTypeSyntax() But could not get any hint about how to reach Identifier and SyntaxType in FieldDeclarationSyntax node. Any idea please? 回答1: Part of the issue is that fields can contain multiple variables. You'll look at Declaration for type and Variables for identifiers. I

MvcBuildViews in MS2015 takes a long time

我的未来我决定 提交于 2020-01-02 03:41:09
问题 We are converting a solution to use the new Roslyn compiler. When I build it via teamCity in release mode, the MVCBuildViews step still uses aspnet_compiler.exe and it takes about 15 minutes to precompile views. The same process used to take 3 minutes using the previous version of aspnet_compiler.exe on .NET 4.5 This is the command that takes a while: C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_compiler.exe -v temp -p E:\path\to\web\project\Directory I have tried tweaking the MSBuild

Get Symbol for ReferenceLocation

夙愿已清 提交于 2020-01-01 12:15:10
问题 I'm using the SymbolFinder to find all references to a certain type in my solution like this: ISymbol typeOfInterest = compilation.GetTypeByMetadataName( "System.Reflection.PropertyInfo"); var references = SymbolFinder.FindReferencesAsync(typeOfInterest, solution).Result; foreach (var reference in references) { // reference.Locations => symbol? } This part is working fine, the SymbolFinder returns correct ReferenceLocations (upon manual inspection). I'm actually interested in the symbols at

Roslyn scripting: Line number information for run time exceptions

非 Y 不嫁゛ 提交于 2020-01-01 07:04:35
问题 I am messing around with the Roslyn scripting stuff (using the Microsoft.CodeAnalysis.CSharp.Scripting nuget package), and I wonder if there is a way to add line number information to the stack traces for exceptions that happen inside a script. When I run the following C# code: // using Microsoft.CodeAnalysis.CSharp.Scripting; var code = @" var a = 0; var b = 1 / a; "; try { await CSharpScript.RunAsync(code); } catch (DivideByZeroException dbze) { Console.WriteLine(dbze.StackTrace); } The

Understanding the various options for runtime code generation in C# (Roslyn, CodeDom, Linq Expressions, …?)

女生的网名这么多〃 提交于 2020-01-01 06:57:10
问题 I'm working on an application where I'd like to dynamically generate code for a numerical calculation (for performance). Doing this calculation as a data driven operation is too slow. To describe my requirements, consider this class: class Simulation { Dictionary<string, double> nodes; double t, dt; private void ProcessOneSample() { t += dt; // Expensive operation that computes the state of nodes at the current t. } public void Process(int N, IDictionary<string, double[]> Input, IDictionary

.net Core amd Roslyn CSharpCompilation, The type 'Object' is defined in an assembly that is not referenced

穿精又带淫゛_ 提交于 2020-01-01 04:14:26
问题 I'm trying to port some .net code to the new Core runtime and I'm having a bad time porting some on-the-fly compilation. To resume, it always asks me for a reference to System.Runtime and mscorlib, but have no clue on how to reference them. As a side note, I can't reference Framework 4.6 as the project must be published to a Linux machine with .net Core. This is the minimum code: string testClass = @"using System; namespace test{ public class tes { public string unescape(string Text) { return

Is there code generation API for TypeScript?

旧城冷巷雨未停 提交于 2020-01-01 02:07:26
问题 When I needed to generate some C# code, for example DTO classes from xsd schema, or an excel table, I've used some roslyn API's. Is there something simmilar for typescript? 回答1: as of Oct-2018 You could use standard TypeScript API for that import ts = require("typescript"); function makeFactorialFunction() { const functionName = ts.createIdentifier("factorial"); const paramName = ts.createIdentifier("n"); const parameter = ts.createParameter( /*decorators*/ undefined, /*modifiers*/ undefined,

Enums in lambda expressions are compiled differently; consequence of overload resolution improvements?

牧云@^-^@ 提交于 2019-12-31 08:32:12
问题 While trying out the Visual Studio 2015 RC, I received a run-time error on previously working code. Given the lambda (x => x.CustomerStatusID == CustomerStatuses.Active) which was passed to a function as an Expression<> , the debugger shows a difference in the expression tree. Formerly it compiled as this: .Lambda #Lambda1<System.Func`2[Services.DataClasses.CustomerDC,System.Boolean]>(Services.DataClasses.CustomerDC $x) { (System.Int32)$x.CustomerStatusID == 0 } But in C# 6.0 it now compiles

Enums in lambda expressions are compiled differently; consequence of overload resolution improvements?

删除回忆录丶 提交于 2019-12-31 08:31:54
问题 While trying out the Visual Studio 2015 RC, I received a run-time error on previously working code. Given the lambda (x => x.CustomerStatusID == CustomerStatuses.Active) which was passed to a function as an Expression<> , the debugger shows a difference in the expression tree. Formerly it compiled as this: .Lambda #Lambda1<System.Func`2[Services.DataClasses.CustomerDC,System.Boolean]>(Services.DataClasses.CustomerDC $x) { (System.Int32)$x.CustomerStatusID == 0 } But in C# 6.0 it now compiles

Roslyn workspace for .NET Core's new .csproj format

拥有回忆 提交于 2019-12-30 02:46:08
问题 I've been working on a VS Code extension that uses Roslyn's workspace API to load a project, at the moment the extension supports .NET Core's old project.json format via the ProjectJsonWorkspace type in the Microsoft.DotNet.ProjectModel.Workspaces package. With the new tooling changes being released soon I'm keen to support the new .csproj build format but can't appear to find a .NET Standard compliant workspace that supports it. My understanding is that as it's using MSBuild, I will need to