Example #1
0
        /// <summary>Gets the workshop value of a macro.</summary>
        public static IWorkshopTree CallMacroFunction(ActionSet actionSet, DefinedMethodInstance macro, MethodCall methodCall)
        {
            actionSet = actionSet.ContainVariableAssigner().PackThis();

            // The list containing the macro and all of its overriders, recursively.
            var allOptions = new List <MacroOption>();

            allOptions.Add(new MacroOption(macro));

            // Add overriders to the list.
            var relations = new MethodClassRelations(actionSet.ToWorkshop, macro);

            if (relations.Overriders != null)
            {
                allOptions.AddRange(relations.Overriders.Select(overrider => new MacroOption(overrider)));
            }

            // Add parameters to the assigner.
            for (int i = 0; i < macro.ParameterVars.Length; i++)
            {
                // Origin parameter variables
                actionSet.IndexAssigner.Add(macro.ParameterVars[i].Provider, methodCall.ParameterValues[i]);

                // Overrider parameter variables.
                foreach (var overrider in relations.Overriders)
                {
                    actionSet.IndexAssigner.Add(overrider.ParameterVars[i].Provider, methodCall.ParameterValues[i]);
                }
            }

            // Create the virtual content builder and then return the resulting value.
            var virtualContentBuilder = new MacroContentBuilder(actionSet, allOptions);

            return(virtualContentBuilder.Value);
        }
Example #2
0
        public UserFunctionController(ToWorkshop toWorkshop, DefinedMethodInstance function, InstanceAnonymousTypeLinker typeArgs)
        {
            _toWorkshop    = toWorkshop;
            _function      = function;
            _typeArgLinker = typeArgs;
            _allVirtualOptions.Add(function);

            Attributes.IsRecursive = function.Attributes.Recursive;

            // If the function is defined in a type.
            if (function.DefinedInType != null)
            {
                Attributes.IsInstance = true;

                var relations = new MethodClassRelations(toWorkshop, function);

                // Get the class relation.
                _classRelation = relations.ClassRelation;

                // Extract the virtual functions.
                _allVirtualOptions.AddRange(relations.Overriders);
            }
        }