コード例 #1
0
ファイル: GMacCodeBlock.cs プロジェクト: cloudRoutine/GMac
        /// <summary>
        /// Find all primitive parameters in this code block that are sub-components of the given
        /// macro parameter value access component
        /// </summary>
        /// <param name="paramValueAccess"></param>
        /// <returns></returns>
        public IEnumerable <IGMacCbParameterVariable> GetParameters(AstDatastoreValueAccess paramValueAccess)
        {
            var result = new List <IGMacCbParameterVariable>();

            if (paramValueAccess.IsNullOrInvalid())
            {
                return(result);
            }

            var name = paramValueAccess.ValueAccessName;

            //A single parameter is to be found
            if (paramValueAccess.IsPrimitive)
            {
                var item = ParameterVariables.FirstOrDefault(
                    p => p.ValueAccessName == name
                    );

                if (ReferenceEquals(item, null) == false)
                {
                    result.Add(item);
                }

                return(result);
            }

            //Partial multivectors require special treatment
            if (paramValueAccess.IsPartialMultivector)
            {
                var primitiveValueAccessList = paramValueAccess.ExpandAll();

                foreach (var primitiveValueAccess in primitiveValueAccessList)
                {
                    IGMacCbParameterVariable paramVar;

                    if (TryGetParameterVariable(primitiveValueAccess, out paramVar))
                    {
                        result.Add(paramVar);
                    }
                }

                return(result);
            }

            //All other cases can be searched by name
            name = name + ".";

            result.AddRange(
                ParameterVariables.Where(
                    p => p.ValueAccessName.IndexOf(name, StringComparison.Ordinal) == 0
                    )
                );

            return(result);
        }
コード例 #2
0
ファイル: GMacCodeBlock.cs プロジェクト: cloudRoutine/GMac
        /// <summary>
        /// Test if the given primitive macro parameter is used as a variable in the code block
        /// </summary>
        /// <param name="paramValueAccess"></param>
        /// <returns></returns>
        public bool IsParameterVariable(AstDatastoreValueAccess paramValueAccess)
        {
            var name = paramValueAccess.ValueAccessName;

            if (_parametersDictionary.Count > 0)
            {
                return(_parametersDictionary.ContainsKey(name));
            }

            return(ParameterVariables.FirstOrDefault(
                       item => item.ValueAccess.ValueAccessName == name
                       ) != null);
        }
コード例 #3
0
ファイル: GMacCodeBlock.cs プロジェクト: cloudRoutine/GMac
        /// <summary>
        /// Try to get a parameter variable by its associated datastore value access
        /// </summary>
        /// <param name="paramValueAccess"></param>
        /// <param name="paramVar"></param>
        /// <returns></returns>
        public bool TryGetParameterVariable(AstDatastoreValueAccess paramValueAccess, out IGMacCbParameterVariable paramVar)
        {
            var name = paramValueAccess.ValueAccessName;

            if (_parametersDictionary.Count > 0)
            {
                return(_parametersDictionary.TryGetValue(name, out paramVar));
            }

            paramVar = ParameterVariables.FirstOrDefault(
                item => item.ValueAccess.ValueAccessName == name
                );

            return(paramVar != null);
        }