如何在 C# 中实现动态 class 的 Intellisense?
How to implement Intellisense to a Dynamic class in c#?
我正在尝试找到一种使用 Intellisense 创建动态 Class 的方法。我已尝试按照此 post Is it possible to provide intellisense for dynamic objects in visual studio? 中的相同说明进行操作,也许我没有成功。无法实现 ICompletionSource
和 ICompletionSourceBuilder
这两个接口,Visual Studio 2015 版无法识别它们。`
暂时使用我的代码:
namespace IntellisenseTest
{
class Program
{
static void Main(string[] args)
{
dynamic d = new DynamicDictionary();
d.test = "test";
Console.WriteLine(d.test);
Console.Read();
}
}
internal class DynamicDictionary : DynamicObject
{
Dictionary<string, object> dictionary
= new Dictionary<string, object>();
public override bool TryGetMember(
GetMemberBinder binder, out object result)
{
string name = binder.Name.ToLower();
return dictionary.TryGetValue(name, out result);
}
public override bool TrySetMember(
SetMemberBinder binder, object value)
{
dictionary[binder.Name.ToLower()] = value;
return true;
}
}
}
Impossible to implements the two Interfaces ICompletionSource and ICompletionSourceBuilder, they're unrecognized by Visual Studio version 2015.`
因为ICompletionSource和ICompletionSourceBuilder这两个接口属于visual studio,所以在使用https://msdn.microsoft.com/en-us/library/mt683786.aspx?f=255&MSPPError=-2147217396.
这两个接口之前需要先安装visual studioSDK
这里有一个ICompletionSource的使用示例,供大家参考。 https://msdn.microsoft.com/en-us/library/ee372314.aspx
我正在尝试找到一种使用 Intellisense 创建动态 Class 的方法。我已尝试按照此 post Is it possible to provide intellisense for dynamic objects in visual studio? 中的相同说明进行操作,也许我没有成功。无法实现 ICompletionSource
和 ICompletionSourceBuilder
这两个接口,Visual Studio 2015 版无法识别它们。`
暂时使用我的代码:
namespace IntellisenseTest
{
class Program
{
static void Main(string[] args)
{
dynamic d = new DynamicDictionary();
d.test = "test";
Console.WriteLine(d.test);
Console.Read();
}
}
internal class DynamicDictionary : DynamicObject
{
Dictionary<string, object> dictionary
= new Dictionary<string, object>();
public override bool TryGetMember(
GetMemberBinder binder, out object result)
{
string name = binder.Name.ToLower();
return dictionary.TryGetValue(name, out result);
}
public override bool TrySetMember(
SetMemberBinder binder, object value)
{
dictionary[binder.Name.ToLower()] = value;
return true;
}
}
}
Impossible to implements the two Interfaces ICompletionSource and ICompletionSourceBuilder, they're unrecognized by Visual Studio version 2015.`
因为ICompletionSource和ICompletionSourceBuilder这两个接口属于visual studio,所以在使用https://msdn.microsoft.com/en-us/library/mt683786.aspx?f=255&MSPPError=-2147217396.
这两个接口之前需要先安装visual studioSDK这里有一个ICompletionSource的使用示例,供大家参考。 https://msdn.microsoft.com/en-us/library/ee372314.aspx