Class: Divine::CsharpGenerator
- Inherits:
-
CsharpHelperMethods
- Object
- BabelHelperMethods
- CsharpHelperMethods
- Divine::CsharpGenerator
- Defined in:
- lib/divine/code_generators/csharp.rb
Overview
Responsible for generating Divine and structs classes
Instance Method Summary collapse
-
#csharp_get_begin_module(opts) ⇒ Object
Build header comments and list of imports.
-
#generate_code(structs, opts) ⇒ Object
Generate csharp class(es) * Args : -
structs
-> Dictionary of structs -opts
-> Dictionary that contains generation params [file, debug, parent_class, target_dir]. -
#get_csharp_imports ⇒ Object
Generate list of imports needed in generated C# classes.
Methods inherited from CsharpHelperMethods
#csharp_base_class_template_str, #csharp_class_template, #csharp_deserialize_internal, #csharp_get_empty_declaration, #csharp_get_type_declaration, #csharp_serialize_internal, #get_header_comment
Methods inherited from BabelHelperMethods
#camelize, #format_src, #get_fresh_variable_name, #get_header_comment_text, #sanity_check
Instance Method Details
#csharp_get_begin_module(opts) ⇒ Object
Build header comments and list of imports
875 876 877 878 879 880 |
# File 'lib/divine/code_generators/csharp.rb', line 875 def csharp_get_begin_module(opts) str = "#{get_header_comment}\n\n" str << get_csharp_imports str << "\n\n" return str end |
#generate_code(structs, opts) ⇒ Object
Generate csharp class(es)
-
Args :
-
structs
-> Dictionary of structs -
opts
-> Dictionary that contains generation params [file, debug, parent_class, target_dir]
-
851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 |
# File 'lib/divine/code_generators/csharp.rb', line 851 def generate_code(structs, opts) $debug_csharp = true if opts[:debug] base_template = Erubis::Eruby.new(csharp_base_class_template_str) keys = structs.keys.sort src = keys.map do |k| ss = structs[k] # Check different aspects the the structs vss = sanity_check(ss) csharp_class_template(StructHandler.new(vss)) end # User defined super class? toplevel = opts[:parent_class] || nil toplevel = " : #{toplevel}" if toplevel return [{ file: opts[:file], src: "#{csharp_get_begin_module(opts)}#{base_template.result({ toplevel_class: toplevel })}\n\n#{src.join("\n\n")} }" }] end |
#get_csharp_imports ⇒ Object
Generate list of imports needed in generated C# classes
885 886 887 888 889 890 891 892 893 894 |
# File 'lib/divine/code_generators/csharp.rb', line 885 def get_csharp_imports [ "System", "System.Collections.Generic", "System.Text.RegularExpressions", "System.IO" ].map do |i| "using #{i};" end.join("\n") end |