吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 3103|回复: 7
收起左侧

[其他原创] 【原创源码】C#编写一款自己的脚本语言.第十五章

[复制链接]
moodlee 发表于 2016-4-20 18:37
第十五章

处处槐花香,香在心头,思念起。
槐花饭、槐花糕、槐花蜜...
槐花在何处?小学的课本。
每欲槐花煮饭,终无果,遗憾了十数年,又一年。
——————————

1.jpg

——————————

上一章,我们写了单个变量的类。从图中,我们可以看出:变量的上一级是变量集(Variables)。
——————————

变量集有哪些属性呢?
——————————

[C#] 纯文本查看 复制代码
 public class UVariables
        {
            private List<UVariable> Variables = new List<UVariable>();

            private  UVariable Index(string Name)
            {
                UVariable myResult = new UVariable();
                //-----
                for (int i = 0; i < Variables.Count; i++)
                {
                    if (Variables[i].Name == Name)
                    {
                        myResult = Variables[i];
                        break;
                    }
                }
                //-----
                return myResult;
            }
            /*清空*/
            public void Clear()
            {
                Variables = new List<UVariable>();
            }
            /*添加*/
            public bool Add(string Type,string Name,string Value)
            {
                bool myResult=true;
                //-----
                if(Index(Name).Actived == true)
                {
                    ShowError(0,"Name="+Name);
                    return false;
                }
                UVariable Variable = new UVariable();
                Variable.Type = Type;
                Variable.Name = Name;
                Variable.Value = Value;
                Variables.Add(Variable);
                //-----
                return myResult;
            }
            /*读取值*/
            public string Read(string Name)
            {
                string myResult = string.Empty;
                //-----
                UVariable V = Index(Name);
                if (V.Actived)
                {
                    myResult = V.Value;
                }else
                {
                    ShowError(1,"Name="+Name);
                }
                //-----
                return myResult;
            }
            /*设置值*/
            public bool Set(string Name,string Value)
            {
                bool myResult = false ;
                //-----
                int IndexV = -1;
                for (int i = 0; i < Variables.Count; i++)
                {
                    if (Variables[i].Name == Name && Variables[i].Actived)
                    {
                        myResult = true;
                        IndexV = i;
                        break;
                    }
                }
                if (IndexV == -1)
                {
                    ShowError(1,"Name="+Name);
                }else
                {
                    Variables[IndexV].Value = Value;
                }
                //-----
                return myResult;
            }
            #region 辅助函数
            private string Error(int ID, string Add = "")
            {
                string myResult = string.Empty;
                //-----
                string KeyError = string.Empty;
                switch (ID)
                {
                    case 0:
                        KeyError = "Error0:The var has existed.";
                        break;
                    case 1:
                        KeyError = "Error1:The var hasn't existed";
                        break;
                }
                if(Add .Length == 0)
                {
                    myResult = KeyError;
                }else
                {
                    myResult = KeyError + " Info:" + Add;
                }
                
                //-----
                return myResult;
            }
            private void ShowError(int ID,string Add = "")
            {
                MessageBox.Show(Error (ID,Add));
            }
            #endregion
        }

——————————

这个类主要实现对变量的管理。但是这种管理还远远不够。
因为变量有这几种情况:
1、类下
2、函数下
——————————

下一步,我们要将Variable实现函数管理、类管理。
——————————

根据图里面的关系,我们可以怎样进行设计呢?
——————————

明日十五,待月圆,仰望天空。


免费评分

参与人数 2热心值 +2 收起 理由
Cizel + 1 坚持加油~
infofans + 1 热心回复!

查看全部评分

本帖被以下淘专辑推荐:

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

 楼主| moodlee 发表于 2016-4-20 18:37
zgkt 发表于 2016-4-20 19:44
啦灯是我干掉的 发表于 2016-4-20 19:50
IRELAND353 发表于 2016-4-20 21:26
看不懂,应该是高手
wangqiustc 发表于 2016-4-21 14:24
终于看到第十五章了
infofans 发表于 2016-4-21 17:26
加油,关注中!!
Fmd1988 发表于 2016-4-22 14:11
很好,不错。
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则

快速回复 收藏帖子 返回列表 搜索

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-9-23 06:28

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表