Example #1
0
        public static void SetProperty(this PhysicalFile physicalFile, string propertyName, string propertyValue)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            var projectItem = physicalFile.AsProjectItem();

            projectItem.Properties.Item(propertyName).Value = propertyValue;
        }
Example #2
0
        public static async Task SetAsChildItemAsync(this PhysicalFile file, PhysicalFile parent)
        {
            await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

            var projectItem = parent.AsProjectItem();

            if (projectItem.ContainingProject.Properties.Item("TargetFrameworkMoniker").Value.ToString().Contains(".NETFramework"))
            {
                projectItem.ProjectItems.AddFromFile(file.FullPath);
            }
            else
            {
                await file.TrySetAttributeAsync("DependentUpon", parent.Text);
            }
        }
Example #3
0
        internal async Task CreateEnumContentAsync(PhysicalFile physicalFile, ContentGenerator generator)
        {
            await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

            var language = physicalFile.AsProjectItem().ContainingProject.CodeModel.Language;

            var codePath = Path.ChangeExtension(physicalFile.FullPath,
                                                CodeModelLanguageConstants.vsCMLanguageVB == language
                    ? ".dv.vb"
                    : ".dv.cs"
                                                );

            var codeProvider = CodeModelLanguageConstants.vsCMLanguageVB == language
                ? CodeDomProvider.CreateProvider("VisualBasic")
                : CodeDomProvider.CreateProvider("C#");

            var fileNamespace = GenerateNamespace(physicalFile);

            var enumContent = generator.GetEnumCode(codeProvider, fileNamespace);

            if (string.IsNullOrWhiteSpace(enumContent))
            {
                var vsFile = await PhysicalFile.FromFileAsync(codePath);

                if (vsFile != null)
                {
                    await vsFile.TryRemoveAsync();
                }

                return;
            }

            var file = await WriteFileAsync(enumContent, codePath, physicalFile.ContainingProject);

            if (file == null)
            {
                return;
            }

            await file.SetAsChildItemAsync(physicalFile);

            await physicalFile.ContainingProject.SaveAsync();
        }