コード例 #1
0
        private CodeGenerationParameter CreateGenerationParameter(string parameter)
        {
            string paramWithoutIdentifiers = parameter.Replace("###", "");

            string[] split = paramWithoutIdentifiers.Split(new char[] { ':' }, 2, StringSplitOptions.RemoveEmptyEntries);

            if (split.Length != 2)
            {
                Debug.LogError("Invalid structure for parameter. Should be ###IDENTIFIER:TYPE###. Instead found " + parameter);
                return(null);
            }

            string identifier = split[0].Trim();
            string typeStr    = split[1].Trim();

            Type type = MatchType(typeStr);

            if (type == null)
            {
                Debug.LogError("Could not match type for " + parameter + "\nType string recognized as: " + typeStr);
                return(null);
            }

            CodeGenerationParameter generationParameter = new CodeGenerationParameter();

            generationParameter.Identifier        = identifier;
            generationParameter.ParameterType     = typeStr;
            generationParameter.ReplacementString = parameter;

            return(generationParameter);
        }
コード例 #2
0
        private void ParseParameters(string template)
        {
            parameters.Clear();

            Dictionary <string, CodeGenerationParameter> extractedParameters = new Dictionary <string, CodeGenerationParameter>();

            int paramStartIndex = template.IndexOf(PARAMETER_IDENTIFIER);

            if (paramStartIndex < 0)
            {
                return;
            }

            do
            {
                string parameter = ExtractParameter(template, ref paramStartIndex);

                CodeGenerationParameter generationParameter = CreateGenerationParameter(parameter);

                if (generationParameter != null && !extractedParameters.ContainsKey(generationParameter.Identifier))
                {
                    extractedParameters.Add(generationParameter.Identifier, generationParameter);
                }
            } while (paramStartIndex >= 0);

            parameters.AddRange(extractedParameters.Values);
        }