Esempio n. 1
0
        /// <summary>
        /// Creates code
        /// </summary>
        /// <param name="trees">Trees</param>
        /// <param name="creator">Code creator</param>
        /// <param name="local">Local code creator</param>
        /// <param name="variables">Variables</param>
        /// <param name="initializers">Initializers</param>
        /// <returns>List of code strings</returns>
        public static IList <string> CreateCode(ObjectFormulaTree[] trees, ICodeCreator creator, out ICodeCreator local,
                                                out IList <string> variables, out IList <string> initializers)
        {
            IList <string> l = StaticCodeCreator.CreateCode(trees, creator, out local,
                                                            out variables, out initializers);

            variables.Add("FormulaEditor.ObjectFormulaTree currentTree = null;");
            variables.Add("object[] currentArray = null;");
            variables.Add("double doubleValue = 0;");
            variables.Add("FormulaEditor.ObjectFormulaTree[] trees = null;");
            ObjectFormulaTree[] lt = local.Trees;
            foreach (ObjectFormulaTree tree in lt)
            {
                object ret = tree.ReturnType;
                if (ret.IsEmpty())
                {
                    continue;
                }
                string s = typeCreator.GetType(ret) + " ";
                s += local[tree];
                string cv  = creator.GetConstValue(tree);
                string def = "";
                if (cv == null)
                {
                    def = typeCreator.GetDefaultValue(ret) + "";
                    if (def.Length > 0)
                    {
                        s += " = ";
                    }
                    s += def;
                }
                else
                {
                    s += " = " + cv;
                }
                s += ";";
                variables.Add(s);
            }
            return(l);
        }
Esempio n. 2
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="BuildCapability" /> class.
        /// </summary>
        /// <param name="typeCreator">The type creator that provides the build functions.</param>
        /// <param name="supportsCreate">
        ///     <c>true</c> if the <paramref name="typeCreator" /> can create an instance; otherwise
        ///     <c>false</c>.
        /// </param>
        /// <param name="supportsPopulate">
        ///     <c>true</c> if the <paramref name="typeCreator" /> can populate an instance; otherwise
        ///     <c>false</c>.
        /// </param>
        /// <exception cref="ArgumentNullException">The <paramref name="typeCreator" /> parameter is <c>null</c>.</exception>
        public BuildCapability(ITypeCreator typeCreator, bool supportsCreate, bool supportsPopulate)
        {
            typeCreator = typeCreator ?? throw new ArgumentNullException(nameof(typeCreator));

            ImplementedByType = typeCreator.GetType();
            SupportsCreate    = supportsCreate;
            SupportsPopulate  = supportsPopulate;
            AutoPopulate      = typeCreator.AutoPopulate;

            _createType      = typeCreator.Create;
            _createProperty  = typeCreator.Create;
            _createParameter = typeCreator.Create;
            _populate        = typeCreator.Populate;
        }