Пример #1
0
        public ArrayType(ITypeSupplier supplier, CodeType arrayOfType) : base(arrayOfType.GetNameOrAny() + "[]")
        {
            ArrayOfType   = arrayOfType;
            ArrayHandler  = arrayOfType.ArrayHandler;
            Attributes    = arrayOfType.Attributes;
            TypeSemantics = arrayOfType.TypeSemantics;
            AsReferenceResetSettability = arrayOfType.AsReferenceResetSettability;
            DebugVariableResolver       = new Debugger.ArrayResolver(ArrayOfType?.DebugVariableResolver, ArrayOfType?.GetName(), ArrayOfType is ClassType);

            Generics = new[] { arrayOfType };

            _length = new InternalVar("Length", supplier.Number(), CompletionItemKind.Property)
            {
                Ambiguous = false
            };
            _last = new InternalVar("Last", ArrayOfType, CompletionItemKind.Property)
            {
                Ambiguous = false
            };
            _first = new InternalVar("First", ArrayOfType, CompletionItemKind.Property)
            {
                Ambiguous = false
            };
            _supplier = supplier;
        }
        public ArrayType(CodeType arrayOfType) : base((arrayOfType?.Name ?? "define") + "[]")
        {
            ArrayOfType           = arrayOfType;
            DebugVariableResolver = new Debugger.ArrayResolver(ArrayOfType?.DebugVariableResolver, ArrayOfType?.GetName(), ArrayOfType is ClassType);

            _length = new InternalVar("Length", CompletionItemKind.Property);
            _last   = new InternalVar("Last", ArrayOfType, CompletionItemKind.Property);
            _first  = new InternalVar("First", ArrayOfType, CompletionItemKind.Property);

            _scope.AddNativeVariable(_length);
            _scope.AddNativeVariable(_last);
            _scope.AddNativeVariable(_first);

            // Filtered Array
            new GenericSortFunction()
            {
                Name                   = "FilteredArray",
                Documentation          = "A copy of the specified array with any values that do not match the specified condition removed.",
                ReturnType             = this,
                ArrayOfType            = ArrayOfType,
                ParameterDocumentation = "The condition that is evaluated for each element of the copied array. If the condition is true, the element is kept in the copied array."
            }.Add <V_FilteredArray>(_scope);
            // Sorted Array
            new GenericSortFunction()
            {
                Name                   = "SortedArray",
                Documentation          = "A copy of the specified array with the values sorted according to the value rank that is evaluated for each element.",
                ReturnType             = this,
                ArrayOfType            = ArrayOfType,
                ParameterDocumentation = "The value that is evaluated for each element of the copied array. The array is sorted by this rank in ascending order."
            }.Add <V_SortedArray>(_scope);
            // Is True For Any
            new GenericSortFunction()
            {
                Name                   = "IsTrueForAny",
                Documentation          = "Whether the specified condition evaluates to true for any value in the specified array.",
                ArrayOfType            = ArrayOfType,
                ParameterDocumentation = "The condition that is evaluated for each element of the specified array."
            }.Add <V_IsTrueForAny>(_scope);
            // Is True For All
            new GenericSortFunction()
            {
                Name                   = "IsTrueForAll",
                Documentation          = "Whether the specified condition evaluates to true for every value in the specified array.",
                ArrayOfType            = ArrayOfType,
                ParameterDocumentation = "The condition that is evaluated for each element of the specified array."
            }.Add <V_IsTrueForAll>(_scope);
            // Mapped
            new GenericSortFunction()
            {
                Name                   = "Map",
                Documentation          = "Whether the specified condition evaluates to true for every value in the specified array.",
                ArrayOfType            = ArrayOfType,
                ParameterDocumentation = "The condition that is evaluated for each element of the specified array."
            }.Add <V_MappedArray>(_scope);
            // Contains
            Func(new FuncMethodBuilder()
            {
                Name            = "Contains",
                Documentation   = "Wether the array contains the specified value.",
                DoesReturnValue = true,
                Parameters      = new CodeParameter[] {
                    new CodeParameter("value", "The value that is being looked for in the array.", ArrayOfType)
                },
                Action = (actionSet, methodCall) => Element.Part <V_ArrayContains>(actionSet.CurrentObject, methodCall.ParameterValues[0])
            });
            // Random
            Func(new FuncMethodBuilder()
            {
                Name            = "Random",
                Documentation   = "Gets a random value from the array.",
                DoesReturnValue = true,
                ReturnType      = ArrayOfType,
                Action          = (actionSet, methodCall) => Element.Part <V_RandomValueInArray>(actionSet.CurrentObject)
            });
            // Randomize
            Func(new FuncMethodBuilder()
            {
                Name            = "Randomize",
                Documentation   = "Returns a copy of the array that is randomized.",
                DoesReturnValue = true,
                ReturnType      = this,
                Action          = (actionSet, methodCall) => Element.Part <V_RandomizedArray>(actionSet.CurrentObject)
            });
            // Append
            Func(new FuncMethodBuilder()
            {
                Name            = "Append",
                Documentation   = "A copy of the array with the specified value appended to it.",
                DoesReturnValue = true,
                ReturnType      = this,
                Parameters      = new CodeParameter[] {
                    new CodeParameter("value", "The value that is appended to the array. If the value is an array, it will be flattened.")
                },
                Action = (actionSet, methodCall) => Element.Part <V_Append>(actionSet.CurrentObject, methodCall.ParameterValues[0])
            });
            // Remove
            Func(new FuncMethodBuilder()
            {
                Name            = "Remove",
                Documentation   = "A copy of the array with the specified value removed from it.",
                DoesReturnValue = true,
                ReturnType      = this,
                Parameters      = new CodeParameter[] {
                    new CodeParameter("value", "The value that is removed from the array.")
                },
                Action = (actionSet, methodCall) => Element.Part <V_RemoveFromArray>(actionSet.CurrentObject, methodCall.ParameterValues[0])
            });
            // Slice
            Func(new FuncMethodBuilder()
            {
                Name            = "Slice",
                Documentation   = "A copy of the array containing only values from a specified index range.",
                DoesReturnValue = true,
                ReturnType      = this,
                Parameters      = new CodeParameter[] {
                    new CodeParameter("startIndex", "The first index of the range."),
                    new CodeParameter("count", "The number of elements in the resulting array. The resulting array will contain fewer elements if the specified range exceeds the bounds of the array.")
                },
                Action = (actionSet, methodCall) => Element.Part <V_ArraySlice>(actionSet.CurrentObject, methodCall.ParameterValues[0], methodCall.ParameterValues[1])
            });
            // Index Of
            Func(new FuncMethodBuilder()
            {
                Name            = "IndexOf",
                Documentation   = "The index of a value within an array or -1 if no such value can be found.",
                DoesReturnValue = true,
                Parameters      = new CodeParameter[] {
                    new CodeParameter("value", "The value for which to search.")
                },
                Action = (actionSet, methodCall) => Element.Part <V_IndexOfArrayValue>(actionSet.CurrentObject, methodCall.ParameterValues[0])
            });
        }