Exemplo n.º 1
0
        public static void AddWizardExtension(this IVsTemplate template, Type templateExtensionType)
        {
            Guard.NotNull(() => template, template);
            Guard.NotNull(() => templateExtensionType, templateExtensionType);
            Guard.OfType(() => template, template, typeof(VSTemplate));

            var temp = (VSTemplate)template;
            var doc  = new XmlDocument();

            var newExtension = new VSTemplateWizardExtension[]
            {
                new VSTemplateWizardExtension
                {
                    Assembly      = new[] { new XmlNode[] { doc.CreateTextNode(templateExtensionType.Assembly.GetName().FullName) } },
                    FullClassName = new[] { new XmlNode[] { doc.CreateTextNode(templateExtensionType.FullName) } }
                }
            };

            if (temp.WizardExtension == null)
            {
                temp.WizardExtension = newExtension;
                VsTemplateFile.Write(template);
            }
            else
            {
                if (temp.WizardExtension.GetExtension(templateExtensionType) == null)
                {
                    if (temp.WizardExtension.Any(ext =>
                                                 (ext.Assembly[0] as XmlNode[])[0].Value.Contains(templateExtensionType.Assembly.GetName().Name) &&
                                                 (ext.FullClassName[0] as XmlNode[])[0].Value.Contains(templateExtensionType.Name)))
                    {
                        RemoveWizardExtension(template, templateExtensionType);
                    }

                    var existingExtensions = temp.WizardExtension;

                    temp.WizardExtension = existingExtensions.Concat(newExtension).ToArray();
                    VsTemplateFile.Write(template);
                }
            }
        }
Exemplo n.º 2
0
        public static void AddWizardExtension(this IVsTemplate template, Type templateExtensionType)
        {
            Guard.NotNull(() => template, template);
            Guard.NotNull(() => templateExtensionType, templateExtensionType);
            Guard.OfType(() => template, template, typeof(VSTemplate));

            var temp = (VSTemplate)template;
            var doc = new XmlDocument();

            var newExtension = new VSTemplateWizardExtension[]
            {
                new VSTemplateWizardExtension
                {
                    Assembly = new[] { new XmlNode[] { doc.CreateTextNode(templateExtensionType.Assembly.GetName().FullName) } },
                    FullClassName = new[] { new XmlNode[] { doc.CreateTextNode(templateExtensionType.FullName) } }
                }
            };

            if (temp.WizardExtension == null)
            {
                temp.WizardExtension = newExtension;
                VsTemplateFile.Write(template);
            }
            else
            {
                if (temp.WizardExtension.GetExtension(templateExtensionType) == null)
                {
                    if (temp.WizardExtension.Any(ext =>
                        (ext.Assembly[0] as XmlNode[])[0].Value.Contains(templateExtensionType.Assembly.GetName().Name) &&
                        (ext.FullClassName[0] as XmlNode[])[0].Value.Contains(templateExtensionType.Name)))
                    {
                        RemoveWizardExtension(template, templateExtensionType);
                    }

                    var existingExtensions = temp.WizardExtension;

                    temp.WizardExtension = existingExtensions.Concat(newExtension).ToArray();
                    VsTemplateFile.Write(template);
                }
            }
        }