コード例 #1
0
        string GetTextWithDirective(MonoDevelop.Ide.Gui.Document document, bool insertDirective)
        {
            string tag = Text;

            if (!tag.Contains("{0}"))
            {
                return(tag);
            }

            if (Type.AssemblyName.StartsWith("System.Web.UI.WebControls", StringComparison.Ordinal))
            {
                return(string.Format(tag, "asp"));
            }

            //register the assembly and look up the class
            //FIXME: only do this on the insert, not the preview - or remove it afterwards
            RegisterReference(document.Project);

            var database = document.GetCompilationAsync().Result;

            var cls = database.GetTypeByMetadataName(Type.Load().FullName);

            if (cls == null)
            {
                return(tag);
            }

            var ed = document.GetContent <WebFormsEditorExtension> ();

            if (ed == null)
            {
                return(tag);
            }

            var assemName = SystemAssemblyService.ParseAssemblyName(Type.AssemblyName);

            WebFormsPageInfo.RegisterDirective directive;
            string prefix = ed.ReferenceManager.GetTagPrefixWithNewDirective(cls, assemName.Name, null, out directive);

            if (prefix == null)
            {
                return(tag);
            }

            tag = string.Format(tag, prefix);

            if (directive != null && insertDirective)
            {
                ed.ReferenceManager.AddRegisterDirective(directive, document.Editor, true);
            }

            return(tag);
        }