@ -7,11 +7,15 @@
@@ -7,11 +7,15 @@
using System ;
using System.Collections ;
using ICSharpCode.SharpDevelop.Project ;
using System.Resources ;
using System.Resources.Tools ;
using System.IO ;
using ICSharpCode.Core ;
using ICSharpCode.SharpDevelop ;
using ICSharpCode.SharpDevelop.Dom ;
using ICSharpCode.SharpDevelop.Project ;
namespace ResourceEditor
{
public class ResourceCodeGeneratorTool : ICustomTool
@ -26,6 +30,21 @@ namespace ResourceEditor
@@ -26,6 +30,21 @@ namespace ResourceEditor
} ) ; * /
string inputFilePath = item . FileName ;
// Ensure that the generated code will not conflict with an
// existing class.
if ( context . Project ! = null ) {
IProjectContent pc = ParserService . GetProjectContent ( context . Project ) ;
if ( pc ! = null ) {
IClass existingClass = pc . GetClass ( context . OutputNamespace + "." + StronglyTypedResourceBuilder . VerifyResourceName ( Path . GetFileNameWithoutExtension ( inputFilePath ) , pc . Language . CodeDomProvider ) , 0 ) ;
if ( existingClass ! = null ) {
if ( ! IsGeneratedResourceClass ( existingClass ) ) {
context . MessageView . AppendLine ( String . Format ( System . Globalization . CultureInfo . CurrentCulture , ResourceService . GetString ( "ResourceEditor.ResourceCodeGeneratorTool.ClassConflict" ) , inputFilePath , existingClass . FullyQualifiedName ) ) ;
return ;
}
}
}
}
IResourceReader reader ;
if ( string . Equals ( Path . GetExtension ( inputFilePath ) , ".resx" , StringComparison . OrdinalIgnoreCase ) ) {
reader = new ResXResourceReader ( inputFilePath ) ;
@ -53,6 +72,33 @@ namespace ResourceEditor
@@ -53,6 +72,33 @@ namespace ResourceEditor
createInternalClass , // internal class
out unmatchable
) ) ;
foreach ( string s in unmatchable ) {
context . MessageView . AppendLine ( String . Format ( System . Globalization . CultureInfo . CurrentCulture , ResourceService . GetString ( "ResourceEditor.ResourceCodeGeneratorTool.CouldNotGenerateResourceProperty" ) , s ) ) ;
}
}
/// <summary>
/// Determines whether the specified class is a generated resource
/// class, based on the attached attributes.
/// </summary>
static bool IsGeneratedResourceClass ( IClass @class )
{
IClass generatedCodeAttributeClass = @class . ProjectContent . GetClass ( "System.CodeDom.Compiler.GeneratedCodeAttribute" , 0 ) ;
if ( generatedCodeAttributeClass = = null ) {
LoggingService . Info ( "Could not find the class for 'System.CodeDom.Compiler.GeneratedCodeAttribute'." ) ;
return false ;
}
IReturnType generatedCodeAttribute = generatedCodeAttributeClass . DefaultReturnType ;
foreach ( IAttribute att in @class . Attributes ) {
if ( att . AttributeType . Equals ( generatedCodeAttribute ) & &
att . PositionalArguments . Count = = 2 & &
String . Equals ( "System.Resources.Tools.StronglyTypedResourceBuilder" , att . PositionalArguments [ 0 ] as string , StringComparison . Ordinal ) ) {
return true ;
}
}
return false ;
}
}