PageRenderTime 25ms CodeModel.GetById 13ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 0ms

/src/AddIns/Misc/PackageManagement/Project/Src/ProjectTargetFramework.cs

https://github.com/ajadex/SharpDevelop
C# | 79 lines | 51 code | 11 blank | 17 comment | 1 complexity | e2efbcf243c4ebf5fcba4a33959d67f8 MD5 | raw file
 1// Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
 2// 
 3// Permission is hereby granted, free of charge, to any person obtaining a copy of this
 4// software and associated documentation files (the "Software"), to deal in the Software
 5// without restriction, including without limitation the rights to use, copy, modify, merge,
 6// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
 7// to whom the Software is furnished to do so, subject to the following conditions:
 8// 
 9// The above copyright notice and this permission notice shall be included in all copies or
10// substantial portions of the Software.
11// 
12// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17// DEALINGS IN THE SOFTWARE.
18
19using System;
20using System.Runtime.Versioning;
21using ICSharpCode.SharpDevelop.Project;
22
23namespace ICSharpCode.PackageManagement
24{
25	public class ProjectTargetFramework
26	{
27		MSBuildBasedProject project;
28		FrameworkName targetFramework;
29		
30		public ProjectTargetFramework(MSBuildBasedProject project)
31		{
32			this.project = project;
33			GetTargetFramework();
34		}
35		
36		void GetTargetFramework()
37		{
38			string identifier = GetTargetFrameworkIdentifier();
39			string version = GetTargetFrameworkVersion();
40			string profile = GetTargetFrameworkProfile();
41			
42			GetTargetFramework(identifier, version, profile);
43		}
44		
45		void GetTargetFramework(string identifier, string version, string profile)
46		{
47			string name = String.Format("{0}, Version={1}, Profile={2}", identifier, version, profile);
48			targetFramework = new FrameworkName(name);
49		}
50		
51		string GetTargetFrameworkIdentifier()
52		{
53			return GetEvaluatedPropertyOrDefault("TargetFrameworkIdentifier", ".NETFramework");
54		}
55		
56		string GetTargetFrameworkVersion()
57		{
58			return project.GetEvaluatedProperty("TargetFrameworkVersion");
59		}
60		
61		string GetTargetFrameworkProfile()
62		{
63			return GetEvaluatedPropertyOrDefault("TargetFrameworkProfile", String.Empty);
64		}
65		
66		string GetEvaluatedPropertyOrDefault(string propertyName, string defaultPropertyValue)
67		{
68			string propertyValue = project.GetEvaluatedProperty(propertyName);
69			if (String.IsNullOrEmpty(propertyValue)) {
70				return defaultPropertyValue;
71			}
72			return propertyValue;
73		}
74		
75		public FrameworkName TargetFrameworkName {
76			get { return targetFramework; }
77		}
78	}
79}