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

            var temp = (VSTemplate)template;

            if (temp.WizardExtension == null)
            {
                return;
            }
            else
            {
                var extensionToRemove = temp.WizardExtension.FirstOrDefault(ext =>
                                                                            (ext.Assembly[0] as XmlNode[])[0].Value.Contains(templateExtensionType.Assembly.GetName().Name) &&
                                                                            (ext.FullClassName[0] as XmlNode[])[0].Value.Contains(templateExtensionType.Name));
                if (extensionToRemove != null)
                {
                    var existingExtensions = temp.WizardExtension.Except(new[] { extensionToRemove }).ToArray();
                    temp.WizardExtension = existingExtensions;
                    VsTemplateFile.Write(template);
                }
            }
        }
Esempio n. 2
0
        public static void SetHidden(this IVsTemplate template, bool hidden)
        {
            Guard.NotNull(() => template, template);
            Guard.OfType(() => template, template, typeof(VSTemplate));

            var temp = (VSTemplate)template;

            temp.TemplateData.HiddenSpecified = hidden;
            temp.TemplateData.Hidden          = hidden;
            VsTemplateFile.Write(temp);
        }
Esempio n. 3
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);
                }
            }
        }
Esempio n. 4
0
        public static void SetWizardData(this IVsTemplate template, string name, string value)
        {
            Guard.NotNull(() => template, template);
            Guard.NotNull(() => name, name);
            Guard.NotNull(() => value, value);
            Guard.OfType(() => template, template, typeof(VSTemplate));

            var temp = (VSTemplate)template;

            var doc         = new XmlDocument();
            var dataElement = doc.CreateElement(name, "http://schemas.microsoft.com/developer/vstemplate/2005");

            dataElement.InnerText = value;

            var newData = new VSTemplateWizardData[]
            {
                new VSTemplateWizardData
                {
                    Any = new[] { dataElement }
                }
            };

            if (temp.WizardData == null)
            {
                temp.WizardData = newData;
                VsTemplateFile.Write(template);
            }
            else if (!temp.WizardData.Any(ext =>
                                          ext.Any.Count(e => e.Name == name && e.InnerText == value) > 0))
            {
                var existingData = temp.WizardData;

                temp.WizardData[0].Any = existingData[0].Any.Concat(new[] { dataElement }).ToArray();
                VsTemplateFile.Write(template);
            }
        }