public void DelegateUtil_ConvertTo_InstanceComplitable() //实例的可兼容方法, { var method = this.GetType().GetMethod("Multiply_InstanceComplitable"); Call objCall1 = DelegateUtil.ConvertTo <Call>(method, new DelegateUtilTests()); Assert.AreEqual(10, objCall1(2, 5)); }
public void DelegateUtil_ConvertTo_Multiply_InstanceFullfit() //实例方法,参数完全一致; { var method = this.GetType().GetMethod("Multiply_InstanceFullfit", BindingFlags.Instance | BindingFlags.Public); Call objCall1 = DelegateUtil.ConvertTo <Call>(method, new DelegateUtilTests()); Assert.IsNotNull(objCall1); Assert.AreEqual(10, objCall1(2, 5)); }
public void DelegateUtil_ConvertTo_StaticComplitable() //静态方法,参数可兼容 { var method = this.GetType().GetMethod("Multiply_StaticComplitable", BindingFlags.Static | BindingFlags.Public); Call objCall1 = DelegateUtil.ConvertTo <Call>(method, null); Assert.IsNotNull(objCall1); Assert.AreEqual(10, objCall1(2, 5)); }
public void DelegateUtil_HasCompatiableMethodParameter() { var method = this.GetType().GetMethod("Multiply_InstanceComplitable"); Assert.IsTrue(DelegateUtil.HasCompatiableMethodParameter <Call>(method)); //可兼容方法,返回 true; method = this.GetType().GetMethod("Multiply_InstanceNoComplitable"); Assert.IsFalse(DelegateUtil.HasCompatiableMethodParameter <Call>(method)); //不可兼容方法,返回 false; }
public static string ImgToBase64String(string path, EncodingType type = EncodingType.UTF8) { string res = ""; return(DelegateUtil.TryExecute(() => { return Convert.ToBase64String(ReadFileToBytes(path, type)); }, res)); }
public void DelegateUtil_ConvertTo_Static_FullComplicatable() //静态方法,参数和返回类型完全一致; { Call objCall; //第二步:声明委托变量 objCall = Multiply_StaticFullfit; var method = this.GetType().GetMethod("Multiply_StaticFullfit"); Call objCall1 = DelegateUtil.ConvertTo <Call>(method, null); Assert.IsNotNull(objCall); Assert.AreEqual(10, objCall1(2, 5)); }
public static void StartCycleTween(GameObject targetGameObject, float startValue, float endValue, float duration, DelegateUtil.FloatDelegate floatDelegate) { var cycleTween = targetGameObject.GetComponent<CycleTween>() ?? targetGameObject.AddComponent<CycleTween>(); cycleTween.m_cycleTweenConfig = new CycleTweenConfig() { m_StartValue = startValue, m_EndValue = endValue, m_Duration = duration, m_FloatDelegate = floatDelegate }; cycleTween.DoCycleTween(); }
public static string ReadFileFromPath(string path, EncodingType type = EncodingType.UTF8) { string line = ""; return(DelegateUtil.TryExecute(() => { if (File.Exists(path)) { StreamReader sr = new StreamReader(path, BytesExt.GetEncoding(type)); while ((line = sr.ReadLine()) != null) { line = sr.ReadToEnd(); return line; } } return line; }, line)); }
public IActionResult ImportExcel(IFormFile file) { if (file == null || file.Length <= 0) { return(BootJsonH((false, PubConst.File1))); } string fileExt = Path.GetExtension(file.FileName).ToLower(); if (!NpoiUtil.excel.Contains(fileExt)) { return(BootJsonH((false, PubConst.File2))); } var filepath = Path.Combine(WebRoot, "upload", PubId.GetUuid()) + fileExt; //1 直接通过流 return(DelegateUtil.TryExecute <IActionResult>(() => { using (var st = new MemoryStream()) { file.CopyTo(st); var dt = NpoiUtil.Import(st, fileExt); var json = _customerServices.Import(dt, UserDtoCache.UserId).JilToJson(); return Content(json); } }, BootJsonH((false, PubConst.File3)) )); //using (var st = new MemoryStream()) //{ // file.CopyTo(st); // var dt = NpoiUtil.Import(st, fileExt); // var json = _customerServices.Import(dt, UserDtoCache.UserId).JilToJson(); // return Content(json); //} //2 先上传到服务器,然后在读取 //using (var stream = new FileStream(filepath, FileMode.CreateNew)) //{ // file.CopyTo(stream); //} //var dt = NpoiUtil.Import(filepath); //FileUtil.Delete(filepath); //var json = _customerServices.Import(dt, UserDtoCache.UserId).JilToJson(); //return Content(json); }
/// <summary> /// 扫描程序集查找所有标记 AbstractEntitysOperateDefineAttribute 属性的方法, 注册此方法为异步消息处理方法; /// /// </summary> /// <param name="assembly"></param> /// <param name="methodDelegateType">方法所需要兼容的委托类型,如果为null,则表示不需要;</param> public static void RegisterAssembly(Assembly assembly, Type methodDelegateType = null) { List <AssemblyClassMethodAndAttribute <AbstractEntitysOperateDefineAttribute> > notifyAttriList = EnumMethodWithAttribute <AbstractEntitysOperateDefineAttribute>(assembly) .Where(a => { if (methodDelegateType == null) { return(true); } if (DelegateUtil.HasCompatiableMethodParameter(methodDelegateType, a.Method)) { return(true); } return(false); }).ToList(); notifyAttriList.ForEach((a) => { //if (a.Attribute.operatePathAppenx == null) //{ // a.Attribute.operatePathAppenx = a.Attribute.label; //} a.Attribute.operatePath = string.Format("{0}.{1}.{2}.{3}", a.Type.Name, a.Method.Name, a.Attribute.label, a.Attribute.operatePathAppenx); //改变 operatePath 为 ClassName.MethodName }); notifyAttriList.GroupBy(a => a.Attribute.limitRequestEntityType.Name).Any((entityTypeNameGroup) => { var innerMap = DictionaryUtil.FindOrInsert(map, entityTypeNameGroup.Key, new Dictionary <string, AssemblyClassMethodAndAttribute <AbstractEntitysOperateDefineAttribute> >()); var pairGroup = entityTypeNameGroup.ToDictionary((pair) => pair.Attribute.operatePath, pair => pair) .ToArray(); innerMap.AddRange(pairGroup); return(false); }); }