Esempio n. 1
0
        /// <summary>
        /// 精准获取动态类
        /// </summary>
        /// <param name="classIndex">类索引,1开始</param>
        /// <param name="namespaceIndex">命名空间索引,1开始</param>
        /// <returns></returns>
        public Type GetType(int classIndex = 1, int namespaceIndex = 1)
        {
            Complier.Add(this);
            string name = default;

            switch (OopTypeEnum)
            {
            case OopType.Class:

                name = ScriptHelper.GetClassName(Script, classIndex, namespaceIndex);
                break;

            case OopType.Struct:

                name = ScriptHelper.GetStructName(Script, classIndex, namespaceIndex);
                break;

            case OopType.Interface:

                name = ScriptHelper.GetInterfaceName(Script, classIndex, namespaceIndex);
                break;

            case OopType.Enum:

                name = ScriptHelper.GetEnumName(Script, classIndex, namespaceIndex);
                break;
            }

            return(Complier.GetType(name));
        }
Esempio n. 2
0
 /// <summary>
 /// 返回强类型委托
 /// </summary>
 /// <typeparam name="S">委托的强类型</typeparam>
 /// <returns></returns>
 public virtual S Complie <S>(object binder = null) where S : Delegate
 {
     Complier.Add(this);
     return(Complier.GetDelegate <S>(
                OopNameScript,
                MethodNameScript,
                binder));
 }
Esempio n. 3
0
        /// <summary>编译源文件</summary>
        /// <param name="cmd"></param>
        /// <param name="file"></param>
        /// <returns></returns>
        public Int32 Compile(String cmd, String file)
        {
            var objName = GetObjPath(file);

            // 如果文件太新,则不参与编译
            var obj = (objName + ".o").AsFile();

            if (!Check(file, obj))
            {
                return(-2);
            }

            obj.DirectoryName.EnsureDirectory(false);

            var sb = new StringBuilder();

            sb.Append(cmd);

            foreach (var item in Includes)
            {
                sb.AppendFormat(" -I{0}", item);
            }

            var rs = OnCompile(file);

            if (!rs.IsNullOrEmpty())
            {
                sb.AppendFormat(" {0}", rs);
            }

            // 加上内置编译时宏定义
            sb.AppendFormat(DefineFormat + "={1}", "__BUILD_DATE__", (Int32)(DateTime.Now - new DateTime(2000, 1, 1)).TotalDays);
            sb.AppendFormat(DefineFormat + "={1}", "__BUILD_TIME__", (Int32)(DateTime.Now - new DateTime(1970, 1, 1)).TotalSeconds);
            sb.AppendFormat(DefineFormat + "=\"\\\"{1}\\\"\"", "__BUILD_STIME__", DateTime.Now.ToFullString());
            sb.AppendFormat(DefineFormat + "=\"\\\"{1}\\\"\"", "__BUILD_SDATE__", DateTime.Now.ToString("yyMMdd"));
            sb.AppendFormat(DefineFormat + "={1}", "__BUILD_ITIME__", DateTime.Now.ToString("HHmmss"));
            sb.AppendFormat(DefineFormat + "={1}", "__BUILD_IDATE__", DateTime.Now.ToString("yyMMdd"));
            var user = $"{Environment.MachineName}_{Environment.UserName}";

            if (user.Length > 15)
            {
                user = Environment.MachineName;
            }
            if (user.Length > 15)
            {
                user = user.Substring(0, 15);
            }
            sb.AppendFormat(DefineFormat + "=\"\\\"{1}\\\"\"", "__BUILD_USER__", user);

            // 先删除目标文件
            if (obj.Exists)
            {
                obj.Delete();
            }

            return(Complier.Run(sb.ToString(), 100, WriteLog));
        }
Esempio n. 4
0
 /// <summary>
 /// 编译返回委托
 /// </summary>
 /// <returns></returns>
 public virtual Delegate Complie(object binder = null)
 {
     Complier.Add(this);
     return(Complier.GetDelegate(
                OopNameScript,
                MethodNameScript,
                DelegateType,
                binder));
 }
Esempio n. 5
0
        /// <summary>编译源文件</summary>
        /// <param name="cmd"></param>
        /// <param name="file"></param>
        /// <returns></returns>
        public Int32 Compile(String cmd, String file)
        {
            var objName = GetObjPath(file);

            // 如果文件太新,则不参与编译
            var obj = (objName + ".o").AsFile();

            if (!Check(file, obj))
            {
                return(-2);
            }

            obj.DirectoryName.EnsureDirectory(false);

            var sb = new StringBuilder();

            sb.Append(cmd);

            foreach (var item in Includes)
            {
                sb.AppendFormat(" -I{0}", item);
            }

            var rs = OnCompile(file);

            if (!rs.IsNullOrEmpty())
            {
                sb.AppendFormat(" {0}", rs);
            }

            // 先删除目标文件
            if (obj.Exists)
            {
                obj.Delete();
            }

            return(Complier.Run(sb.ToString(), 100, WriteLog));
        }