Skip to content

Commit

Permalink
Updating C# atoms generation to use lazy-loaded dictionary for proper…
Browse files Browse the repository at this point in the history
…ties
  • Loading branch information
jimevans committed Dec 3, 2013
1 parent da2ae56 commit ab70e03
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions rake-tasks/crazy_fun/mappings/javascript.rb
Original file line number Diff line number Diff line change
Expand Up @@ -909,7 +909,7 @@ def write_atom_string_literal(to_file, dir, atom, language, utf8 = true)
elsif language == :java
line_format = " .append\(\"%s\"\)"
elsif language == :csharp
line_format = " atom.Append\(\"%s\"\);"
line_format = " atom.Append\(\"%s\"\);"
end

to_file << "\n"
Expand All @@ -923,7 +923,10 @@ def write_atom_string_literal(to_file, dir, atom, language, utf8 = true)
to_file << " {\n"
to_file << " get\n"
to_file << " {\n"
to_file << " StringBuilder atom = new StringBuilder();\n"
to_file << " const string atomName = \"#{atom_name}\";\n"
to_file << " if (!atomsRepository.ContainsKey(atomName))\n"
to_file << " {\n"
to_file << " StringBuilder atom = new StringBuilder();\n"
end

# Make the header file play nicely in a terminal: limit lines to 80
Expand Down Expand Up @@ -955,7 +958,10 @@ def write_atom_string_literal(to_file, dir, atom, language, utf8 = true)
elsif language == :cpp
to_file << ",\n NULL\n};\n"
elsif language == :csharp
to_file << "\n return atom.ToString();\n"
to_file << "\n atomsRepository[atomName] = atom.ToString();\n"
to_file << " }\n"
to_file << "\n"
to_file << " return atomsRepository[atomName];\n"
to_file << " }\n"
to_file << " }\n"
end
Expand Down Expand Up @@ -1105,6 +1111,7 @@ def generate_csharp(dir, name, task_name, output, js_files, package)
out << COPYRIGHT
out << "\n"
out << "using System.CodeDom.Compiler;\n"
out << "using System.Collections.Generic;\n"
out << "using System.Text;\n"
out << "\n"
out << "namespace #{package}\n"
Expand All @@ -1116,7 +1123,8 @@ def generate_csharp(dir, name, task_name, output, js_files, package)
out << " */\n"
out << " [GeneratedCode(\"WebDriver\", \"#{version}\")]\n"
out << " public static class #{class_name}\n"
out << " {"
out << " {\n"
out << " private static Dictionary<string, string> atomsRepository = new Dictionary<string, string>();\n"

js_files.each do |js_file|
write_atom_string_literal(out, dir, js_file, :csharp)
Expand Down

0 comments on commit ab70e03

Please sign in to comment.