简体   繁体   中英

How to implement Intellisense to a Dynamic class in c#?

I'm trying to find a way to create a Dynamic Class with Intellisense. I have tried to follow the same instructions in this post Is it possible to provide intellisense for dynamic objects in visual studio? , perhaps I didn't succeed to do it. Impossible to implements the two Interfaces ICompletionSource and ICompletionSourceBuilder , they're unrecognized by Visual Studio version 2015.`

Bellow my code for the moment :

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.`

Because these two Interfaces ICompletionSource and ICompletionSourceBuilder belong to visual studio, you need to install visual studio SDK before you use the two interfaces https://msdn.microsoft.com/en-us/library/mt683786.aspx?f=255&MSPPError=-2147217396 .

Here is a sample about the usage ICompletionSource for your reference. https://msdn.microsoft.com/en-us/library/ee372314.aspx

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM