小编g.p*_*dou的帖子

如何使用Roslyn(Microsoft CodeAnalysis)获取范围内的所有可见局部变量名称

(请注意:这不是关于运行时反射/ metainfo)

我正在编写Roslyn CSharpSyntaxVisitor的具体实现

实现VisitIdentifierName时

public override SyntaxNode VisitIdentifierName(IdentifierNameSyntax name)
{
   var symbolInfo = _semanticModel.GetSymbolInfo(name);
   var fieldSymbol = symbolInfo.Symbol as IFieldSymbol;
   if (fieldSymbol != null)
   {
       // Here I would like to get all the local variable names what are visible
       // in the very same scope where this field IdentifierNameSyntax under visiting resides
       // We can suppose that _semanticNodel for the Document is available.
   }
}
Run Code Online (Sandbox Code Playgroud)

c# roslyn

4
推荐指数
1
解决办法
1738
查看次数

How to configure Roslyn CustomWorkSpace not to cry for Visual Basic?

I have a simple Roslyn code line as follows:

var workspace = new CustomWorkspace();
Run Code Online (Sandbox Code Playgroud)

This line throws (and handles internally) the exception like:

"Could not load file or assembly 'Microsoft.CodeAnalysis.VisualBasic.Workspaces, Version=0.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified."

Please note the exception is only visible if you run the code in debugger, and configured the VS to show not only the unhandled exception.

I would not like to use Visual Basic features at …

c# roslyn

4
推荐指数
1
解决办法
1340
查看次数

C#编译器:CS0121:以下方法或属性之间的调用不明确

这是我见过的最疯狂的事情,因为Fody插件通过发出无效代码来破坏我的程序集并且控制流在运行时随机变化......这次没有Fody.

事实:

  • 整个故事都在一个项目中.
  • GetMessage扩展方法已经存在几周了......
  • 问题从2个小时开始,我无法弄清楚它是什么.
  • 只有一个GetMessage扩展方法.
  • 错误消息(参见图片)列出了两个相同的方法规范

    Error CS0121 The call is ambiguous between the following methods or properties: 'ComiCalc.Data.ExceptionExtensions.GetMessage2(System.Exception)' and 'ComiCalc.Data.ExceptionExtensions.GetMessage2(System.Exception)' ComiCalc.Data D:\2014Develop\.vsonline\ComiCalc\src\ComiCalc.Data\Services\UserService.cs 61

  • 如果我同时将方法定义(在2个位置只编辑了2个)更改为GetMessage2,那么我只是引用了GetMessage2的完全相同的错误消息.

  • 使用VS 2015

有任何想法吗?

在此输入图像描述

这是单一的方法:

namespace ComiCalc.Data
{

    using System;
    using System.Data.Entity.Validation;
    using PluralTouch.DataAccess;
    // TODO: Move to PluralTouch
    public static class ExceptionExtensions
    {
        public static string GetMessage2(this Exception exception)
        {

            var message = exception.Message;
            if (exception is DbEntityValidationException)
            {
                message = ((DbEntityValidationException) exception).DbEntityValidationResultToString();
            }
            return message;
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

c#

4
推荐指数
2
解决办法
1万
查看次数

试用帐户中的 Twilio SMS 前缀

我正在尝试使用 Twilio Java API 发送消息。使用试用帐户,我看到我的消息中添加了前缀。

可以删除/修改此前缀“从您的 Twilio 试用帐户发送”吗?

sms message prefix twilio

4
推荐指数
1
解决办法
3460
查看次数

NuGet TypeScript工具:为什么仍无法使用添加的Typescript编译器版本?

语境

我正在使用VS 2017.3。刚创建一个ASP MVC项目,然后添加了两个nuget包,

  • Microsoft.TypeScript.Compiler v2.5.3
  • Microsoft.TypeScript.MSBuild v2.5.3

尝试配置打字稿版本时,我发现TypeScript版本2.5不可用。

我想念什么?我以为添加这些nuget软件包将使项目(和构建)独立于开发机器的安装状态...

到目前为止我尝试过的

  • 卸载,重新加载项目
  • 退出VS,
  • 重新启动VS构建项目

在此处输入图片说明

在此处输入图片说明

msbuild visual-studio nuget typescript visual-studio-2017

4
推荐指数
1
解决办法
678
查看次数

如何在 PowerShell 中将哈希字符串转换为字节数组?

当我的脚本运行时,我读取了一个哈希值,我想将它写入注册表。我发现以下命令可以做到:

New-ItemProperty  $RegPath -Name $AttrName -PropertyType Binary -Value $byteArray
Run Code Online (Sandbox Code Playgroud)

我还找到了如何使用 PowerShell 设置二进制注册表值 (REG_BINARY)?.

但是,所有答案都假设字符串的形式为:

"50,33,01,00,00,00,00,00,...."
Run Code Online (Sandbox Code Playgroud)

但我只能以以下形式读取我的哈希:

"F5442930B1778ED31A....."
Run Code Online (Sandbox Code Playgroud)

我不知道如何将其转换为字节数组,其值为 F5、44 等。

registry powershell

4
推荐指数
1
解决办法
4972
查看次数

是否可以使用.NET Core更改.cshtml视图并立即查看更改?

语境

在我的NET Framework 4.x ASP MVC项目中,使用IDE时,可以编辑.cshtml视图,然后保存,然后在浏览器中按ctrl + F5并查看实际更改。

它似乎在.NET Core中不起作用(使用VS 2019和.NET Core 3 Preview 5)

.NET Core是否缺少此功能,或者是预览问题,还是我缺少某些功能?

razor asp.net-core asp.net-core-3.0

4
推荐指数
2
解决办法
262
查看次数

使用 AD B2C 时如何添加 OnTokenValidated 事件处理程序?

我在 ASP.NET Core 3 应用程序中使用 Azure B2C,它运行良好。我在启动中使用以下代码:

services.AddAuthentication(AzureADB2CDefaults.AuthenticationScheme)
    .AddAzureADB2C(options => Configuration.Bind("AzureAdB2C", options));
Run Code Online (Sandbox Code Playgroud)

我想处理标准的 TokenValidated OpenIdConnect 事件,换句话说,我需要一个配置来设置我的事件处理程序。

检查源代码,我看到了该类AzureAdB2COpenIDConnectEventHandlers.cs及其用法,AzureADB2COpenIdConnectOptionsConfiguration但不幸的是,两个类都声明为internal

我所需要的只是让我的 TokenValidated 处理程序生效,保留所有现成的基于 OpenIdConnect 的 AD B2C 功能,该功能目前正在运行。

伪代码,类似这样:

options.Events = new OpenIdConnectEvents()
{
     // ...
     OnTokenValidated = MyTokenValidatedHandler
};
Run Code Online (Sandbox Code Playgroud)

如何以简单的方式完成此操作?

openid-connect azure-ad-b2c asp.net-core

4
推荐指数
1
解决办法
789
查看次数

Blazor 服务器应用程序中的 HttpContext.Session

我正在尝试HttpContext.Session在我的 ASP.NET Core Blazor Server 应用程序中使用(如本MS Doc 中所述,我的意思是:在启动时全部正确设置)

这是我尝试设置值时的代码部分:

var session = _contextAccessor.HttpContext?.Session;
if (session != null && session.IsAvailable)
{
    session.Set(key, data);
    await session.CommitAsync();
}
Run Code Online (Sandbox Code Playgroud)

当这个代码在剃刀称为组件OnAfterRenderAsyncsession.Set抛出以下异常:

响应开始后无法建立会话。

我(可能)理解该消息,但这使得 Session 基础设施非常不可用:应用程序需要在执行的每个阶段访问其状态......

我应该完全忘记DistributedSession基础设施,而去使用 Cookies 或浏览器 SessionStorage 吗?...或者这里是否有解决方法仍在使用HttpContext.Session?我不想只是为了较低级别的实现而放弃分布式会话基础设施......

(仅供参考:浏览器的会话存储不是跨选项卡,这很痛苦)

session httpcontext asp.net-core blazor-server-side

4
推荐指数
1
解决办法
2934
查看次数

如何克隆conda环境,除了conda包之外还有pip包?

语境

我正在尝试将我的开发 conda 环境克隆到测试服务器。在这个环境中,除了许多 conda 软件包之外,我还必须通过pip. 我正在使用迷你康达。

我尝试过的:

conda list --explicit > spec-file.txt
Run Code Online (Sandbox Code Playgroud)

然后

conda create --name myclonedenv --file spec-file.txt
Run Code Online (Sandbox Code Playgroud)

pip然而,这并没有安装在原始 conda 环境中安装的几个软件包。

问题

如果当前 conda 环境包含通过安装的一些软件包,如何导出当前 conda 环境并将其克隆到另一台计算机上pip

import clone export pip conda

4
推荐指数
1
解决办法
3641
查看次数