예제 #1
0
파일: MainForm.cs 프로젝트: uvbs/FullSource
        /// <summary>
        /// 转换行文本
        /// </summary>
        /// <param name="line">行文本</param>
        /// <returns>新文本</returns>
        private string ConvertLine(string line)
        {
            string newLine = line;

            CodeConvert codeConvert = CodeConvert.GetCodeConvert();

            codeConvert.ConvertTableName = "stringTable";
            List <string> wordList = codeConvert.GetStringList(line);

            if (wordList.Count > 0) // 需要字符串替换
            {
                DataBaseManager dataBaseManager = DataBaseManager.GetDataBaseManager();

                foreach (string s in wordList)
                {
                    if (!s.Contains(",") && !line.Contains(string.Format("context, {0}", s))) // 参数类型不用替换
                    {
                        string id = dataBaseManager.InsertIntoFlowChartLS(s.Replace("'", "''"), mapName);
                        newLine = newLine.Replace(s, string.Format("{0}[{1}]", codeConvert.ConvertTableName, id));
                    }
                }
            }

            return(newLine);
        }
예제 #2
0
        public bool TryResolve <T>(out T value, Tokenizer tok, object scope = null)
        {
            List <object> results = new List <object>();

            //Show.Log(Tokenizer.DebugPrint(tokens));
            SyntaxTree.ResolveTerms(tok, scope, tokens, 0, tokens.Count, results);
            //Show.Log(results.Join("]["));
            if (results == null || results.Count != 1)
            {
                tok.AddError(-1, "missing results");
                value = default(T); return(false);
            }
            object obj = results[0];

            if (obj.GetType() == typeof(T))
            {
                value = (T)obj; return(true);
            }
            if (!CodeConvert.TryConvert(ref obj, typeof(T)))
            {
                if (obj.GetType() == typeof(string))
                {
                    Expression deepExpression = new Expression(obj as string, tok);
                    return(deepExpression.TryResolve(out value, tok, scope));
                }
                tok.AddError("unable to parse (" + obj.GetType() + ")\"" + obj + "\" as " + typeof(T).ToString());
                value = default(T);
                return(false);
            }
            value = (T)obj;
            return(true);
        }
예제 #3
0
파일: M100.cs 프로젝트: ghbylmt/LsPay
        /// <summary>
        /// Ic卡热冷复位
        /// </summary>
        /// <returns></returns>
        public string ICCardHotReset()
        {
            #region cmd build
            byte[] cmd = new byte[] { 0x02, 0x00, 0x02, 0x37, 0x2f, 0x03, new byte() };
            byte   bss = cmd[0];
            int    end = cmd.Length - 1;
            for (int i = 1; i < end; i++)
            {
                bss = (byte)(bss ^ cmd[i]);
            }
            cmd[end] = bss;
            #endregion

            if (!com.IsOpen)
            {
                com.OpenPort();
            }
            byte[] result          = com.SendCmd(cmd);
            int    resetDataLength = result[7];
            byte[] resetData       = result.Skip(8).Take(resetDataLength).ToArray();
            com.ClosePort();
            return(string.Format("操作状态:{0} \r\n复位数据:{1}",
                                 ASCIIEncoding.ASCII.GetString(new byte[] { result[5] })
                                 , CodeConvert.ToHexString(resetData)
                                 ));
        }
예제 #4
0
        /// <summary>
        /// 获取处理选项
        /// </summary>
        /// <param name="card"></param>
        public void GPO(ICCard card)
        {
            StringBuilder body    = new StringBuilder();
            List <string> gpoList = new List <string>();

            if (card.GPOL == null || card.GPOL.Count == 0)
            {
                throw new CardReadException("未读取到处理选项列表");
            }
            gpoList = card.GPOL.ToList();
            gpoList.ForEach(pdo => body.Append(PublicStaticData.PDOL[pdo]));
            body.Insert(0, (body.Length / 2).ToString("x2"));
            body.Insert(0, "83");
            body.Insert(0, (body.Length / 2).ToString("x2"));
            APDUEntity       GPO     = new APDUEntity("80", "A8", "00", "00", body.ToString());
            string           result  = CardReader.SendAPDU(GPO.ToString());
            List <TLVEntity> tlvList = TLVHelper.ToTLVEntityList(result);
            TLVEntity        entity  = null;

            if (tlvList != null && tlvList.Count > 0)
            {
                entity = tlvList[0];
            }
            card.AIP = CodeConvert.ToHexString(entity.Value.Take(2).ToArray());//前两位是AIP
            List <string> afl = new List <string>();

            for (int i = 2; i < entity.Value.Length; i = i + 4)
            {
                afl.Add(CodeConvert.ToHexString(entity.Value.Take(i + 4).Skip(i).ToArray()));
            }
            card.AFL = afl;
        }
예제 #5
0
        public Dialog[] Generate()
        {
            Dictionary <string, object> parametersForTemplate;
            Tokenizer tokenizer      = new Tokenizer();
            string    dialogData     = DialogManager.Instance.GetAsset(parameters),
                      dialogTemplate = DialogManager.Instance.GetAsset(template);

            if (dialogData == null || dialogTemplate == null)
            {
                Show.Error("failed to find components of templated script " + template + "<" + parameters + ">");
                return(null);
            }
            CodeConvert.TryParse(dialogData, out parametersForTemplate, null, tokenizer);
            if (tokenizer.ShowErrorTo(Show.Error))
            {
                return(null);
            }
            //Show.Log(parametersForTemplate.Stringify(pretty: true));
            Dialog[] templatedDialogs;
            CodeConvert.TryParse(dialogTemplate, out templatedDialogs, parametersForTemplate, tokenizer);
            if (tokenizer.ShowErrorTo(Show.Error))
            {
                return(null);
            }
            //Show.Log(templatedDialogs.Stringify(pretty: true));
            return(templatedDialogs);
        }
예제 #6
0
        /// <summary>
        /// 获取应用密文
        /// </summary>
        /// <param name="card">卡片信息</param>
        /// <returns></returns>
        public void GENERATEARQC(ICCard card, string transactionType = TransactionType.Pay)
        {
            PublicStaticData.TransactionType = TransactionType.Pay;
            Random random = new Random();

            PublicStaticData.RadomData = CodeConvert.ToHexString(new byte[] { (byte)random.Next(256), (byte)random.Next(256), (byte)random.Next(256), (byte)random.Next(256) });
            card.RadomData             = PublicStaticData.RadomData;
            StringBuilder cdol1Builder = new StringBuilder();

            card.CDOL1.ToList().ForEach(cdo => cdol1Builder.Append(PublicStaticData.CDOL1[cdo]));
            cdol1Builder.Insert(0, (cdol1Builder.Length / 2).ToString("x2"));
            APDUEntity entity = new APDUEntity("80", "AE", "80", "00", cdol1Builder.ToString());
            string     arqc   = CardReader.SendAPDU(entity.ToString());

            List <TLVEntity> entityList = TLVHelper.ToTLVEntityList(arqc);

            if (entityList.Count == 0)
            {
                throw new CardReadException("获取应用密文(ARQC)失败");
            }
            TLVEntity arqcEntity = entityList[0];

            card.CID            = arqcEntity.Value[0].ToString("x2");                                               //密文信息 L:1
            card.ATC            = CodeConvert.ToHexString(new byte[] { arqcEntity.Value[1], arqcEntity.Value[2] }); //ATC 应用交易计数器 L:2
            card.AC             = CodeConvert.ToHexString(arqcEntity.Value.Take(11).Skip(3).ToArray());             //AC应用密文 L:8
            card.IssBankAppData = CodeConvert.ToHexString(arqcEntity.Value.Skip(11).ToArray());                     //发卡行应用数据
        }
예제 #7
0
 public static object op_mod(Tokenizer tok, Context.Entry e, object scope)
 {
     op_BinaryArgs(tok, e, scope, out object left, out object right, out Type lType, out Type rType);
     do
     {
         if (lType == typeof(string))
         {
             string        format = left as string;
             List <object> args;
             if (rType != typeof(List <object>))
             {
                 args = new List <object>();
                 args.Add(right);
             }
             else
             {
                 args = right as List <object>;
             }
             return(Format(format, args, scope, tok, e.tokens[0].index));
         }
         if (lType == typeof(string) || rType == typeof(string))
         {
             break;
         }
         if (CodeConvert.IsConvertable(lType) && CodeConvert.IsConvertable(rType))
         {
             CodeConvert.TryConvert(ref left, typeof(double));
             CodeConvert.TryConvert(ref right, typeof(double));
             return(((double)left) % ((double)right));
         }
     } while (false);
     tok.AddError(e.tokens[1], "unable to modulo " + lType + " and " + rType + " : " + left + " % " + right);
     return(e);
 }
예제 #8
0
    public void Init()
    {
        Tokenizer tokenizer = new Tokenizer();

        CodeConvert.TryParse(resourceNamesText.text, out resourceNames, null, tokenizer);
        GenerateAdvancementSequence();
    }
 void Init()
 {
     if (initialized)
     {
         return;
     }
     else
     {
         initialized = true;
     }
     InitializeCommands();
     InitializeListUi();
     tokenizer = new Tokenizer();
     CodeConvert.TryParse(dialogAsset.text, out dialogs, GetScriptScope(), tokenizer);
     if (tokenizer.errors.Count > 0)
     {
         Debug.LogError(tokenizer.errors.Join("\n"));
     }
     //Debug.Log(tokenizer.DebugPrint());
     //Debug.Log(NonStandard.Show.Stringify(dialogs, true));
     if (dialogs == null)
     {
         dialogs = new List <Dialog>();
     }
     if (dialogs.Count > 0)
     {
         SetDialog(dialogs[0], UiPolicy.StartOver);
     }
 }
예제 #10
0
        public bool TryResolve <T>(out T value, Tokenizer tok, object scope = null)
        {
            List <object> results = new List <object>();

            //Show.Log(Tokenizer.DebugPrint(tokens));
            Context.Entry.ResolveTerms(tok, scope, tokens, 0, tokens.Count, results);
            //Show.Log(results.Join("]["));
            if (results == null || results.Count != 1)
            {
                tok.AddError(-1, "missing results");
                value = default(T); return(false);
            }
            object obj = results[0];

            if (obj.GetType() == typeof(T))
            {
                value = (T)obj; return(true);
            }
            if (!CodeConvert.TryConvert(ref obj, typeof(T)))
            {
                tok.AddError(-1, "unable to parse as " + typeof(T).ToString());
                value = default(T);
                return(false);
            }
            value = (T)obj;
            return(true);
        }
예제 #11
0
파일: MainForm.cs 프로젝트: uvbs/FullSource
        /// <summary>
        /// 保存ls文件
        /// </summary>
        /// <param name="filePath">文件路径</param>
        private void SaveLSFile(string filePath)
        {
            string    sqlString = string.Format("SELECT * FROM sys_script_lsfile WHERE classification = '{0}'", mapName);
            DataTable lsTable   = dataBaseManager.GetDataTable(sqlString, dataBaseManager.Connection_Jx3web);
            string    lsContent = CodeConvert.ConvertLsFileContent(lsTable.Select(string.Format("classification = '{0}'", mapName)));

            SaveDataToFile(filePath, lsContent);
        }
예제 #12
0
        public static object op_mul(Tokenizer tok, Context.Entry e, object scope)
        {
            object left, right; Type lType, rType;

            op_BinaryArgs(tok, e, scope, out left, out right, out lType, out rType);
            do
            {
                bool lString = lType == typeof(string);
                bool rString = rType == typeof(string);
                // if one of them is a string, there is some string multiplication logic to do!
                if (lString != rString)
                {
                    string meaningfulString;
                    double meaningfulNumber;
                    if (lString)
                    {
                        if (!CodeConvert.IsConvertable(rType))
                        {
                            break;
                        }
                        meaningfulString = left.ToString();
                        CodeConvert.TryConvert(ref right, typeof(double));
                        meaningfulNumber = (double)right;
                    }
                    else
                    {
                        if (!CodeConvert.IsConvertable(lType))
                        {
                            break;
                        }
                        meaningfulString = right.ToString();
                        CodeConvert.TryConvert(ref left, typeof(double));
                        meaningfulNumber = (double)left;
                    }
                    StringBuilder sb = new StringBuilder();
                    for (int i = 0; i < meaningfulNumber; ++i)
                    {
                        sb.Append(meaningfulString);
                    }
                    meaningfulNumber -= (int)meaningfulNumber;
                    int count = (int)(meaningfulString.Length * meaningfulNumber);
                    if (count > 0)
                    {
                        sb.Append(meaningfulString.Substring(0, count));
                    }
                    return(sb.ToString());
                }
                if (CodeConvert.IsConvertable(lType) && CodeConvert.IsConvertable(rType))
                {
                    CodeConvert.TryConvert(ref left, typeof(double));
                    CodeConvert.TryConvert(ref right, typeof(double));
                    return(((double)left) * ((double)right));
                }
            } while (false);
            tok.AddError(e.tokens[1], "unable to multiply " + lType + " and " + rType);
            return(e);
        }
예제 #13
0
 private static async Task Main(string[] args)
 {
     var app = CodeConvert.ForType <StaticMethods>()
               .ForType <AsyncStaticMethods>()
               .ForType <InstanceTestClass>()
               .WithInstanceCreator(InstanceProvider)
               .CreateConsoleApplication();
     await app.RunAsync(args);
 }
예제 #14
0
        void Start()
        {
            if (dialogView == null)
            {
                dialogView = FindObjectOfType <DialogViewer>();
            }
            if (dict == null)
            {
                dict = GetComponentInChildren <ScriptedDictionary>();
            }
            Dialog[] dialogs;
            //NonStandard.Show.Log(knownAssets.JoinToString(", ", ta => ta.name));
            //NonStandard.Show.Log(root.name+":" + root.text.Length);
            Tokenizer tokenizer = new Tokenizer();

            if (dict != null)
            {
                Global.GetComponent <ScriptedDictionaryManager>().SetMainDicionary(dict);
            }
            try {
                CodeConvert.TryParse(root.text, out dialogs, dict.Dictionary, tokenizer);
                tokenizer.ShowErrorTo(NonStandard.Show.Error);
                if (dialogs == null)
                {
                    return;
                }
                //NonStandard.Show.Log("dialogs: [" + d.Stringify(pretty:true)+"]");
                this.dialogs.AddRange(dialogs);
                ResolveTemplatedDialogs(this.dialogs);
            } catch (System.Exception e) {
                NonStandard.Show.Log("~~~#@Start " + e);
            }
            //NonStandard.Show.Log("finished initializing " + this);
            //NonStandard.Show.Log(this.dialogs.JoinToString(", ", dialog => dialog.name));
            // execute all "__init__" dialogs
            ScriptedDictionaryManager m = Global.Get <ScriptedDictionaryManager>();
            object standardScope        = m.Main;     //Commander.Instance.GetScope();

            for (int i = 0; i < this.dialogs.Count; ++i)
            {
                Dialog dialog = this.dialogs[i];
                if (!dialog.name.StartsWith("__init__"))
                {
                    continue;
                }

                //NonStandard.Show.Log("initializing "+dialog.name);
                Tokenizer tok = new Tokenizer();
                dialog.ExecuteCommands(tok, standardScope);
                if (tok.HasError())
                {
                    tok.ShowErrorTo(NonStandard.Show.Warning);
                }
            }
            //NonStandard.Show.Log(standardScope.Stringify(pretty: true));
        }
예제 #15
0
 private bool TryGetValue_TokenSubstitution(Token token, TokenSubstitution sub)
 {
     memberValue = sub.value;
     if (!memberType.IsAssignableFrom(memberValue.GetType()) && !CodeConvert.TryConvert(ref memberValue, memberType))
     {
         AddError("unable to convert substitution (" + memberValue + ") to type '" + memberType + "'");
         return(false);
     }
     return(true);
 }
예제 #16
0
        private static Task RunCommand(string command)
        {
            var commandRunner = CodeConvert.ForType <StaticMethods>()
                                .ForType <AsyncStaticMethods>()
                                .ForType <InstanceTestClass>()
                                .WithInstanceCreator(InstanceProvider)
                                .CreateRunner();

            return(commandRunner.RunCommandAsync(command));
        }
예제 #17
0
        /// <summary>
        /// 获取应用标识符
        /// </summary>
        /// <returns></returns>
        public void GetAID(ICCard card)
        {
            string           result  = CardReader.SendAPDU(APDUCommand.GETDATA);
            List <TLVEntity> tlvList = TLVHelper.ToTLVEntityList(result);
            var entity = TLVHelper.GetValueByTag(tlvList, EMVTag.AID);

            if (entity == null)
            {
                throw new CardReadException("获取不到卡片的应用标识符!");
            }
            card.AID = CodeConvert.ToHexString(entity.Value);
        }
예제 #18
0
        public void AssignFromText(string text)
        {
            //TMPro.TMP_InputField input = GetComponent<TMPro.TMP_InputField>();
            //Show.Log("assign "+text+" instead of "+input.text);
            UnityDataSheet uds = GetComponentInParent <UnityDataSheet>();

            if (uds == null)
            {
                // this happens the first instant that the input field is created, before it is connected to the UI properly
                //Show.Log("missing "+nameof(UnityDataSheet)+" for "+transform.HierarchyPath());
                return;
            }
            int col = transform.GetSiblingIndex();
            int row = uds.GetRowIndex(transform.parent.gameObject);

            Udash.ColumnSetting column = uds.GetColumn(col);
            if (column.canEdit)
            {
                object value           = text;
                bool   validAssignment = true;
                if (column.type != null)
                {
                    if (!CodeConvert.Convert(ref value, column.type))
                    {
                        errorMessage = "could not assign \"" + text + "\" to " + column.type;
                        uds.errLog.AddError(-1, errorMessage);
                        validAssignment = false;
                        uds.popup.Set("err", gameObject, errorMessage);
                    }
                }
                if (validAssignment)
                {
                    ITokenErrLog errLog = new TokenErrorLog();
                    validAssignment = column.SetValue(uds.GetItem(row), value, errLog);
                    if (errLog.HasError())
                    {
                        errorMessage    = errLog.GetErrorString();
                        validAssignment = false;
                        uds.popup.Set("err", gameObject, errorMessage);
                    }
                }

                if (validAssignment)
                {
                    uds.data.Set(row, col, value);
                    if (errorMessage == uds.popup.Message)
                    {
                        uds.popup.Hide();
                    }
                }
            }
        }
예제 #19
0
        /// <summary>
        /// 获取处理选项数据对象列表(PDOL)
        /// </summary>
        /// <returns></returns>
        public void GetPDOL(ICCard card)
        {
            string           aid     = card.AID;
            APDUEntity       apdu    = new APDUEntity("00", APDU_INS.SELECT, "04", "00", string.Format("{0}{1}", (aid.Length / 2).ToString("x2"), aid));
            string           result  = CardReader.SendAPDU(apdu.ToString());
            List <TLVEntity> tlvList = TLVHelper.ToTLVEntityList(result);
            var entity = TLVHelper.GetValueByTag(tlvList, EMVTag.PDOL);

            if (entity == null)
            {
                throw new CardReadException("获取不到卡片的处理选项数据对象列表!");
            }
            card.GPOL = CodeConvert.ToTLStringList(entity.Value);
        }
        public void OnSetDefaultValue(string text)
        {
            object    value     = null;
            Tokenizer tokenizer = new Tokenizer();

            CodeConvert.TryParseType(expectedValueType, text, ref value, null, tokenizer);
            // parse errors
            if (tokenizer.HasError())
            {
                popup.Set("err", defaultValue.gameObject, tokenizer.GetErrorString()); return;
            }
            cHeader.columnSetting.defaultValue = value;
            popup.Hide();
        }
예제 #21
0
        /// <summary>
        /// 计算MAC码
        /// </summary>
        /// <param name="source"></param>
        /// <returns></returns>
        public string CalculateMAC(StringBuilder source)
        {
            byte[] sourceBytes = CodeConvert.HexStringToByteArray(source.ToString());
            File.AppendAllText("mac.txt", source.ToString());
            StringBuilder sbMac    = new StringBuilder();
            StringBuilder sbReturn = new StringBuilder();

            ZT_EPP.ZT_EPP_ActivWorkPin(0x00, 0x01);
            ZT_EPP.ZT_EPP_SetDesPara(0x06, 0x03);
            ZT_EPP.ZT_EPP_PinCalMAC(1, 4, source, sbMac);
            string mac = CodeConvert.ToHexString(Encoding.ASCII.GetBytes(sbMac.ToString().Substring(0, 8)));

            return(mac);
        }
예제 #22
0
        static void Main(string[] args)
        {
            string testData = "name\"the player\"i-2 f3testing12\"3\"2.99";
            SensitiveHashTable_stringfloat dict;
            Tokenizer tok = new Tokenizer();

            CodeConvert.TryParse(testData, out dict, null, tok);
            if (tok.errors.Count > 0)
            {
                Show.Log(tok.errors.Join("\n"));
            }
            Show.Log(tok.DebugPrint());
            Show.Log("result: " + Show.Stringify(dict, true));
        }
예제 #23
0
 public static void op_BinaryArgs(Tokenizer tok, Context.Entry e, object scope, out object left, out object right, out Type lType, out Type rType)
 {
     op_ResolveToken(tok, e.tokens[0], scope, out left, out lType);
     op_ResolveToken(tok, e.tokens[2], scope, out right, out rType);
     // upcast to double. all the math operations expect doubles only, for algorithm simplicity
     if (lType != typeof(string) && lType != typeof(double) && CodeConvert.IsConvertable(lType))
     {
         CodeConvert.TryConvert(ref left, typeof(double)); lType = typeof(double);
     }
     if (rType != typeof(string) && rType != typeof(double) && CodeConvert.IsConvertable(rType))
     {
         CodeConvert.TryConvert(ref right, typeof(double)); rType = typeof(double);
     }
 }
예제 #24
0
        protected void FinalParseDataCompile()
        {
            if (listData == null)
            {
                return;
            }
            //result = ConvertIList(listData, resultType, memberType);
            object ilist = listData;

            if (!CodeConvert.TryConvertIList(ref ilist, resultType, memberType))
            {
                throw new Exception("convert failed");
            }
            result = ilist;
        }
예제 #25
0
 public static object op_add(Tokenizer tok, Context.Entry e, object scope)
 {
     op_BinaryArgs(tok, e, scope, out object left, out object right, out Type lType, out Type rType);
     if (lType == typeof(string) || rType == typeof(string))
     {
         return(left.ToString() + right.ToString());
     }
     if (CodeConvert.IsConvertable(lType) && CodeConvert.IsConvertable(rType))
     {
         CodeConvert.TryConvert(ref left, typeof(double));
         CodeConvert.TryConvert(ref right, typeof(double));
         return(((double)left) + ((double)right));
     }
     tok.AddError(e.tokens[1], "unable to add " + lType + " and " + rType + " : " + left + " + " + right);
     return(e);
 }
예제 #26
0
        public static bool op_reduceToBoolean(object obj, Type type)
        {
            if (obj == null)
            {
                return(false);
            }
            if (type == typeof(string))
            {
                return(((string)obj).Length != 0);
            }
            if (!CodeConvert.TryConvert(ref obj, typeof(double)))
            {
                return(true);
            }
            double d = (double)obj;

            return(d != 0);
        }
예제 #27
0
 public bool TryGet <T>(string argId, out T value)
 {
     value = default(T);
     if (!namedValues.TryGetValue(argId, out object obj))
     {
         return(false);
     }
     if (obj != null && typeof(T) != obj.GetType())
     {
         CodeConvert.TryConvert(ref obj, typeof(T));
     }
     if (typeof(T) == obj?.GetType())
     {
         value = (T)obj;
         return(true);
     }
     return(false);
 }
예제 #28
0
        /// <summary>
        /// 发卡行外部认证
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public bool IssueBankAuthenticate(string data)
        {
            //支付成功获取发卡行返回的55域数据
            byte[]           part55Data = CodeConvert.HexStringToByteArray(data);
            List <TLVEntity> tlvList    = TLVPackage.Construct(part55Data);
            TLVEntity        entity     = TLVHelper.GetValueByTag(tlvList, "91");//获取发卡行认证数据

            if (entity != null)
            {
                APDUEntity apdu   = new APDUEntity("00", "82", "00", "00", CodeConvert.ToHexString(entity.Length) + CodeConvert.ToHexString(entity.Value));
                string     result = CardReader.SendAPDU(apdu.ToString());
                return(true);// result.Equals(StatusCode.Success) == result.Equals(StatusCode.Authenticated);
            }
            else
            {
                return(true);
            }
        }
        public void SetExpectedEditType(object sampleValue)
        {
            Type sampleValueType = GetEditType();

            if (sampleValueType == null)
            {
                // set to read only
                expectedValueType = null;
                DropDownEvent.PopulateDropdown(valueType, new string[] { "read only" }, this, null, 0, false);
            }
            else
            {
                if (sampleValueType != expectedValueType)
                {
                    // set to specific type
                    if (sampleValueType == typeof(object))
                    {
                        sampleValueType = sampleValue.GetType();
                        int defaultChoice = -1;
                        if (defaultChoice < 0 && CodeConvert.IsIntegral(sampleValueType))
                        {
                            defaultChoice = defaultValueTypes.FindIndex(kvp => kvp.Key == typeof(long));
                        }
                        if (defaultChoice < 0 && CodeConvert.IsNumeric(sampleValueType))
                        {
                            defaultChoice = defaultValueTypes.FindIndex(kvp => kvp.Key == typeof(double));
                        }
                        if (defaultChoice < 0)                          // && sampleValueType == typeof(string)) {
                        {
                            defaultChoice = defaultValueTypes.FindIndex(kvp => kvp.Key == typeof(string));
                        }
                        List <string> options = defaultValueTypes.ConvertAll(kvp => kvp.Value);
                        DropDownEvent.PopulateDropdown(valueType, options, this, SetEditType, defaultChoice, true);
                        cHeader.columnSetting.type = defaultValueTypes[defaultChoice].Key;
                    }
                    else
                    {
                        DropDownEvent.PopulateDropdown(valueType, new string[] { sampleValueType.ToString() }, this, null, 0, false);
                        cHeader.columnSetting.type = sampleValueType;
                    }
                    expectedValueType = sampleValueType;
                }
            }
        }
예제 #30
0
 public static object op_pow(Tokenizer tok, Context.Entry e, object scope)
 {
     op_BinaryArgs(tok, e, scope, out object left, out object right, out Type lType, out Type rType);
     do
     {
         if (lType == typeof(string) || rType == typeof(string))
         {
             break;
         }
         if (CodeConvert.IsConvertable(lType) && CodeConvert.IsConvertable(rType))
         {
             CodeConvert.TryConvert(ref left, typeof(double));
             CodeConvert.TryConvert(ref right, typeof(double));
             return(Math.Pow((double)left, (double)right));
         }
     } while (false);
     tok.AddError(e.tokens[1], "unable to exponent " + lType + " and " + rType + " : " + left + " ^^ " + right);
     return(e);
 }