zoukankan      html  css  js  c++  java
  • 将DLL放在资源文件中,利用反射来调用它的泛型函数!

    public static string ListToJson<T>(T List)
            {
                
    
                System.Reflection.Assembly ass = System.Reflection.Assembly.Load(SCB.FDS.Client.AutoUpdate.Resource.Newtonsoft_Json);
                Type type = ass.GetType("Newtonsoft.Json.JsonConvert");
                MethodInfo method = GetMethodToString(type, "SerializeObject", 1);
    
                return method.Invoke(null, new object[] { List }).ToString();   
            }
    
            public static T JsonToList<T>(string List)
            {
                
    
                System.Reflection.Assembly ass = System.Reflection.Assembly.Load(SCB.FDS.Client.AutoUpdate.Resource.Newtonsoft_Json);
    
                Type type = ass.GetType("Newtonsoft.Json.JsonConvert");
    
                MethodInfo method = GetMethodToT(type, "DeserializeObject", 1).MakeGenericMethod(typeof(T));
                
                T t = (T)method.Invoke(null, new object[] { List });
                
                return t;
            }
    
            private static MethodInfo GetMethodToT(Type type, string methodName, int paramCount)
            {
                return type.GetMethods().FirstOrDefault(m => { return m.ReturnType != typeof(string) && m.ReturnType != typeof(object) && m.Name == methodName && m.GetParameters().Count() == paramCount; });
            }
    
            private static MethodInfo GetMethodToString(Type type, string methodName, int paramCount)
            {
                return type.GetMethods().FirstOrDefault(m => { return m.ReturnType == typeof(string) && m.Name == methodName && m.GetParameters().Count() == paramCount; });
            }
      
  • 相关阅读:
    iOS RunTime
    js本地对象的操作
    js面向对象实现切换面板
    css3上下翻页效果
    Normalize.css用法
    javasript深度拷贝
    div中div水平垂直居中
    正则表达式匹配括号内网址
    ajax聊天
    移动端px转rem的两种方法
  • 原文地址:https://www.cnblogs.com/jordan2009/p/3067207.html
Copyright © 2011-2022 走看看