Class: Divine::CsharpGenerator

Inherits:
CsharpHelperMethods show all
Defined in:
lib/divine/code_generators/csharp.rb

Overview

Responsible for generating Divine and structs classes

Instance Method Summary collapse

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



849
850
851
852
853
854
# File 'lib/divine/code_generators/csharp.rb', line 849

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]



825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
# File 'lib/divine/code_generators/csharp.rb', line 825

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_importsObject

Generate list of imports needed in generated C# classes



859
860
861
862
863
864
865
866
867
868
# File 'lib/divine/code_generators/csharp.rb', line 859

def get_csharp_imports
  [
  "System",
  "System.Collections.Generic",
  "System.Text.RegularExpressions",
  "System.IO"
    ].map do |i|
      "using #{i};"
    end.join("\n") 
end