void WriteBind(string fieldName, string className, string viewPropertyName, string value)
 {
     if (!string.IsNullOrEmpty(value))
     {
         var match       = GetParameterMatch(value);
         var actualValue = match.Success
             ? NameUtility.SlugifyConstName(match.Groups[1].Value)
             : value;
         var bindablePropertyName = "property" + NameUtility.PascalCase(viewPropertyName);
         m_BindMethod.AddBodyLine(string.Format("RegisterBinding({0}.AddBinding({1}.{2}, {3}));", fieldName, className, bindablePropertyName, actualValue));
     }
 }
 void WriteSetOrBind(string fieldName, string className, string viewPropertyName, string value, string setFormat = "{0}.{1} = {2};")
 {
     if (!string.IsNullOrEmpty(value))
     {
         var match = GetParameterMatch(value);
         if (match.Success)
         {
             var slugifiedValue       = NameUtility.SlugifyConstName(match.Groups[1].Value);
             var bindablePropertyName = "property" + NameUtility.PascalCase(viewPropertyName);
             m_BindMethod.AddBodyLine(string.Format("RegisterBinding({0}.AddBinding({1}.{2}, {3}));", fieldName, className, bindablePropertyName, slugifiedValue));
         }
         else
         {
             m_BuildMethod.AddBodyLine(string.Format(setFormat, fieldName, viewPropertyName, value));
         }
     }
 }
        void GeneratePropertyInternal(string type, string name, string fieldName, string pptName, string getterContent, string setterContent, string fieldType = null)
        {
            var csProperty = new CSProperty(Scope.Public, name, type);

            m_Class.AddProperty(csProperty);

            if (string.IsNullOrEmpty(getterContent))
            {
                csProperty.SetGetter("return (" + type + ")" + fieldName + ";");
            }
            else
            {
                csProperty.SetGetter(kVariableReference.Replace(getterContent, "$1") + ";");
            }

            var hasSetter = !string.IsNullOrEmpty(setterContent) ||
                            string.IsNullOrEmpty(getterContent) && string.IsNullOrEmpty(setterContent);

            if (hasSetter)
            {
                var setterMethod = new CSMethod(Scope.Private, "bool", "Set" + NameUtility.PascalCase(name))
                                   .AddArgument(type, "value");
                m_Class.AddMethod(setterMethod);

                if (!string.IsNullOrEmpty(setterContent))
                {
                    setterMethod.AddBodyLine(setterContent);
                }
                else
                {
                    var fieldTypeCast = (string.IsNullOrEmpty(fieldType) ? "" : "(" + fieldType + ")");
                    setterMethod
                    .AddBodyLine("if (" + fieldName + " != " + fieldTypeCast + "value)")
                    .AddBodyLine("{")
                    .AddBodyLine("    " + fieldName + " = " + fieldTypeCast + "value;")
                    .AddBodyLine("    return true;")
                    .AddBodyLine("}")
                    .AddBodyLine("return false;");
                }

                var dependentProperties = new HashSet <string>()
                {
                    name
                };

                if (m_PropertyGetterDependencies.ContainsKey(name))
                {
                    dependentProperties.UnionWith(m_PropertyGetterDependencies[name]);
                }

                var properties = dependentProperties.Select(p => "Properties." + NameUtility.SlugifyConstName(p)).Aggregate((l, r) => l + ", " + r);

                csProperty.SetSetter("if (" + setterMethod.name + "(value)) { SetPropertyChanged(" + properties + "); }");
            }

            m_PropertyClass.AddField(
                new CSField(
                    Scope.Public,
                    pptName,
                    "ClassProperty<" + type + ">",
                    "new StaticClassProperty<" + type + ", " + m_Class.name + ">(\"" + name + "\")",
                    CSField.Modifier.Static | CSField.Modifier.Readonly));
        }