Exemple #1
0
        private static void GenerateComponent(ComponentDefinition componentDefinition)
        {
            // Paths
            var componentsPath = componentDefinition.Directory;

            if (componentsPath.EndsWith("Components"))
            {
                componentsPath = PathExtension.SystemPath(componentsPath);
            }
            else
            {
                componentsPath = PathExtension.SystemPath(Path.Combine(componentsPath, "Components"));
            }
            if (!Directory.Exists(componentsPath))
            {
                Directory.CreateDirectory(componentsPath);
            }

            var template = CodeGeneratorUtils.LoadTemplate("Component");

            var processors = ProcessorsSelector.Selectors <ICodeGeneratorComponentProcessors>();

            foreach (var processor in processors)
            {
                template = processor.Process(componentDefinition, template);
            }

            var upperedComponentName = componentDefinition.ComponentName.ToUpperFirstChar();
            var componentPath        = Path.Combine(componentsPath, $"{upperedComponentName}.cs");

            GenerateComponentFile(upperedComponentName, componentPath, template);
        }
Exemple #2
0
        public string Process(ComponentDefinition componentDefinition, string template)
        {
            var dotCompoennts = ".Components";
            var namespaceName = componentDefinition.Namespace;

            if (namespaceName.EndsWith(dotCompoennts))
            {
                namespaceName = namespaceName.Substring(0, namespaceName.Length - dotCompoennts.Length);
            }
            return(s_namespaceRegex.Replace(template, namespaceName));
        }
Exemple #3
0
        public string Process(ComponentDefinition componentDefinition, string template)
        {
            // Namespaces
            var usingNamespaces = componentDefinition.Fields
                                  .Where(f => f.type.Type != null)
                                  .Select(f => f.type.Type.Namespace)
                                  .Distinct()
                                  .Except(typeof(IPrimitiveType).Namespace.Yield());

            StringBuilder usingsBuilder = new StringBuilder();

            foreach (var usingNamespace in usingNamespaces)
            {
                usingsBuilder.Append("using ");
                usingsBuilder.Append(usingNamespace);
                usingsBuilder.AppendLine(";");
            }

            template = s_usingsRegex.Replace(template, usingsBuilder.ToString());
            return(template);
        }
Exemple #4
0
        public string Process(ComponentDefinition componentDefinition, string template)
        {
            var fieldsBuilder = new StringBuilder();

            foreach (var field in componentDefinition.Fields)
            {
                if (field.type.Type != null)
                {
                    if (typeof(IPrimitiveType).IsAssignableFrom(field.type.Type))
                    {
                        IPrimitiveType primitiveType = Activator.CreateInstance(field.type.Type) as IPrimitiveType;
                        fieldsBuilder.AppendLine(primitiveType.GetFieldDeclaration(field.name, FieldAccessType(field.accessType)));
                    }
                    else
                    {
                        fieldsBuilder.AppendLine($"\t\t{FieldAccessType( field.accessType )} {field.type.Type.Name} {field.name};");
                    }
                }
            }

            return(s_fieldsRegex.Replace(template, fieldsBuilder.ToString()));
        }
Exemple #5
0
 public static void Generate(ComponentDefinition componentDefinition)
 {
     GenerateComponent(componentDefinition);
     AssetDatabase.Refresh();
 }
Exemple #6
0
        public string Process(ComponentDefinition componentDefinition, string template)
        {
            var componentInterfaceName = GetInterfaceName(componentDefinition.ComponentType);

            return(s_componentTypesRegex.Replace(template, componentInterfaceName));
        }
Exemple #7
0
        public string Process(ComponentDefinition componentDefinition, string template)
        {
            var upperedComponentName = componentDefinition.ComponentName.ToUpperFirstChar();

            return(s_nameRegex.Replace(template, upperedComponentName));
        }