コード例 #1
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);
            }
        }
コード例 #2
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);
            }
        }