Skip to content
This repository has been archived by the owner on Dec 18, 2017. It is now read-only.

Commit

Permalink
Make IProjectContext a POCO class
Browse files Browse the repository at this point in the history
  • Loading branch information
troydai committed Apr 28, 2015
1 parent f13cdb1 commit 150ec92
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Microsoft.Framework.Runtime.Roslyn
{
public class AfterCompileContext
{
public IProjectContext ProjectContext { get; set; }
public ProjectContext ProjectContext { get; set; }

public CSharpCompilation Compilation { get; set; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class BeforeCompileContext
{
public CSharpCompilation Compilation { get; set; }

public IProjectContext ProjectContext { get; set; }
public ProjectContext ProjectContext { get; set; }

public IList<ResourceDescription> Resources { get; set; }

Expand Down
Original file line number Diff line number Diff line change
@@ -1,41 +1,43 @@
using System;
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System.Runtime.Versioning;

namespace Microsoft.Framework.Runtime.Roslyn
{
/// <summary>
/// Stores information about the project
/// </summary>
public interface IProjectContext
public class ProjectContext
{
/// <summary>
/// Path to the project directory
/// </summary>
string ProjectDirectory { get; }
public string ProjectDirectory { get; set; }

/// <summary>
/// Path to the project file
/// </summary>
string ProjectFilePath { get; }
public string ProjectFilePath { get; set; }

/// <summary>
/// The name of the project
/// </summary>
string Name { get; }
public string Name { get; set; }

/// <summary>
/// The target framework of the project currently being compiled
/// </summary>
FrameworkName TargetFramework { get; }
public FrameworkName TargetFramework { get; set; }

/// <summary>
/// The configuration of the project currently being compiled
/// </summary>
string Configuration { get; }
public string Configuration { get; set; }

/// <summary>
/// Project version
/// </summary>
string Version { get; }
public string Version { get; set; }
}
}
14 changes: 12 additions & 2 deletions src/Microsoft.Framework.Runtime.Roslyn/CompilationContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,20 @@ public CompilationContext(CSharpCompilation compilation,

_resourcesResolver = resourcesResolver;

var projectContext = new ProjectContext
{
Name = project.Name,
ProjectDirectory = project.ProjectDirectory,
ProjectFilePath = project.ProjectFilePath,
TargetFramework = targetFramework,
Version = project.Version?.ToString(),
Configuration = configuration
};

_beforeCompileContext = new BeforeCompileContext
{
Compilation = compilation,
ProjectContext = new ProjectContext(project, targetFramework, configuration),
ProjectContext = projectContext,
Resources = new LazyList<ResourceDescription>(ResolveResources),
Diagnostics = new List<Diagnostic>(),
MetadataReferences = new List<IMetadataReference>(incomingReferences)
Expand All @@ -61,7 +71,7 @@ public IList<ResourceDescription> Resources
get { return _beforeCompileContext.Resources; }
}

public IProjectContext ProjectContext
public ProjectContext ProjectContext
{
get { return _beforeCompileContext.ProjectContext; }
}
Expand Down
26 changes: 0 additions & 26 deletions src/Microsoft.Framework.Runtime.Roslyn/ProjectContext.cs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using Xunit;

namespace Microsoft.Framework.Runtime.Roslyn.Tests
{
public class ProjectContextFacts
{
[Fact]
public void DefaultConstructorSetAllPropertiesNull()
{
var target = new ProjectContext();

// nothing is set
Assert.Null(target.Configuration);
Assert.Null(target.Name);
Assert.Null(target.ProjectDirectory);
Assert.Null(target.ProjectFilePath);
Assert.Null(target.TargetFramework);
Assert.Null(target.Version);
}
}
}

0 comments on commit 150ec92

Please sign in to comment.