Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/280.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Intellisense无法从扩展方法推断类型_C#_.net_Visual Studio_Intellisense - Fatal编程技术网

C# Intellisense无法从扩展方法推断类型

C# Intellisense无法从扩展方法推断类型,c#,.net,visual-studio,intellisense,C#,.net,Visual Studio,Intellisense,下面的示例编译成功。 编译器可以推断e(客户)的类型 我的问题是为什么Intellisense不能做同样的事情? 当我键入customer.SetValue(时,它正确地显示了方法所期望的 Expression<Func<Customer, TProperty>> 表达式 但当我输入e=>e.时,它无法理解e是客户 这是预期的还是错误? using System; using System.Linq.Expressions; using System.Reflect

下面的示例编译成功。
编译器可以推断e(客户)的类型
我的问题是为什么Intellisense不能做同样的事情?
当我键入customer.SetValue(时,它正确地显示了方法所期望的

 Expression<Func<Customer, TProperty>>
表达式
但当我输入e=>e.时,它无法理解e是客户

这是预期的还是错误?

using System;
using System.Linq.Expressions;
using System.Reflection;

namespace ConsoleApplicationExpressionTree
{
    class Program
    {
        static void Main(string[] args)
        {
            Customer customer = new Customer();
            customer.SetValue(e => e.Age, 10);
            customer.SetValue(e => e.Name, "TheName");
            //type here
         }
     }

     public static class Extentions
     {
        public static void SetValue<TEntity, TProperty>(this TEntity instance, Expression<Func<TEntity, TProperty>> expression, TProperty newValue)
        {
            if (instance == null)
                throw new ArgumentNullException();

            var memberExpression = (MemberExpression)expression.Body;
            var property = (PropertyInfo)memberExpression.Member;

            property.SetValue(instance, newValue, null);
        }
    } 
    public class Customer
    {
        public string Name { get; set; }
         public int Age { get; set; }
    }
}
使用系统;
使用System.Linq.Expressions;
运用系统反思;
命名空间控制台应用程序表达式树
{
班级计划
{
静态void Main(字符串[]参数)
{
客户=新客户();
设置值(e=>e.年龄,10岁);
customer.SetValue(e=>e.Name,“TheName”);
//在这里输入
}
}
公共静态类扩展
{
公共静态void SetValue(此tenty实例、表达式、TProperty newValue)
{
if(实例==null)
抛出新ArgumentNullException();
var memberExpression=(memberExpression)expression.Body;
var property=(PropertyInfo)memberExpression.Member;
SetValue(实例,newValue,null);
}
} 
公共类客户
{
公共字符串名称{get;set;}
公共整数{get;set;}
}
}
我使用的是VS 2015、.NET 4.6.1

更新
它与表达式无关,方法可以更改为

public static void SetValue<TEntity, TProperty>(this TEntity instance, Func<TEntity, TProperty> expression, TProperty newValue)
publicstaticvoidsetvalue(此tenty实例、Func表达式、TProperty newValue)
更新2
我可以用计算机复制它

  • VS 2015企业版
  • VS 2015社区版
它似乎正在运行(尚未测试其他版本)

  • VS 2013终极版
  • VS 2013年保费
这是预期的还是一个bug

这两者都不是真的

虽然智能感知有助于尽可能多地帮助你,但它从未声称要正确解析代码中的每个声明。这在传统上是C++和复杂的基于宏的声明的一个问题,但是你也会在C语言中遇到问题。
如果你愿意,你可以就此提出一个连接问题,但除此之外,这是一个你可以很容易接受的问题,因此不要期待太快的响应(想想2017年,而不是2015年更新2).

我已经在

上提交了一份错误报告,我已经有过几次这样的情况发生,大约每隔一周发生一次。关闭和重新打开VS通常会为我修复它,但它仍然让人恼火。我确定省略了一些代码以保持问题的小型化,但我可以问扩展的目的是什么来设置属性吗?看起来像是个错误,可能是需要解决的问题和Roslyn一起去。@Wobbles,不,这是完整的example@JRLambert我已经重新启动了我的VS/PC,但我一直都有这个问题。我会打开一个bug报告感谢@Blindy的回答,但由于它在以前的版本中工作,我认为这是一个bug