Esempio n. 1
0
            public override bool GetStandardValuesExclusive(ITypeDescriptorContext context)
            {
                //only make the list exclusive if we managed to get a list from the parent project
                ProjectFileDescriptor descriptor = context != null?
                                                   context.Instance as ProjectFileDescriptor : null;

                return(descriptor != null && descriptor.file != null && descriptor.file.Project != null);
            }
            public override System.Collections.ICollection GetStandardStrings(ITypeDescriptorContext context)
            {
                ProjectFileDescriptor descriptor = context != null?
                                                   context.Instance as ProjectFileDescriptor : null;

                if (descriptor != null && descriptor.file != null && descriptor.file.Project != null)
                {
                    return(descriptor.file.Project.GetBuildActions());
                }
                else
                {
                    return(new string[] { "Content", "None", "Compile" });
                }
            }
        public void GeneratorStandardValues()
        {
            using var project = new FileContainerProject();
            project.Files.Add(new ProjectFile("bar.cs")
            {
                Generator = "MyCustomTool"
            });
            project.Files.Add(new ProjectFile("baz.resx")
            {
                Generator = "ResXFileCodeGenerator"
            });

            var file = new ProjectFile("foo.tt");

            project.Files.Add(file);

            using var desc = new ProjectFileDescriptor(file);
            var props = desc.GetProperties();

            var genProp = props.Find("Generator", false);

            Assert.NotNull(genProp);

            Assert.True(genProp.Converter.GetStandardValuesSupported());

            var ctx          = new SimpleTypeDescriptorContext(null, desc);
            var standardVals = genProp.Converter.GetStandardValues(ctx);

            Assert.NotNull(standardVals);

            var standardStrings = standardVals.OfType <string> ().ToList();

            Assert.AreEqual(standardVals.Count, standardStrings.Count);

            // resx generator is filtered to resx files so it shouldn't be here
            // even though another file in the project uses it
            Assert.False(standardStrings.Contains("ResXFileCodeGenerator"));

            // t4 generator is registered for tt files so it should be here
            // even though it's not used on any other file in the project yet
            Assert.True(standardStrings.Contains("TextTemplatingFileGenerator"));

            // make sure other generators seen in the project are here
            Assert.True(standardStrings.Contains("MyCustomTool"));
        }