<commit_before>#!/usr/bin/env ruby

models_path = File.dirname(__FILE__)

puts "Transmogrifying any default properties to PropertySet() in: #{models_path}"

regex = /public\s([a-zA-Z\?]*)\s([a-zA-Z]*)\s{ get; set; }/

# match group \1 is the property type, \2 is the property name
replace_with = <<-eos
private \\1 _\\2;
        public \\1 \\2
        {
            get { return _\\2; }
            set {
                SetProperty(ref _\\2, value);
            }
        }
eos

cs_glob = File.join(models_path, "*.cs")

Dir.glob(cs_glob) do |cs_file|
  puts "... #{cs_file}"
  cs_file_path = File.join(models_path, cs_file)

  cs_file_contents = File.read(cs_file_path)
  puts "... ... #{cs_file_contents.length}"

  
  transmog = cs_file_contents.gsub(regex, replace_with)
  puts transmog
end<commit_msg>Propify.rb now writes changes to the cs files.<commit_after>#!/usr/bin/env ruby

# Replace simple { get; set; } flat properties with
# explicitly generated (and sadly boilerplatey) prop
# getter and setters that call SetProperty() in order
# to make our IPropertyChangedRegime work.

# Obviously a bit naiively and regexy, but it works.
# I didn't want to use Fody or a Weaver because of lack
# of MonoDevelop/xbuild support.

models_path = File.dirname(__FILE__)

puts "Transmogrifying any default properties to PropertySet() in: #{models_path}"

regex = /public\s([a-zA-Z\?\<\>]*)\s([a-zA-Z]*)\s{ get; set; }/

# match group \1 is the property type, \2 is the property name
replace_with = <<-eos
private \\1 _\\2;
        public \\1 \\2
        {
            get { return _\\2; }
            set {
                SetProperty(ref _\\2, value);
            }
        }
eos

cs_glob = File.join(models_path, "*.cs")

Dir.glob(cs_glob) do |cs_file|
  puts "... #{cs_file}"
  cs_file_path = File.join(models_path, cs_file)

  cs_file_contents = ""
  fd = File.open(cs_file_path, "rb") do |fd|
    cs_file_contents = fd.read()
  end
  
  transmog = cs_file_contents.gsub(regex, replace_with)

  fd = File.open(cs_file_path, "wb") do |fd|
    fd.write(transmog)
  end
end
{'fraction_non_alphanumeric': 0.1403085824493732, 'fraction_numerical': 0.007714561234329798, 'mean_word_length': 2.765880217785844, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5563735', 'n_tokens_mistral': 762, 'n_tokens_neox': 733, 'n_words': 198}