Skip to content

Instantly share code, notes, and snippets.

View rippinrobr's full-sized avatar

Rob Rowe rippinrobr

View GitHub Profile
@rippinrobr
rippinrobr / gist:655350
Created October 30, 2010 14:38
The method used to create a classes properties
def define_property(tb, name, type, attributes=FieldAttributes.Public)
@rippinrobr
rippinrobr / gist:655360
Created October 30, 2010 14:48
key statements in the GenerateAssembly.initialize method
# atually creates the dynamic assembly and then the dynamic module
@assembly = AppDomain.CurrentDomain.DefineDynamicAssembly(@asm,
AssemblyBuilderAccess.RunAndSave)
@mod_builder = @assembly.DefineDynamicModule("#{@asm.Name}",
@dll_name,
false)
@rippinrobr
rippinrobr / gist:655368
Created October 30, 2010 14:54
CodeGen.create_models and CodeGen.create_model methods
def create_models
# The where method here is from System.Linq
@elem_svc.get_views.where( lambda{ |w| w.end_date.nil? }).each do |e|
create_model(e)
end
end
# Creates each individual model for the assembly and queues up
# the domain level classes that are need to support the models
def create_model(view_obj)
@rippinrobr
rippinrobr / gist:655372
Created October 30, 2010 14:59
GenerateAssembly.define_class method
#-------------------------------------------------------------
# Creates the class type and returns it to the calling method.
# Any fields, properties, or methods will need the object. If
# no interface is need the simple call is made creating the
# type object as a Public class. The first two parameters are
# the same in both DefineType calls. In the cases where we are
# implementing an interface we need to pass in the Object
# constructor and the interface type we are implementing.
#-------------------------------------------------------------
def define_class(class_name, interface=nil)
@rippinrobr
rippinrobr / gist:655412
Created October 30, 2010 15:32
ModelGenerator.generate method
def generate(class_name, fields_to_gen)
class_obj = gen_class_type("Models", class_name)
tables = create_properties(class_obj, fields_to_gen)
model_type = class_obj.CreateType
puts "Done!"
[ model_type, tables ]
end
@rippinrobr
rippinrobr / gist:655477
Created October 30, 2010 16:31
getter method body
get_method = tb.DefineMethod("get_#{name}", get_set_attr, type, Type.EmptyTypes) prop_il.Emit(OpCodes.Ldarg_0)
prop_il.Emit(OpCodes.Ldfld, private_field)
prop_il.Emit(OpCodes.Ret)
@rippinrobr
rippinrobr / gist:655499
Created October 30, 2010 16:51
setting up the params for the setter and creating the method builder
# Define "set" accessor method for the property.
set_params = System::Collections::Generic::List.of(Type).new
set_params.add type
set_method = tb.DefineMethod("set_#{name}", get_set_attr, nil,
set_params.ToArray)
@rippinrobr
rippinrobr / gist:655516
Created October 30, 2010 17:10
creates the private field used to store the property's value
private_field = tb.DefineField("_#{name.downcase}", type,
FieldAttributes.Private)
@rippinrobr
rippinrobr / gist:655527
Created October 30, 2010 17:14
creating the property
prop = tb.DefineProperty(name, PropertyAttributes.HasDefault,
type, nil)
@rippinrobr
rippinrobr / gist:655536
Created October 30, 2010 17:19
setting the field's value to the parameter
prop_il.Emit(OpCodes.Ldarg_1)
prop_il.Emit(OpCodes.Stfld, private_field)