Get namespace in a Code Snippet

99封情书 提交于 2019-12-03 16:38:38

Found out that it can be done and it brings into picture the classes ExpansionProvider & ExpansionFunction

For the above snippet, I had to do something as such:

internal class NameSpaceExpansionFunction : ExpansionFunction
    {
        public NameSpaceExpansionFunction(ExpansionProvider provider)
            : base(provider)
        {
        }

        public override string GetCurrentValue()
        {
           //get namespace
           return namespace;
        }
    }

And the LanguageService tells the snippet file where to look for definition of the function:

public class MyLanguageService : LanguageService
    {
        public override ExpansionFunction CreateExpansionFunction(ExpansionProvider provider,
                                                                  string functionName)
        {
            ExpansionFunction function = null;
            if (String.Compare(functionName, "NameSpace", true) == 0)
            {
                function = new NameSpaceExpansionFunction(provider);
            }
            return function;
        }
    }

This turned out to be more like a tutorial question hence I have provided the links above. Should be helpful. Worked for me :)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!