6 Commits

Author SHA1 Message Date
Christian Resma Helle 58d95afea5 Implement generating code for either VS2012 or VS2013 2013-10-24 00:08:29 +02:00
Christian Resma Helle 5e50270b4b Removed tag v1.2 2013-10-23 23:51:34 +02:00
Christian Resma Helle e93bc8bfd2 Added tag v1.2 for changeset 41eacde49f95 2013-10-23 21:56:43 +02:00
Christian Resma Helle 4f89aeefe4 Added tag v1.1 for changeset 3a9f94503dea 2013-10-23 21:56:31 +02:00
Christian Resma Helle b2429f3add Creates the ResourceLoader instance using the static method GetForCurrentView() instead of the constructor to resolve the Visual Studio 2013 compiler warning 2013-10-23 21:56:08 +02:00
Christian Resma Helle abeb5e25ab changed target to visual studio integrated shell 2013-08-19 13:01:15 +02:00
11 changed files with 93 additions and 69 deletions
@@ -62,7 +62,7 @@ namespace ChristianHelle.DeveloperTools.CodeGenerators.Resw.CustomTool.Tests
[TestMethod]
public void ResourceLoaderInitializedWithClassName()
{
Assert.IsTrue(actual.Contains("new ResourceLoader(currentAssemblyName + \"/Resources\");"));
Assert.IsTrue(actual.Contains("ResourceLoader.GetForCurrentView(currentAssemblyName + \"/Resources\");"));
}
}
}
@@ -63,7 +63,7 @@ namespace ChristianHelle.DeveloperTools.CodeGenerators.Resw.CustomTool.Tests
[TestMethod]
public void ResourceLoaderInitializedWithClassName()
{
Assert.IsTrue(actual.Contains("new ResourceLoader(currentAssemblyName + \"/Resources\");"));
Assert.IsTrue(actual.Contains("ResourceLoader.GetForCurrentView(currentAssemblyName + \"/Resources\");"));
}
}
}
@@ -64,7 +64,7 @@ namespace ChristianHelle.DeveloperTools.CodeGenerators.Resw.CustomTool.Tests
[TestMethod]
public void ResourceLoaderInitializedWithClassName()
{
Assert.IsTrue(actual.Contains("New ResourceLoader(currentAssemblyName + \"/Resources\")"));
Assert.IsTrue(actual.Contains("ResourceLoader.GetForCurrentView(currentAssemblyName + \"/Resources\")"));
}
}
}
@@ -57,7 +57,7 @@ namespace ChristianHelle.DeveloperTools.CodeGenerators.Resw.CustomTool.Tests
[TestMethod]
public void ResourceLoaderInitializedWithClassName()
{
Assert.IsTrue(actual.Contains("New ResourceLoader(currentAssemblyName + \"/Resources\")"));
Assert.IsTrue(actual.Contains("ResourceLoader.GetForCurrentView(currentAssemblyName + \"/Resources\")"));
}
}
}
@@ -10,18 +10,25 @@ using Microsoft.CSharp;
namespace ChristianHelle.DeveloperTools.CodeGenerators.Resw.VSPackage.CustomTool
{
public class CodeDomCodeGenerator : CodeGenerator, IDisposable
{
private readonly string className;
{
private readonly TypeAttributes? classAccessibility;
private readonly VisualStudioVersion visualStudioVersion;
private readonly string className;
private readonly CodeNamespace codeNamespace;
private readonly CodeCompileUnit compileUnit;
private readonly CodeDomProvider provider;
public CodeDomCodeGenerator(IResourceParser resourceParser, string className, string defaultNamespace, CodeDomProvider codeDomProvider = null, TypeAttributes? classAccessibility = null)
public CodeDomCodeGenerator(IResourceParser resourceParser,
string className,
string defaultNamespace,
CodeDomProvider codeDomProvider = null,
TypeAttributes? classAccessibility = null,
VisualStudioVersion visualStudioVersion = VisualStudioVersion.VS2012)
: base(resourceParser, defaultNamespace)
{
this.className = className;
this.classAccessibility = classAccessibility;
this.visualStudioVersion = visualStudioVersion;
compileUnit = new CodeCompileUnit();
provider = codeDomProvider ?? new CSharpCodeProvider();
codeNamespace = new CodeNamespace(defaultNamespace);
@@ -29,7 +36,8 @@ namespace ChristianHelle.DeveloperTools.CodeGenerators.Resw.VSPackage.CustomTool
public override string GenerateCode()
{
codeNamespace.Comments.Add(new CodeCommentStatement("--------------------------------------------------------------------------------------------------"));
codeNamespace.Comments.Add(
new CodeCommentStatement("--------------------------------------------------------------------------------------------------"));
codeNamespace.Comments.Add(new CodeCommentStatement("<auto-generatedInfo>"));
codeNamespace.Comments.Add(new CodeCommentStatement("\tThis code was generated by ResW File Code Generator (http://reswcodegen.codeplex.com)"));
codeNamespace.Comments.Add(new CodeCommentStatement("\tResW File Code Generator was written by Christian Resma Helle"));
@@ -40,66 +48,75 @@ namespace ChristianHelle.DeveloperTools.CodeGenerators.Resw.VSPackage.CustomTool
codeNamespace.Comments.Add(new CodeCommentStatement(string.Empty));
codeNamespace.Comments.Add(new CodeCommentStatement("\tGenerated: " + DateTime.Now.ToString(CultureInfo.InvariantCulture)));
codeNamespace.Comments.Add(new CodeCommentStatement("</auto-generatedInfo>"));
codeNamespace.Comments.Add(new CodeCommentStatement("--------------------------------------------------------------------------------------------------"));
codeNamespace.Comments.Add(
new CodeCommentStatement("--------------------------------------------------------------------------------------------------"));
codeNamespace.Imports.Add(new CodeNamespaceImport("Windows.ApplicationModel.Resources"));
var targetClass = new CodeTypeDeclaration(className)
{
IsClass = true,
IsPartial = true,
TypeAttributes = classAccessibility.HasValue ? classAccessibility.Value : TypeAttributes.Public
};
{
IsClass = true,
IsPartial = true,
TypeAttributes = classAccessibility.HasValue ? classAccessibility.Value : TypeAttributes.Public
};
const string resourceLoaderType = "ResourceLoader";
var resourceLoaderField = new CodeMemberField(resourceLoaderType, "resourceLoader")
{
Attributes = MemberAttributes.Private | MemberAttributes.Static | MemberAttributes.Final
};
{
Attributes = MemberAttributes.Private | MemberAttributes.Static | MemberAttributes.Final
};
targetClass.Members.Add(resourceLoaderField);
var constructor = new CodeTypeConstructor();
var executingAssemblyVar = new CodeVariableDeclarationStatement(typeof(string), "executingAssemblyName");
var executingAssemblyInit = new CodeAssignStatement(
new CodeVariableReferenceExpression("executingAssemblyName"),
new CodeSnippetExpression("Windows.UI.Xaml.Application.Current.GetType().AssemblyQualifiedName"));
var executingAssemblySplit = new CodeVariableDeclarationStatement(typeof(string[]), "executingAssemblySplit");
var executingAssemblyInit2 = new CodeAssignStatement(
new CodeVariableReferenceExpression("executingAssemblySplit"),
new CodeMethodInvokeExpression(new CodeVariableReferenceExpression("executingAssemblyName"), "Split", new CodePrimitiveExpression(',')));
var executingAssemblyInit3 = new CodeAssignStatement(
new CodeVariableReferenceExpression("executingAssemblyName"),
new CodeArrayIndexerExpression(new CodeVariableReferenceExpression("executingAssemblySplit"), new CodePrimitiveExpression(1)));
var executingAssemblyVar = new CodeVariableDeclarationStatement(typeof (string), "executingAssemblyName");
var executingAssemblyInit = new CodeAssignStatement(new CodeVariableReferenceExpression("executingAssemblyName"),
new CodeSnippetExpression("Windows.UI.Xaml.Application.Current.GetType().AssemblyQualifiedName"));
var executingAssemblySplit = new CodeVariableDeclarationStatement(typeof (string[]), "executingAssemblySplit");
var executingAssemblyInit2 = new CodeAssignStatement(new CodeVariableReferenceExpression("executingAssemblySplit"),
new CodeMethodInvokeExpression(new CodeVariableReferenceExpression("executingAssemblyName"),
"Split",
new CodePrimitiveExpression(',')));
var executingAssemblyInit3 = new CodeAssignStatement(new CodeVariableReferenceExpression("executingAssemblyName"),
new CodeArrayIndexerExpression(new CodeVariableReferenceExpression("executingAssemblySplit"),
new CodePrimitiveExpression(1)));
var currentAssemblyVar = new CodeVariableDeclarationStatement(typeof(string), "currentAssemblyName");
var currentAssemblyInit = new CodeAssignStatement(
new CodeVariableReferenceExpression("currentAssemblyName"),
new CodePropertyReferenceExpression(new CodeTypeOfExpression(className), "AssemblyQualifiedName"));
var currentAssemblySplit = new CodeVariableDeclarationStatement(typeof(string[]), "currentAssemblySplit");
var currentAssemblyInit2 = new CodeAssignStatement(
new CodeVariableReferenceExpression("currentAssemblySplit"),
new CodeMethodInvokeExpression(new CodeVariableReferenceExpression("currentAssemblyName"), "Split", new CodePrimitiveExpression(',')));
var currentAssemblyInit3 = new CodeAssignStatement(
new CodeVariableReferenceExpression("currentAssemblyName"),
new CodeArrayIndexerExpression(new CodeVariableReferenceExpression("currentAssemblySplit"), new CodePrimitiveExpression(1)));
var currentAssemblyVar = new CodeVariableDeclarationStatement(typeof (string), "currentAssemblyName");
var currentAssemblyInit = new CodeAssignStatement(new CodeVariableReferenceExpression("currentAssemblyName"),
new CodePropertyReferenceExpression(new CodeTypeOfExpression(className), "AssemblyQualifiedName"));
var currentAssemblySplit = new CodeVariableDeclarationStatement(typeof (string[]), "currentAssemblySplit");
var currentAssemblyInit2 = new CodeAssignStatement(new CodeVariableReferenceExpression("currentAssemblySplit"),
new CodeMethodInvokeExpression(new CodeVariableReferenceExpression("currentAssemblyName"),
"Split",
new CodePrimitiveExpression(',')));
var currentAssemblyInit3 = new CodeAssignStatement(new CodeVariableReferenceExpression("currentAssemblyName"),
new CodeArrayIndexerExpression(new CodeVariableReferenceExpression("currentAssemblySplit"),
new CodePrimitiveExpression(1)));
var createResourceLoader = new CodeConditionStatement(
new CodeSnippetExpression("executingAssemblyName.Equals(currentAssemblyName)"),
new CodeStatement[] // true
{
new CodeAssignStatement(
new CodeFieldReferenceExpression(null, "resourceLoader"),
new CodeObjectCreateExpression(new CodeTypeReference("ResourceLoader"),
new CodeSnippetExpression("\"" + className + "\"")))
},
{
visualStudioVersion == VisualStudioVersion.VS2013
? new CodeAssignStatement(new CodeFieldReferenceExpression(null, "resourceLoader"),
new CodeMethodInvokeExpression(new CodeTypeReferenceExpression("ResourceLoader"),
"GetForCurrentView",
new CodeSnippetExpression("\"" + className + "\"")))
: new CodeAssignStatement(new CodeFieldReferenceExpression(null, "resourceLoader"),
new CodeObjectCreateExpression(new CodeTypeReference("ResourceLoader"),
new CodeSnippetExpression("\"" + className + "\"")))
},
new CodeStatement[] // false
{
new CodeAssignStatement(
new CodeFieldReferenceExpression(null, "resourceLoader"),
new CodeObjectCreateExpression(new CodeTypeReference("ResourceLoader"),
new CodeSnippetExpression("currentAssemblyName + \"/" + className + "\"")))
});
{
visualStudioVersion == VisualStudioVersion.VS2013
? new CodeAssignStatement(new CodeFieldReferenceExpression(null, "resourceLoader"),
new CodeMethodInvokeExpression(new CodeTypeReferenceExpression("ResourceLoader"),
"GetForCurrentView",
new CodeSnippetExpression("currentAssemblyName + \"/" + className + "\"")))
: new CodeAssignStatement(new CodeFieldReferenceExpression(null, "resourceLoader"),
new CodeObjectCreateExpression(new CodeTypeReference("ResourceLoader"),
new CodeSnippetExpression("currentAssemblyName + \"/" + className + "\"")))
});
constructor.Statements.Add(executingAssemblyVar);
constructor.Statements.Add(executingAssemblyInit);
@@ -122,12 +139,12 @@ namespace ChristianHelle.DeveloperTools.CodeGenerators.Resw.VSPackage.CustomTool
continue;
var property = new CodeMemberProperty
{
Name = item.Name.Trim(),
Attributes = MemberAttributes.Public | MemberAttributes.Static,
HasGet = true,
Type = new CodeTypeReference(typeof(string))
};
{
Name = item.Name.Trim(),
Attributes = MemberAttributes.Public | MemberAttributes.Static,
HasGet = true,
Type = new CodeTypeReference(typeof (string))
};
property.Comments.Add(new CodeCommentStatement("<summary>", true));
property.Comments.Add(new CodeCommentStatement("Localized resource similar to \"" + (item.Value ?? item.Name) + "\"", true));
@@ -135,7 +152,8 @@ namespace ChristianHelle.DeveloperTools.CodeGenerators.Resw.VSPackage.CustomTool
property.GetStatements.Add(
new CodeMethodReturnStatement(
new CodeMethodInvokeExpression(
new CodeFieldReferenceExpression(null, "resourceLoader"), "GetString",
new CodeFieldReferenceExpression(null, "resourceLoader"),
"GetString",
new CodePrimitiveExpression(item.Name))));
targetClass.Members.Add(property);
@@ -149,7 +167,7 @@ namespace ChristianHelle.DeveloperTools.CodeGenerators.Resw.VSPackage.CustomTool
private string GenerateCodeFromCompileUnit()
{
var options = new CodeGeneratorOptions { BracingStyle = "C" };
var options = new CodeGeneratorOptions {BracingStyle = "C"};
var code = new StringBuilder();
@@ -163,16 +181,16 @@ namespace ChristianHelle.DeveloperTools.CodeGenerators.Resw.VSPackage.CustomTool
private bool disposed;
~CodeDomCodeGenerator()
{
Dispose(false);
}
public void Dispose()
{
Dispose(true);
}
~CodeDomCodeGenerator()
{
Dispose(false);
}
protected virtual void Dispose(bool dispose)
{
if (disposed)
@@ -0,0 +1,8 @@
namespace ChristianHelle.DeveloperTools.CodeGenerators.Resw.VSPackage.CustomTool
{
public enum VisualStudioVersion
{
VS2012,
VS2013
}
}
@@ -29,7 +29,7 @@ using System.Runtime.InteropServices;
// You can specify all the values or you can default the Revision and Build Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("1.1.0.*")]
[assembly: AssemblyVersion("1.2.0.*")]
[assembly: InternalsVisibleTo("VSPackage_IntegrationTests, PublicKey=002400000480000094000000060200000024000052534131000400000100010045bd05a5b24c74b83f069df52e138682c2fb8b1ee65cb9d351fd7e8d622308aeb588b2a2975d75da4fe8a392510528baa26a3317809ec064d3cc852f0df94752ad2228d9f2a048ee2858c1e9d505b05f7fb4ede02f34154f75ea50445741c84f5ab1c814358f5fd6a6f08bb3d94284cff0524d5ca9d888c8648bcbc7a1e0a3c8")]
[assembly: InternalsVisibleTo("VSPackage_UnitTests, PublicKey=002400000480000094000000060200000024000052534131000400000100010045bd05a5b24c74b83f069df52e138682c2fb8b1ee65cb9d351fd7e8d622308aeb588b2a2975d75da4fe8a392510528baa26a3317809ec064d3cc852f0df94752ad2228d9f2a048ee2858c1e9d505b05f7fb4ede02f34154f75ea50445741c84f5ab1c814358f5fd6a6f08bb3d94284cff0524d5ca9d888c8648bcbc7a1e0a3c8")]
@@ -119,6 +119,7 @@
</COMReference>
</ItemGroup>
<ItemGroup>
<Compile Include="CustomTool\VisualStudioVersion.cs" />
<Compile Include="VisualStudio2013Package.cs" />
<Compile Include="CustomTool\ClassNameExtractor.cs" />
<Compile Include="CustomTool\CodeDomCodeGenerator.cs" />
@@ -63,7 +63,6 @@ namespace ChristianHelle.DeveloperTools.CodeGenerators.Resw.VSPackage
{
Debug.WriteLine (string.Format(CultureInfo.CurrentCulture, "Entering Initialize() of: {0}", this.ToString()));
base.Initialize();
}
#endregion
@@ -63,7 +63,6 @@ namespace ChristianHelle.DeveloperTools.CodeGenerators.Resw.VSPackage
{
Debug.WriteLine (string.Format(CultureInfo.CurrentCulture, "Entering Initialize() of: {0}", this.ToString()));
base.Initialize();
}
#endregion
@@ -13,8 +13,7 @@
<License>License.txt</License>
</Metadata>
<Installation InstalledByMsi="false">
<InstallationTarget Version="[11.0,12.0]"
Id="Microsoft.VisualStudio.Premium" />
<InstallationTarget Version="[11.0,12.0]" Id="Microsoft.VisualStudio.IntegratedShell" />
</Installation>
<Dependencies>
<Dependency Id="Microsoft.Framework.NDP"