Added Support for Visual Studio 2013 and Generating the class as Internal (C#) or Friend (VB)
This commit is contained in:
@@ -1,14 +1,18 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<TestSettings
|
||||
id="85f80678-5acf-4267-a4f8-e5bf47bd5e87"
|
||||
name="Integration Tests"
|
||||
enableDefaultDataCollectors="false"
|
||||
xmlns="http://microsoft.com/schemas/VisualStudio/TeamTest/2010">
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<TestSettings name="Integration Tests" id="85f80678-5acf-4267-a4f8-e5bf47bd5e87" xmlns="http://microsoft.com/schemas/VisualStudio/TeamTest/2010">
|
||||
<Description>This test run configuration uses the VS IDE host type in the test run.</Description>
|
||||
<Deployment enabled="false" />
|
||||
<Execution>
|
||||
<Hosts>
|
||||
<VSSDKTestHostRunConfig name="VS IDE" HiveName="11.0Exp" xmlns="http://microsoft.com/schemas/VisualStudio/SDK/Tools/IdeHostAdapter/2006/06" />
|
||||
<VSSDKTestHostRunConfig name="VS IDE" HiveKind="DevEnv" HiveName="11.0Exp" xmlns="http://microsoft.com/schemas/VisualStudio/SDK/Tools/IdeHostAdapter/2006/06" />
|
||||
</Hosts>
|
||||
<TestTypeSpecific>
|
||||
<UnitTestRunConfig testTypeId="13cdc9d9-ddb5-4fa4-a97d-d965ccfc6d4b">
|
||||
<AssemblyResolution>
|
||||
<TestDirectory useLoadContext="true" />
|
||||
</AssemblyResolution>
|
||||
</UnitTestRunConfig>
|
||||
</TestTypeSpecific>
|
||||
<AgentRule name="LocalMachineDefaultRole">
|
||||
</AgentRule>
|
||||
</Execution>
|
||||
</TestSettings>
|
||||
</TestSettings>
|
||||
@@ -29,6 +29,12 @@ namespace ChristianHelle.DeveloperTools.CodeGenerators.Resw.CustomTool.Tests
|
||||
Assert.IsNotNull(actual);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void GeneratedCodeIsAPublicClass()
|
||||
{
|
||||
Assert.IsTrue(actual.Contains("public partial class"));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void GeneratedCodeContainsPropertiesDefinedInResources()
|
||||
{
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using System.CodeDom;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using ChristianHelle.DeveloperTools.CodeGenerators.Resw.VSPackage.CustomTool;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
|
||||
@@ -20,7 +20,7 @@ namespace ChristianHelle.DeveloperTools.CodeGenerators.Resw.CustomTool.Tests
|
||||
{
|
||||
reswFileContents = File.ReadAllText(FILE_PATH);
|
||||
|
||||
target = new CodeGeneratorFactory().Create(FILE_PATH.Replace(".resw", string.Empty), "TestApp", reswFileContents, classAccessibility: MemberAttributes.Assembly);
|
||||
target = new CodeGeneratorFactory().Create(FILE_PATH.Replace(".resw", string.Empty), "TestApp", reswFileContents, classAccessibility: TypeAttributes.NestedAssembly);
|
||||
actual = target.GenerateCode();
|
||||
}
|
||||
|
||||
@@ -30,6 +30,12 @@ namespace ChristianHelle.DeveloperTools.CodeGenerators.Resw.CustomTool.Tests
|
||||
Assert.IsNotNull(actual);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void GeneratedCodeIsAnInternalClass()
|
||||
{
|
||||
Assert.IsTrue(actual.Contains("internal partial class"));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void GeneratedCodeContainsPropertiesDefinedInResources()
|
||||
{
|
||||
|
||||
@@ -57,6 +57,7 @@
|
||||
<ItemGroup>
|
||||
<Compile Include="ClassNameExtractorTests.cs" />
|
||||
<Compile Include="CodeGeneratorFactoryTests.cs" />
|
||||
<Compile Include="VisualBasicCodeGeneratorInternalTests.cs" />
|
||||
<Compile Include="CSharpCodeGeneratorTests.cs" />
|
||||
<Compile Include="CSharpCodeGeneratorTestsInternal.cs" />
|
||||
<Compile Include="ResourceParserErrorHandlingTests.cs" />
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using ChristianHelle.DeveloperTools.CodeGenerators.Resw.VSPackage.CustomTool;
|
||||
using Microsoft.VisualBasic;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
|
||||
namespace ChristianHelle.DeveloperTools.CodeGenerators.Resw.CustomTool.Tests
|
||||
{
|
||||
[TestClass]
|
||||
[DeploymentItem("Resources/Resources.resw")]
|
||||
public class VisualBasicCodeGeneratorInternalTests
|
||||
{
|
||||
private const string FILE_PATH = "Resources.resw";
|
||||
private string actual;
|
||||
private string reswFileContents;
|
||||
private ICodeGenerator target;
|
||||
|
||||
[TestInitialize]
|
||||
public void Initialize()
|
||||
{
|
||||
reswFileContents = File.ReadAllText(FILE_PATH);
|
||||
|
||||
target = new CodeGeneratorFactory().Create(FILE_PATH.Replace(".resw", string.Empty), "TestApp", reswFileContents, new VBCodeProvider(), TypeAttributes.NestedAssembly);
|
||||
actual = target.GenerateCode();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void GenerateCodeDoesNotReturnNull()
|
||||
{
|
||||
Assert.IsNotNull(actual);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void GeneratedCodeIsFriendClass()
|
||||
{
|
||||
Assert.IsTrue(actual.Contains("Partial Friend Class"));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void GeneratedCodeContainsPropertiesDefinedInResources()
|
||||
{
|
||||
var resourceItems = target.ResourceParser.Parse();
|
||||
|
||||
foreach (var item in resourceItems.Where(item => !item.Name.Contains(".")))
|
||||
Assert.IsTrue(actual.Contains("Public Shared ReadOnly Property " + item.Name + "() As String"));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void GeneratedCodePropertiesContainsCommentsSimilarToValuesDefinedInResources()
|
||||
{
|
||||
var resourceItems = target.ResourceParser.Parse();
|
||||
|
||||
foreach (var item in resourceItems.Where(item => !item.Name.Contains(".")))
|
||||
Assert.IsTrue(actual.Contains("Localized resource similar to \"" + item.Value + "\""));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ClassNameEqualsFileNameWithoutExtension()
|
||||
{
|
||||
Assert.IsTrue(actual.Contains("Class Resources"));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ResourceLoaderInitializedWithClassName()
|
||||
{
|
||||
Assert.IsTrue(actual.Contains("New ResourceLoader(currentAssemblyName + \"/Resources\")"));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,15 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<TestSettings
|
||||
id="906380a7-c058-43a6-8f36-966013e5a9eb"
|
||||
name="Unit Tests"
|
||||
enableDefaultDataCollectors="false"
|
||||
xmlns="http://microsoft.com/schemas/VisualStudio/TeamTest/2010">
|
||||
<Deployment enabled="false" />
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<TestSettings name="Unit Tests" id="906380a7-c058-43a6-8f36-966013e5a9eb" xmlns="http://microsoft.com/schemas/VisualStudio/TeamTest/2010">
|
||||
<Description>This test run configuration is used for running the unit tests</Description>
|
||||
</TestSettings>
|
||||
<Execution>
|
||||
<TestTypeSpecific>
|
||||
<UnitTestRunConfig testTypeId="13cdc9d9-ddb5-4fa4-a97d-d965ccfc6d4b">
|
||||
<AssemblyResolution>
|
||||
<TestDirectory useLoadContext="true" />
|
||||
</AssemblyResolution>
|
||||
</UnitTestRunConfig>
|
||||
</TestTypeSpecific>
|
||||
<AgentRule name="LocalMachineDefaultRole">
|
||||
</AgentRule>
|
||||
</Execution>
|
||||
</TestSettings>
|
||||
@@ -3,6 +3,7 @@ using System.CodeDom;
|
||||
using System.CodeDom.Compiler;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using Microsoft.CSharp;
|
||||
|
||||
@@ -11,12 +12,12 @@ namespace ChristianHelle.DeveloperTools.CodeGenerators.Resw.VSPackage.CustomTool
|
||||
public class CodeDomCodeGenerator : CodeGenerator, IDisposable
|
||||
{
|
||||
private readonly string className;
|
||||
private readonly MemberAttributes? classAccessibility;
|
||||
private readonly TypeAttributes? classAccessibility;
|
||||
private readonly CodeNamespace codeNamespace;
|
||||
private readonly CodeCompileUnit compileUnit;
|
||||
private readonly CodeDomProvider provider;
|
||||
|
||||
public CodeDomCodeGenerator(IResourceParser resourceParser, string className, string defaultNamespace, CodeDomProvider codeDomProvider = null, MemberAttributes? classAccessibility = null)
|
||||
public CodeDomCodeGenerator(IResourceParser resourceParser, string className, string defaultNamespace, CodeDomProvider codeDomProvider = null, TypeAttributes? classAccessibility = null)
|
||||
: base(resourceParser, defaultNamespace)
|
||||
{
|
||||
this.className = className;
|
||||
@@ -47,7 +48,7 @@ namespace ChristianHelle.DeveloperTools.CodeGenerators.Resw.VSPackage.CustomTool
|
||||
{
|
||||
IsClass = true,
|
||||
IsPartial = true,
|
||||
Attributes = (classAccessibility.HasValue ? classAccessibility.Value : MemberAttributes.Public) | MemberAttributes.Static
|
||||
TypeAttributes = classAccessibility.HasValue ? classAccessibility.Value : TypeAttributes.Public
|
||||
};
|
||||
|
||||
const string resourceLoaderType = "ResourceLoader";
|
||||
@@ -159,7 +160,7 @@ namespace ChristianHelle.DeveloperTools.CodeGenerators.Resw.VSPackage.CustomTool
|
||||
}
|
||||
|
||||
#region IDisposable
|
||||
|
||||
|
||||
private bool disposed;
|
||||
|
||||
~CodeDomCodeGenerator()
|
||||
@@ -180,7 +181,7 @@ namespace ChristianHelle.DeveloperTools.CodeGenerators.Resw.VSPackage.CustomTool
|
||||
|
||||
if (dispose)
|
||||
provider.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
using System.CodeDom;
|
||||
using System.CodeDom.Compiler;
|
||||
using System.Reflection;
|
||||
|
||||
namespace ChristianHelle.DeveloperTools.CodeGenerators.Resw.VSPackage.CustomTool
|
||||
{
|
||||
public class CodeGeneratorFactory
|
||||
{
|
||||
public ICodeGenerator Create(string className, string defaultNamespace, string inputFileContents, CodeDomProvider codeDomProvider = null, MemberAttributes? classAccessibility = null)
|
||||
public ICodeGenerator Create(string className, string defaultNamespace, string inputFileContents, CodeDomProvider codeDomProvider = null, TypeAttributes? classAccessibility = null)
|
||||
{
|
||||
return new CodeDomCodeGenerator(new ResourceParser(inputFileContents), className, defaultNamespace, codeDomProvider, classAccessibility);
|
||||
}
|
||||
|
||||
+2
-1
@@ -1,4 +1,5 @@
|
||||
using System.CodeDom;
|
||||
using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
using Microsoft.CSharp;
|
||||
|
||||
@@ -9,7 +10,7 @@ namespace ChristianHelle.DeveloperTools.CodeGenerators.Resw.VSPackage.CustomTool
|
||||
public class ReswFileCSharpCodeGeneratorInternal : ReswFileCodeGenerator
|
||||
{
|
||||
public ReswFileCSharpCodeGeneratorInternal()
|
||||
: base(new CSharpCodeProvider(), MemberAttributes.Assembly)
|
||||
: base(new CSharpCodeProvider(), TypeAttributes.NestedAssembly)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.CodeDom;
|
||||
using System.CodeDom.Compiler;
|
||||
using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
@@ -12,9 +13,9 @@ namespace ChristianHelle.DeveloperTools.CodeGenerators.Resw.VSPackage.CustomTool
|
||||
public abstract class ReswFileCodeGenerator : IVsSingleFileGenerator
|
||||
{
|
||||
private readonly CodeDomProvider codeDomProvider;
|
||||
private readonly MemberAttributes? classAccessibility;
|
||||
private readonly TypeAttributes? classAccessibility;
|
||||
|
||||
protected ReswFileCodeGenerator(CodeDomProvider codeDomProvider, MemberAttributes? classAccessibility = null)
|
||||
protected ReswFileCodeGenerator(CodeDomProvider codeDomProvider, TypeAttributes? classAccessibility = null)
|
||||
{
|
||||
this.codeDomProvider = codeDomProvider;
|
||||
this.classAccessibility = classAccessibility;
|
||||
|
||||
+2
-2
@@ -1,4 +1,4 @@
|
||||
using System.CodeDom;
|
||||
using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
using Microsoft.VisualBasic;
|
||||
|
||||
@@ -9,7 +9,7 @@ namespace ChristianHelle.DeveloperTools.CodeGenerators.Resw.VSPackage.CustomTool
|
||||
public class ReswFileVisualBasicCodeGeneratorInternal : ReswFileCodeGenerator
|
||||
{
|
||||
public ReswFileVisualBasicCodeGeneratorInternal()
|
||||
: base(new VBCodeProvider(), MemberAttributes.Assembly)
|
||||
: base(new VBCodeProvider(), TypeAttributes.NestedAssembly)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -27,12 +27,14 @@ namespace ChristianHelle.DeveloperTools.CodeGenerators.Resw.VSPackage
|
||||
[DefaultRegistryRoot("Software\\Microsoft\\VisualStudio\\11.0")]
|
||||
[ProvideObject(typeof(ReswFileCSharpCodeGenerator))]
|
||||
[ProvideObject(typeof(ReswFileVisualBasicCodeGenerator))]
|
||||
[ProvideObject(typeof(ReswFileCSharpCodeGeneratorInternal))]
|
||||
[ProvideObject(typeof(ReswFileVisualBasicCodeGeneratorInternal))]
|
||||
[ProvideGeneratorAttribute(typeof(ReswFileCSharpCodeGenerator), "ReswFileCodeGenerator", "ResW File Code Generator for C#", "{FAE04EC1-301F-11D3-BF4B-00C04F79EFBC}", true)] // csharp
|
||||
[ProvideGeneratorAttribute(typeof(ReswFileVisualBasicCodeGenerator), "ReswFileCodeGenerator", "ResW File Code Generator for VB", "{164B10B9-B200-11D0-8C61-00A0C91E29D5}", true)] // visual basic
|
||||
[ProvideGeneratorAttribute(typeof(ReswFileCSharpCodeGenerator), "PublicReswFileCodeGenerator", "ResW File Code Generator for C#", "{FAE04EC1-301F-11D3-BF4B-00C04F79EFBC}", true)] // csharp
|
||||
[ProvideGeneratorAttribute(typeof(ReswFileVisualBasicCodeGenerator), "PublicReswFileCodeGenerator", "ResW File Code Generator for VB", "{164B10B9-B200-11D0-8C61-00A0C91E29D5}", true)] // visual basic
|
||||
[ProvideGeneratorAttribute(typeof(ReswFileCSharpCodeGeneratorInternal), "InternalReswFileCodeGenerator", "ResW File Code Generator for C#", "{151F74CA-404D-4188-B994-D7683C32ACF4}", true)] // csharp
|
||||
[ProvideGeneratorAttribute(typeof(ReswFileVisualBasicCodeGeneratorInternal), "InternalReswFileCodeGenerator", "ResW File Code Generator for VB", "{6C6AC14F-9B11-47C1-BC90-DFBFB89B1CB8}", true)] // visual basic
|
||||
[ProvideGeneratorAttribute(typeof(ReswFileCSharpCodeGeneratorInternal), "InternalReswFileCodeGenerator", "ResW File Code Generator for C#", "{FAE04EC1-301F-11D3-BF4B-00C04F79EFBC}", true)] // csharp
|
||||
[ProvideGeneratorAttribute(typeof(ReswFileVisualBasicCodeGeneratorInternal), "InternalReswFileCodeGenerator", "ResW File Code Generator for VB", "{164B10B9-B200-11D0-8C61-00A0C91E29D5}", true)] // visual basic
|
||||
public sealed class VisualStudio2012Package : Package
|
||||
{
|
||||
/// <summary>
|
||||
|
||||
@@ -27,12 +27,14 @@ namespace ChristianHelle.DeveloperTools.CodeGenerators.Resw.VSPackage
|
||||
[DefaultRegistryRoot("Software\\Microsoft\\VisualStudio\\12.0")]
|
||||
[ProvideObject(typeof(ReswFileCSharpCodeGenerator))]
|
||||
[ProvideObject(typeof(ReswFileVisualBasicCodeGenerator))]
|
||||
[ProvideObject(typeof(ReswFileCSharpCodeGeneratorInternal))]
|
||||
[ProvideObject(typeof(ReswFileVisualBasicCodeGeneratorInternal))]
|
||||
[ProvideGeneratorAttribute(typeof(ReswFileCSharpCodeGenerator), "ReswFileCodeGenerator", "ResW File Code Generator for C#", "{FAE04EC1-301F-11D3-BF4B-00C04F79EFBC}", true)] // csharp
|
||||
[ProvideGeneratorAttribute(typeof(ReswFileVisualBasicCodeGenerator), "ReswFileCodeGenerator", "ResW File Code Generator for VB", "{164B10B9-B200-11D0-8C61-00A0C91E29D5}", true)] // visual basic
|
||||
[ProvideGeneratorAttribute(typeof(ReswFileCSharpCodeGenerator), "PublicReswFileCodeGenerator", "ResW File Code Generator for C#", "{FAE04EC1-301F-11D3-BF4B-00C04F79EFBC}", true)] // csharp
|
||||
[ProvideGeneratorAttribute(typeof(ReswFileVisualBasicCodeGenerator), "PublicReswFileCodeGenerator", "ResW File Code Generator for VB", "{164B10B9-B200-11D0-8C61-00A0C91E29D5}", true)] // visual basic
|
||||
[ProvideGeneratorAttribute(typeof(ReswFileCSharpCodeGeneratorInternal), "InternalReswFileCodeGenerator", "ResW File Code Generator for C#", "{151F74CA-404D-4188-B994-D7683C32ACF4}", true)] // csharp
|
||||
[ProvideGeneratorAttribute(typeof(ReswFileVisualBasicCodeGeneratorInternal), "InternalReswFileCodeGenerator", "ResW File Code Generator for VB", "{6C6AC14F-9B11-47C1-BC90-DFBFB89B1CB8}", true)] // visual basic
|
||||
[ProvideGeneratorAttribute(typeof(ReswFileCSharpCodeGeneratorInternal), "InternalReswFileCodeGenerator", "ResW File Code Generator for C#", "{FAE04EC1-301F-11D3-BF4B-00C04F79EFBC}", true)] // csharp
|
||||
[ProvideGeneratorAttribute(typeof(ReswFileVisualBasicCodeGeneratorInternal), "InternalReswFileCodeGenerator", "ResW File Code Generator for VB", "{164B10B9-B200-11D0-8C61-00A0C91E29D5}", true)] // visual basic
|
||||
public sealed class VisualStudio2013Package : Package
|
||||
{
|
||||
/// <summary>
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
Language="en-US"
|
||||
Publisher="Christian Resma Helle" />
|
||||
<DisplayName>ResW File Code Generator</DisplayName>
|
||||
<Description>Information about my packageA Visual Studio 2012 Custom Tool for generating a strongly typed helper class for accessing localized resources from a .ResW file.</Description>
|
||||
<Description xml:space="preserve">A Visual Studio Custom Tool for generating a strongly typed helper class for accessing localized resources from a .ResW file.</Description>
|
||||
<MoreInfo>http://visualstudiogallery.msdn.microsoft.com/3ab88efd-1afb-4ff5-9faf-8825a282596a</MoreInfo>
|
||||
<License>License.txt</License>
|
||||
</Metadata>
|
||||
|
||||
Reference in New Issue
Block a user