예제 #1
0
        void Build(DOMCommand command)
        {
            Assert.IsFalse(string.IsNullOrEmpty(command.name), "name is required for <command />");

            var pptName = NameUtility.SlugifyConstName(command.name);

            var parametricArgs = string.Empty;

            if (command.args != null && command.args.Length > 0)
            {
                var builder = new StringBuilder();
                builder.Append("<");
                for (int i = 0; i < command.args.Length; i++)
                {
                    if (i > 0)
                    {
                        builder.Append(", ");
                    }
                    builder.Append(command.args[i].type);
                }
                builder.Append(">");
                parametricArgs = builder.ToString();
            }

            m_Class.AddField(
                new CSField(
                    Scope.Private,
                    pptName,
                    "IClassMethod" + parametricArgs,
                    "new DynamicClassMethod" + parametricArgs + "(\"" + command.name + "\")",
                    CSField.Modifier.Static | CSField.Modifier.Readonly));
        }
예제 #2
0
 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));
     }
 }
예제 #3
0
        void Build(DOMProperty property)
        {
            Assert.IsFalse(string.IsNullOrEmpty(property.type), "type is required for <property />");
            Assert.IsFalse(string.IsNullOrEmpty(property.name), "name is required for <property />");

            var pptName = NameUtility.SlugifyConstName(property.name);

            m_Class.AddField(
                new CSField(
                    Scope.Private,
                    pptName,
                    "ClassProperty<" + property.type + ">",
                    "new DynamicClassProperty<" + property.type + ">(\"" + property.name + "\")",
                    CSField.Modifier.Static | CSField.Modifier.Readonly));
        }
예제 #4
0
        void VisitIn(DOMProperty property)
        {
            Assert.IsFalse(string.IsNullOrEmpty(property.type), "type is required for <property />");
            Assert.IsFalse(string.IsNullOrEmpty(property.name), "name is required for <property />");

            var fieldName = NameUtility.SlugifyFieldName(property.name);
            var pptName   = NameUtility.SlugifyConstName(property.name);

            var getterContent = property.getter != null ? property.getter.textContent : string.Empty;
            var setterContent = property.setter != null ? property.setter.textContent : string.Empty;

            GeneratePropertyInternal(property.type, property.name, fieldName, pptName, getterContent, setterContent);

            m_Class.AddField(new CSField(Scope.Private, fieldName, property.type, property.@default));
        }
예제 #5
0
 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));
         }
     }
 }
예제 #6
0
        void VisitIn(DOMCommand command)
        {
            Assert.IsFalse(string.IsNullOrEmpty(command.name), "name is required for <command />");

            var parametricArgs0 = string.Empty;
            var parametricArgs1 = string.Empty;

            if (command.args != null && command.args.Length > 0)
            {
                var parametricTypes = command.args.Select(a => a.type).ToArray();
                parametricArgs0 = "<" + string.Join(", ", parametricTypes) + ">";
                parametricArgs1 = ", " + string.Join(", ", parametricTypes);
            }

            m_PropertyClass.AddField(
                new CSField(
                    Scope.Public,
                    NameUtility.SlugifyConstName(command.name),
                    "IClassMethod" + parametricArgs0, "new StaticClassMethod<" + m_Class.name + parametricArgs1 + ">(\"" + command.name + "\")",
                    CSField.Modifier.Static | CSField.Modifier.Readonly));
        }
예제 #7
0
        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));
        }
예제 #8
0
        void VisitIn(DOMSerializedProperty serializedProperty)
        {
            Assert.IsFalse(string.IsNullOrEmpty(serializedProperty.name), "name is required for <serialized-property />");

            var type = string.Empty;

            switch (serializedProperty.type)
            {
            case DOMSerializedProperty.Type.Object:
            case DOMSerializedProperty.Type.Enum:
            {
                type = serializedProperty.customType;
                break;
            }

            case DOMSerializedProperty.Type.AnimationCurve:
            case DOMSerializedProperty.Type.Bounds:
            case DOMSerializedProperty.Type.Vector2:
            case DOMSerializedProperty.Type.Vector3:
            case DOMSerializedProperty.Type.Vector4:
            case DOMSerializedProperty.Type.Color:
            case DOMSerializedProperty.Type.Rect:
            case DOMSerializedProperty.Type.Quaternion:
            {
                type = serializedProperty.type.ToString();
                break;
            }

            default:
            {
                type = serializedProperty.type.ToString().ToLowerInvariant();
                break;
            }
            }

            var pptName   = NameUtility.SlugifyConstName(serializedProperty.name);
            var fieldName = "this[\"" + serializedProperty.name + "\"]";
            var fieldType = (string)null;

            switch (serializedProperty.type)
            {
            case DOMSerializedProperty.Type.AnimationCurve: fieldName += ".animationCurveValue"; break;

            case DOMSerializedProperty.Type.Bool: fieldName += ".boolValue"; break;

            case DOMSerializedProperty.Type.Bounds: fieldName += ".boundsValue"; break;

            case DOMSerializedProperty.Type.Color: fieldName += ".colorValue"; break;

            case DOMSerializedProperty.Type.Double: fieldName += ".doubleValue"; break;

            case DOMSerializedProperty.Type.Enum: fieldName += ".enumValueIndex"; fieldType = "int"; break;

            case DOMSerializedProperty.Type.Float: fieldName += ".floatValue"; break;

            case DOMSerializedProperty.Type.Int: fieldName += ".intValue"; break;

            case DOMSerializedProperty.Type.Long: fieldName += ".longValue"; break;

            case DOMSerializedProperty.Type.Object: fieldName += ".objectReferenceValue"; break;

            case DOMSerializedProperty.Type.Quaternion: fieldName += ".quaternionValue"; break;

            case DOMSerializedProperty.Type.String: fieldName += ".stringValue"; break;

            case DOMSerializedProperty.Type.Vector2: fieldName += ".vector2Value"; break;

            case DOMSerializedProperty.Type.Vector3: fieldName += ".vector3Value"; break;

            case DOMSerializedProperty.Type.Vector4: fieldName += ".vector4Value"; break;

            case DOMSerializedProperty.Type.Rect: fieldName += ".rectValue"; break;

            default: throw new NotSupportedException("Not supported type: " + serializedProperty.type);
            }

            GeneratePropertyInternal(type, serializedProperty.name, fieldName, pptName, null, null, fieldType);
        }