Browse files

Added Reference and Resource file addition capabilities to assemblyGe…

…nerator with an intention to expand the dynamic compilation and execution capabilities.

Now passing a string of ClassNames instead of list of ClassProperties
  • Loading branch information...
1 parent 062090d commit d97dc4816af6e0d6d3f81da139b4f635d89024dd @shashankshetty shashankshetty committed Jun 25, 2009
View
8 src/ExcelMapper.Tests/Service/AssemblyGeneratorTests.cs
@@ -21,11 +21,13 @@ public class When_given_a_list_of_class_files
private List<ClassProperties> _classPropertiesList;
private AssemblyProperties _assemblyProperties;
private const string LogFile = "TestLog";
+ private string[] _classNames;
[SetUp]
public void SetUp()
{
const string nameSpace = "Assembly.User";
+
_classProperties = new ClassProperties("User")
{
NameSpace = nameSpace,
@@ -40,7 +42,7 @@ public void SetUp()
"System.String"
}
};
-
+ _classNames = new[] { _classProperties.FullName };
_classPropertiesList = new List<ClassProperties>
{
_classProperties
@@ -64,7 +66,7 @@ public void TearDown()
public void Should_generate_an_assembly()
{
_classGenerator.Create(_classProperties);
- Assert.IsTrue(_assemblyGenerator.Compile(_classPropertiesList, _assemblyProperties, LogFile));
+ Assert.IsTrue(_assemblyGenerator.Compile(_classNames, _assemblyProperties, LogFile));
Assert.IsTrue(File.Exists(_assemblyProperties.FullName));
}
@@ -74,7 +76,7 @@ public void Should_generate_an_errorLog_if_it_cannot_compile_the_assembly()
_classProperties.PropertyType[0] = "Double";
_classGenerator.Create(_classProperties);
- Assert.IsFalse(_assemblyGenerator.Compile(_classPropertiesList, _assemblyProperties, LogFile));
+ Assert.IsFalse(_assemblyGenerator.Compile(_classNames, _assemblyProperties, LogFile));
Assert.IsTrue(File.Exists(LogFile));
}
}
View
3 src/ExcelMapper/ExcelToDTOMapper.cs
@@ -1,4 +1,5 @@
using System.Collections.Generic;
+using System.Linq;
using ExcelMapper.DTO;
using ExcelMapper.Repository;
@@ -39,7 +40,7 @@ public bool Run(string assemblyName, List<string> files)
}
}
return ((classPropertiesList.Count > 0)
- && _assemblyGenerator.Compile(classPropertiesList, new AssemblyProperties(assemblyName), DefaultSettings.LogFile));
+ && _assemblyGenerator.Compile(classPropertiesList.Select(x => x.FullName).ToArray(), new AssemblyProperties(assemblyName), DefaultSettings.LogFile));
}
}
}
View
10 src/ExcelMapper/Service/AssemblyGenerator.cs
@@ -20,7 +20,7 @@ public AssemblyGenerator(IFileWriter fileWriter)
_fileWriter = fileWriter;
}
- public bool Compile(List<ClassProperties> classPropertiesList, AssemblyProperties assemblyProperties, string logFile)
+ public bool Compile(string[] classNames, AssemblyProperties assemblyProperties, string logFile)
{
CSharpCodeProvider codeProvider = new CSharpCodeProvider(new Dictionary<string, string>
{
@@ -31,11 +31,11 @@ public bool Compile(List<ClassProperties> classPropertiesList, AssemblyPropertie
{
OutputAssembly = assemblyProperties.FullName
};
-
- //assemblyProperties.References.Select(reference => parameters.ReferencedAssemblies.Add(reference));
- //assemblyProperties.Resources.Select(resource => parameters.EmbeddedResources.Add(resource));
- CompilerResults compilerResults = codeProvider.CompileAssemblyFromFile(parameters, classPropertiesList.Select(x => x.FullName).ToArray());
+ parameters.ReferencedAssemblies.AddRange(assemblyProperties.References.ToArray());
+ parameters.EmbeddedResources.AddRange(assemblyProperties.Resources.ToArray());
+
+ CompilerResults compilerResults = codeProvider.CompileAssemblyFromFile(parameters, classNames);
GenerateErrorReport(compilerResults.Errors, logFile);
View
4 src/ExcelMapper/Service/IAssemblyGenerator.cs
@@ -1,11 +1,9 @@
-using System.Collections.Generic;
-
using ExcelMapper.DTO;
namespace ExcelMapper.Service
{
public interface IAssemblyGenerator
{
- bool Compile(List<ClassProperties> classPropertiesList, AssemblyProperties assemblyProperties, string logFile);
+ bool Compile(string[] classNames, AssemblyProperties assemblyProperties, string logFile);
}
}

0 comments on commit d97dc48

Please sign in to comment.