Exemplo n.º 1
0
        protected override void CopyProperties(IProject sourceProject, IProject targetProject)
        {
            VBNetProject vbProject = (VBNetProject)targetProject;

            base.CopyProperties(sourceProject, targetProject);
            FixProperty(vbProject, "DefineConstants", v => v.Replace(';', ','));
            FixProperty(vbProject, "ProjectTypeGuids",
                        v => v.Replace(ProjectTypeGuids.CSharp, ProjectTypeGuids.VBNet, StringComparison.OrdinalIgnoreCase));

            // determine the StartupObject
            startupObject = vbProject.GetEvaluatedProperty("StartupObject");
            if (string.IsNullOrEmpty(startupObject))
            {
                IList <IClass> startupObjects = ICSharpCode.SharpDevelop.Gui.OptionPanels.ApplicationSettings.GetPossibleStartupObjects(sourceProject);
                if (startupObjects.Count == 1)
                {
                    startupObject = startupObjects[0].FullyQualifiedName;
                    if (vbProject.OutputType == OutputType.WinExe)
                    {
                        // we have to set StartupObject to prevent the VB compiler from choosing
                        // the generated Main method.
                        vbProject.SetProperty("StartupObject", startupObject);
                    }
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Builds Visual Basic's "My" namespace for the specified project.
        /// </summary>
        public static void BuildNamespace(VBNetProject project, IProjectContent pc)
        {
            ICompilationUnit cu = new DefaultCompilationUnit(pc);
            //cu.FileName = "GeneratedMyNamespace.vb"; // leave FileName null - fixes SD2-854
            string ns;

            if (project.RootNamespace == null || project.RootNamespace.Length == 0)
            {
                ns = "My";
            }
            else
            {
                ns = project.RootNamespace + ".My";
            }
            IClass myApp  = CreateMyApplication(cu, project, ns);
            IClass myComp = CreateMyComputer(cu, project, ns);

            cu.Classes.Add(myApp);
            cu.Classes.Add(myComp);

            IClass myForms = null;

            if (project.OutputType == OutputType.WinExe)
            {
                myForms = CreateMyForms(cu, project, ns);
                cu.Classes.Add(myForms);
            }
            DefaultClass c = new DefaultClass(cu, ns + ".MyProject");

            c.ClassType = ClassType.Module;
            c.Modifiers = ModifierEnum.Internal | ModifierEnum.Partial | ModifierEnum.Sealed | ModifierEnum.Synthetic;
            c.Attributes.Add(new DefaultAttribute(CreateTypeRef(cu, "Microsoft.VisualBasic.HideModuleNameAttribute")));

            // we need to use GetClassReturnType instead of DefaultReturnType because we need
            // a reference to the compound class.
            c.Properties.Add(new DefaultProperty("Application",
                                                 new GetClassReturnType(pc, myApp.FullyQualifiedName, 0),
                                                 ModifierEnum.Public | ModifierEnum.Static,
                                                 DomRegion.Empty, DomRegion.Empty, c));
            c.Properties.Add(new DefaultProperty("Computer",
                                                 new GetClassReturnType(pc, myComp.FullyQualifiedName, 0),
                                                 ModifierEnum.Public | ModifierEnum.Static,
                                                 DomRegion.Empty, DomRegion.Empty, c));
            if (myForms != null)
            {
                c.Properties.Add(new DefaultProperty("Forms",
                                                     new GetClassReturnType(pc, myForms.FullyQualifiedName, 0),
                                                     ModifierEnum.Public | ModifierEnum.Static,
                                                     DomRegion.Empty, DomRegion.Empty, c));
            }
            c.Properties.Add(new DefaultProperty("User",
                                                 new GetClassReturnType(pc, "Microsoft.VisualBasic.ApplicationServices.User", 0),
                                                 ModifierEnum.Public | ModifierEnum.Static,
                                                 DomRegion.Empty, DomRegion.Empty, c));
            cu.Classes.Add(c);
            pc.UpdateCompilationUnit(null, cu, cu.FileName);
        }
Exemplo n.º 3
0
        protected override IProject CreateProject(string targetProjectDirectory, IProject sourceProject)
        {
            VBNetProject             project  = (VBNetProject)base.CreateProject(targetProjectDirectory, sourceProject);
            IProjectItemListProvider provider = (IProjectItemListProvider)project;

            foreach (string import in defaultImports)
            {
                provider.AddProjectItem(new ImportProjectItem(project, import));
            }
            return(project);
        }
Exemplo n.º 4
0
        static IClass CreateMyApplication(ICompilationUnit cu, VBNetProject project, string ns)
        {
            DefaultClass c = new DefaultClass(cu, ns + ".MyApplication");

            c.ClassType = ClassType.Class;
            c.Modifiers = ModifierEnum.Internal | ModifierEnum.Sealed | ModifierEnum.Partial | ModifierEnum.Synthetic;
            c.Attributes.Add(new DefaultAttribute(CreateTypeRef(cu, "Microsoft.VisualBasic.HideModuleNameAttribute")));
            switch (project.OutputType)
            {
            case OutputType.WinExe:
                c.BaseTypes.Add(CreateTypeRef(cu, "Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase"));
                if (project.GetEvaluatedProperty("MyType") == "WindowsForms")
                {
                    c.Methods.Add(
                        new DefaultMethod(c, "Main")
                    {
                        Modifiers  = ModifierEnum.Internal | ModifierEnum.Static,
                        ReturnType = c.ProjectContent.SystemTypes.Void,
                        Parameters = new[] {
                            new DefaultParameter(
                                "args",
                                new ArrayReturnType(c.ProjectContent, c.ProjectContent.SystemTypes.String, 1),
                                DomRegion.Empty
                                )
                        }
                    });
                }
                break;

            case OutputType.Exe:
                c.BaseTypes.Add(CreateTypeRef(cu, "Microsoft.VisualBasic.ApplicationServices.ConsoleApplicationBase"));
                break;

            default:
                c.BaseTypes.Add(CreateTypeRef(cu, "Microsoft.VisualBasic.ApplicationServices.ApplicationBase"));
                break;
            }
            return(c);
        }