Skip to content

Instantly share code, notes, and snippets.

@jasmarc
Created July 31, 2010 17:06
Show Gist options
  • Save jasmarc/502380 to your computer and use it in GitHub Desktop.
Save jasmarc/502380 to your computer and use it in GitHub Desktop.
require 'yaml'
class String
def to_camel
parts = self.scan(/[A-Z]*[a-z]*/)
parts.first.downcase!
parts.join
end
end
def top(clazz)
<<EOF
using Put.Usings.Here;
namespace Your.Namespace.Here
{
public class #{clazz}Wrapper : BaseWrapper
{
private #{clazz} _#{clazz.to_camel};
internal #{clazz}Wrapper(#{clazz} #{clazz.to_camel})
{
_#{clazz.to_camel} = #{clazz.to_camel};
}
EOF
end
def prop(clazz, var, typ)
<<EOF
public #{typ} #{var}
{
get { return _#{clazz.to_camel}.#{var}; }
set
{
if (ValueChanged(_#{clazz.to_camel}.#{var}, value))
{
_#{clazz.to_camel}.#{var} = value;
NotifyPropertyChanged("#{var}");
}
}
}
EOF
end
def endd
<<EOF
}
}
EOF
end
File.open("API.yaml") do |ydoc|
YAML.load(ydoc).each_pair do |clazz, properties|
puts top clazz
properties.each_pair do |var,typ|
puts prop(clazz, var, typ)
end
puts endd
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment