Skip to content

Instantly share code, notes, and snippets.

@jmlyn
Created October 22, 2016 05:37
Show Gist options
  • Select an option

  • Save jmlyn/2860520af8866933eaefffcc79b70ea5 to your computer and use it in GitHub Desktop.

Select an option

Save jmlyn/2860520af8866933eaefffcc79b70ea5 to your computer and use it in GitHub Desktop.
C# property generator in ruby
vars = {
"DoesNotBlockInput" => "bool",
"Invisible" => "bool",
"OntopDoober" => "bool",
"OntopOfBuilding" => "bool",
"CenterOfCollider" => "bool",
"ShowDimmer" => "bool",
"DoesNotSendClickMessage" => "bool",
"HideOnClickMiss" => "bool",
"DoesNotHideOnClick" => "bool",
"LookAtTreatment" => "bool",
"TargetName" => "string",
"ArrowText" => "string",
"Location" => "ArrowLocation?",
"TargetSet" => "Type",
"Scale" => "Vector2",
"CustomOffset" => "Vector3",
"TargetPos" => "Vector3?",
"PerspectiveCamera" => "Camera",
"Target" => "GameObject"
}
def gen_prop(access, class_name, var_name, type)
if type == "bool"
return access + " " + class_name + " " + var_name + " { get { _" + var_name + " = true; return this; } }\n"
else
var_camel = var_name[0].downcase
var_camel.concat var_name[1..var_name.length - 1]
return access + " " + class_name + " " + var_name + " (" + type + " " + var_camel + ") { _"+ var_name + " = " + var_camel + "; return this; }\n"
end
end
def gen_var(access, class_name, var_name, type)
return access + " " + type + " _" + var_name + ";"
end
vars.each {|key, value|
puts gen_prop("public", "ArrowConfig", key, value)
puts gen_var("public", "ArrowConfig", key, value)
puts "\n"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment