Пример #1
0
        /// <summary>
        /// グループにアセットを登録する
        /// </summary>
        /// <param name="group">登録するグループ</param>
        /// <param name="funcAssetDef">アセット</param>
        protected static void CreateAssetMenu(CommandCanvas OwnerCommandCanvas, TreeMenuNode group, IFuncCreateAssetDef funcAssetDef)
        {
            AddAsset(funcAssetDef);
            string title = TreeViewCommand.MakeGroup(ref group, funcAssetDef.MenuTitle);
            var    menu  = new TreeMenuNode(title, funcAssetDef.HelpText);

            group.AddChild(menu);
            menu.LeftClickCommand = OwnerCommandCanvas.CreateEventCanvasCommand(
                menu.Path,
                () => {
                var result = CbScript.CreateFunction(OwnerCommandCanvas, funcAssetDef.AssetCode);
                if (funcAssetDef.MenuTitle.Contains(CbSTUtils.MENU_OLD_SPECIFICATION))
                {
                    result.OldSpecification = true;
                }
                return(result);
            }
                );
        }
Пример #2
0
        /// <summary>
        /// グループにアセットを登録する
        /// </summary>
        /// <param name="group">登録するグループ</param>
        /// <param name="funcAssetDef">アセット</param>
        public static void CreateAssetMenu(CommandCanvas OwnerCommandCanvas, TreeMenuNode group, IFuncAssetLiteralDef funcAssetDef)
        {
            //AddAsset(funcAssetDef); 不要
            string title = TreeViewCommand.MakeGroup(ref group, funcAssetDef.MenuTitle);
            var    menu  = new TreeMenuNode(title, funcAssetDef.HelpText);

            group.AddChild(menu);
            menu.LeftClickCommand = OwnerCommandCanvas.CreateEventCanvasCommand(
                menu.Path,
                () => {
                var result = CbScript.SelectVariableType(OwnerCommandCanvas, funcAssetDef.typeRequests);
                if (funcAssetDef.MenuTitle.Contains(CbSTUtils.MENU_OLD_SPECIFICATION))
                {
                    result.OldSpecification = true;
                }
                return(result);
            }
                );
        }
Пример #3
0
        /// <summary>
        /// 代入の可否を判定します。
        /// </summary>
        /// <param name="toName">代入先の型名</param>
        /// <param name="fromName">代入元の型名</param>
        /// <param name="toType">代入先の型情報</param>
        /// <param name="fromType">代入元の型情報</param>
        /// <param name="isCast">キャストでの判定なら true</param>
        /// <returns>接続可能なら true</returns>
        static public bool IsAssignment(
            Type toType,
            Type fromType,
            bool isCast = false
            )
        {
            /// <summary>
            /// キャストを通しての代入の可否を判定します。
            /// </summary>
            bool IsCastAssignment(Type toType, Type fromType)
            {
                if (fromType == typeof(object))
                {
                    return(true);    // 接続元が object なら無条件でキャスト可能
                }
                if (!CbScript.IsCalcable(fromType) || !CbScript.IsCalcable(toType))
                {
                    return(false);
                }

                // 以下、値を表現する型のみ

                if (fromType == typeof(decimal) && toType == typeof(char))
                {
                    return(false);
                }

                if (fromType == typeof(char) &&
                    (toType == typeof(decimal) || toType == typeof(float) || toType == typeof(double)))
                {
                    return(false);
                }

                if (fromType == typeof(ulong) || fromType == typeof(uint) || fromType == typeof(ushort) || fromType == typeof(byte))
                {
                    return(true);
                }

                return(true);
            }

            if (toType == typeof(object))
            {
                return(true);    // object型なら無条件に繋がる
            }
            if (IsDelegate(toType))
            {
                // 接続先がデリゲート型

                Type toRetType = GetDelegateReturnType(toType);

                if (IsDelegate(fromType))
                {
                    // 接続元のデリゲート

                    Type fromRetType = GetDelegateReturnType(fromType);
                    return(IsAssignment(toRetType, fromRetType, isCast));
                }

                if (IsVoid(toRetType))
                {
                    // 値を返さないデリゲートは、無条件で繋がる

                    return(true);
                }
            }

            if (fromType == typeof(CbVoid))
            {
                return(false);   // object と Action 以外には繋がらない
            }
            if (toType == typeof(string))
            {
                return(true);    // CbVoid型以外なら無条件に繋がる
            }
            if (isCast && IsCastAssignment(toType, fromType))
            {
                return(true);    // Cast接続なら繋がる
            }
            if (IsDelegate(toType))
            {
                // 接続先がデリゲート型

                Type type = GetDelegateReturnType(toType);
                Debug.Assert(!IsVoid(type));
                return(IsAssignment(type, fromType, isCast));
            }

            if (toType.IsAssignableFrom(fromType))
            {
                return(true);    // 繋がる
            }
            return(false);
        }