Exemple #1
0
        static Array fromText(Value target, Value value)
        {
            var fields        = State.FieldPattern.Split(value.Text);
            var fieldQueue    = new Queue <string>(fields);
            var parameters    = (Parameters)target;
            var variableNames = parameters.VariableNames;
            var varQueue      = new Queue <string>(variableNames);

            while (varQueue.Count > 0)
            {
                var variableName = varQueue.Dequeue();
                var field        = fieldQueue.Count > 0 ? fieldQueue.Dequeue() : "";
                if (varQueue.Count == 0 && fieldQueue.Count > 0)
                {
                    var fieldList = new List <string> {
                        field
                    };
                    while (fieldQueue.Count > 0)
                    {
                        fieldList.Add(fieldQueue.Dequeue());
                    }

                    field = fieldList.Listify(State.FieldSeparator.Text);
                }

                Regions.CreateVariableIfNonexistant(variableName);
                Regions[variableName] = ConvertIfNumeric(field);
            }

            return(new Array(fields));
        }
Exemple #2
0
        static Array fromObject(Parameters target, Object source)
        {
            var array = new Array();

            foreach (var variableName in target.VariableNames)
            {
                if (SendMessage(source, variableName) is Variable variable)
                {
                    var value = variable.Value;
                    Regions.CreateVariableIfNonexistant(variableName);
                    Regions[variableName] = value;
                    array[variableName]   = value;
                }
            }

            return(array);
        }
Exemple #3
0
        public static Array FromFields(Array sourceArray, Parameters parameters, bool readOnly = false)
        {
            var length           = sourceArray.Length;
            var parametersLength = parameters.Length;
            var minLength        = Min(length, parametersLength);

            for (var i = 0; i < minLength; i++)
            {
                var parameter    = parameters[i];
                var variableName = parameter.Name;
                Regions.CreateVariableIfNonexistant(variableName);
                Regions[variableName] = ConvertIfNumeric(sourceArray[i]);
            }

            if (length > minLength)
            {
                if (minLength == 0)
                {
                    return(new Array());
                }

                var parameter    = parameters[minLength - 1];
                var variableName = parameter.Name;
                var lastValue    = Regions[variableName];
                var array        = new Array {
                    lastValue
                };
                for (var i = minLength; i < length; i++)
                {
                    array.Add(ConvertIfNumeric(sourceArray[i]));
                }

                Regions.CreateVariableIfNonexistant(variableName);
                Regions[variableName] = array;
                if (parameter.ReadOnly)
                {
                    Regions.SetReadOnly(variableName);
                }
            }
            else if (parametersLength > minLength)
            {
                for (var i = minLength; i < parametersLength; i++)
                {
                    var parameter    = parameters[i];
                    var variableName = parameter.Name;
                    Regions.CreateVariableIfNonexistant(variableName);
                    Regions[variableName] = ConvertIfNumeric(parameter.DefaultValue?.Evaluate() ?? "");
                    if (parameter.ReadOnly)
                    {
                        Regions.SetReadOnly(variableName);
                    }
                }
            }

            var result = new Array();

            for (var i = 0; i < parametersLength; i++)
            {
                var name = parameters[i].Name;
                result[name] = Regions[name];
            }

            return(result);
        }