📄 abstractproject.cs
字号:
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Mike Krüger" email="mike@icsharpcode.net"/>
// <version>$Revision: 1343 $</version>
// </file>
using System;
using System.ComponentModel;
using System.CodeDom.Compiler;
using System.Diagnostics;
using System.IO;
using System.Globalization;
using System.Collections.Generic;
using System.Reflection;
using System.Text;
using System.Text.RegularExpressions;
using System.Xml;
using ICSharpCode.Core;
using ICSharpCode.SharpDevelop.Gui;
using ICSharpCode.SharpDevelop.Internal.Templates;
namespace ICSharpCode.SharpDevelop.Project
{
public abstract class AbstractProject : AbstractSolutionFolder, IProject
{
protected Dictionary<string, PropertyGroup> configurations = new Dictionary<string, PropertyGroup>();
protected Dictionary<string, PropertyGroup> userConfigurations = new Dictionary<string, PropertyGroup>();
protected List<ProjectItem> items = new List<ProjectItem>();
protected List<string> imports = new List<string>();
readonly List<ProjectSection> projectSections = new List<ProjectSection>();
string fileName;
string language;
[Browsable(false)]
public Dictionary<string, PropertyGroup> Configurations {
get {
return configurations;
}
}
[Browsable(false)]
public Dictionary<string, PropertyGroup> UserConfigurations {
get {
return userConfigurations;
}
}
public static string GetConfigurationNameFromKey(string key)
{
return key.Substring(0, key.IndexOf('|'));
}
public static string GetPlatformNameFromKey(string key)
{
return key.Substring(key.IndexOf('|') + 1);
}
public List<string> GetConfigurationNames()
{
List<string> configurationNames = new List<string>();
foreach (string key in configurations.Keys) {
string configuration = GetConfigurationNameFromKey(key);
if (configuration != "*" && !configurationNames.Contains(configuration)) {
configurationNames.Add(configuration);
}
}
foreach (string key in userConfigurations.Keys) {
string configuration = GetConfigurationNameFromKey(key);
if (configuration != "*" && !configurationNames.Contains(configuration)) {
configurationNames.Add(configuration);
}
}
if (!configurationNames.Contains(this.Configuration)) {
configurationNames.Add(this.Configuration);
}
return configurationNames;
}
public List<string> GetPlatformNames()
{
List<string> platformNames = new List<string>();
foreach (string key in configurations.Keys) {
string platform = GetPlatformNameFromKey(key);
if (platform != "*" && !platformNames.Contains(platform)) {
platformNames.Add(platform);
}
}
foreach (string key in userConfigurations.Keys) {
string platform = GetPlatformNameFromKey(key);
if (platform != "*" && !platformNames.Contains(platform)) {
platformNames.Add(platform);
}
}
if (!platformNames.Contains(this.Platform)) {
platformNames.Add(this.Platform);
}
return platformNames;
}
/// <summary>
/// Import options from an attribute collection. This is used to read the template options.
/// </summary>
public void ImportOptions(XmlAttributeCollection attributes)
{
Type t = GetType();
foreach (XmlAttribute attr in attributes) {
PropertyInfo prop = t.GetProperty(attr.Name, BindingFlags.IgnoreCase | BindingFlags.Instance | BindingFlags.Public);
if (prop == null) {
MessageService.ShowError("Property '" + attr.Name + "' does not exist!");
} else {
TypeConverter desc = TypeDescriptor.GetConverter(prop.PropertyType);
prop.SetValue(this, desc.ConvertFromInvariantString(attr.Value), null);
}
}
}
protected bool isDirty = false;
[Browsable(false)]
public bool IsDirty {
get {
return isDirty;
}
set {
isDirty = value;
}
}
PropertyGroup baseConfiguration = new PropertyGroup();
[Browsable(false)]
public PropertyGroup BaseConfiguration {
get {
return baseConfiguration;
}
}
PropertyGroup userBaseConfiguration = new PropertyGroup();
[Browsable(false)]
public PropertyGroup UserBaseConfiguration {
get {
return userBaseConfiguration;
}
}
[Browsable(false)]
public List<ProjectItem> Items {
get {
return items;
}
}
/// <summary>
/// Gets a list of property sections stored in the solution file.
/// </summary>
[Browsable(false)]
public List<ProjectSection> ProjectSections {
get {
return projectSections;
}
}
/// <summary>
/// Gets the list of MSBuild Imports.
/// </summary>
/// <returns>
/// List of Import filenames, <example>$(MSBuildBinPath)\Microsoft.VisualBasic.targets</example>
/// </returns>
[Browsable(false)]
public List<string> Imports {
get {
return imports;
}
}
[Browsable(false)]
public string FileName {
get {
if (fileName == null) {
return String.Empty;
}
return fileName;
}
set {
fileName = value;
}
}
string directoryName;
[Browsable(false)]
public string Directory {
get {
if (directoryName == null) {
if (fileName == null) {
return String.Empty;
}
directoryName = Path.GetDirectoryName(fileName);
}
return directoryName;
}
}
[ReadOnly(true)]
[LocalizedProperty("${res:MainWindow.Windows.Debug.CallStack.Language}")]
public string Language {
get {
return language;
}
set {
language = value;
}
}
ICSharpCode.SharpDevelop.Dom.LanguageProperties languageProperties = ICSharpCode.SharpDevelop.Dom.LanguageProperties.CSharp;
[Browsable(false)]
public ICSharpCode.SharpDevelop.Dom.LanguageProperties LanguageProperties {
get {
return languageProperties;
}
set {
languageProperties = value;
}
}
[Browsable(false)]
public virtual IAmbience Ambience {
get {
return null;
}
}
string activeConfiguration = "Debug";
string activePlatform = "AnyCPU";
[ReadOnly(true)]
[LocalizedProperty("${res:Dialog.ProjectOptions.Platform}")]
public string Platform {
get {
return activePlatform;
}
set {
if (value == "Any CPU") {
// This seems to be a special case in MSBuild
List<string> platformNames = GetPlatformNames();
if (!platformNames.Contains("Any CPU") && platformNames.Contains("AnyCPU")) {
value = "AnyCPU";
}
}
activePlatform = value;
}
}
[ReadOnly(true)]
[LocalizedProperty("${res:Dialog.ProjectOptions.Configuration}")]
public string Configuration {
get {
return activeConfiguration;
}
set {
activeConfiguration = value;
}
}
[Browsable(false)]
public string DefaultConfiguration {
get {
// is always stored in BaseConfiguration
return BaseConfiguration["Configuration"];
}
set {
BaseConfiguration["Configuration"] = value;
}
}
[Browsable(false)]
public string DefaultPlatform {
get {
// is always stored in BaseConfiguration
return BaseConfiguration["Platform"];
}
set {
BaseConfiguration["Platform"] = value;
}
}
[Browsable(false)]
public virtual OutputType OutputType {
get {
return GetProperty("OutputType", OutputType.Exe);
}
set {
SetProperty("OutputType", value);
}
}
[Browsable(false)]
public string DocumentationFileName {
get {
string file = GetProperty("DocumentationFile");
if (file == null || file.Length == 0)
return null;
return Path.Combine(Directory, file);
}
}
[Browsable(false)]
public string OutputAssemblyFullPath {
get {
string outputPath = GetProperty("OutputPath");
return Path.Combine(Path.Combine(Directory, outputPath), AssemblyName + GetExtension(OutputType));
}
}
public static string GetExtension(OutputType outputType)
{
switch (outputType) {
case OutputType.WinExe:
case OutputType.Exe:
return ".exe";
case OutputType.Module:
return ".netmodule";
default:
return ".dll";
}
}
/// <summary>
/// Legacy, only for VS.NET compatiblity reasons.
/// </summary>
[Browsable(false)]
public Guid Guid {
get {
// is always in base config
return new Guid(BaseConfiguration["ProjectGuid"]);
}
}
[Browsable(false)]
public string RootNamespace {
get {
return GetProperty("RootNamespace");
}
set {
SetProperty("RootNamespace", value);
}
}
[Browsable(false)]
public string AssemblyName {
get {
return GetProperty("AssemblyName");
}
set {
SetProperty("AssemblyName", value);
}
}
[Browsable(false)]
public string AppDesignerFolder {
get {
return GetProperty("AppDesignerFolder");
}
set {
SetProperty("AppDesignerFolder", value);
}
}
[Browsable(false)]
public override string TypeGuid {
get {
return LanguageBindingService.GetCodonPerLanguageName(Language).Guid;
}
set {
throw new System.NotSupportedException();
}
}
public virtual bool CanCompile(string fileName)
{
return false;
}
public virtual void Save()
{
Save(FileName);
}
public virtual void Save(string fileName)
{
}
public virtual void Start(bool withDebugging)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -