Category - C#/.Net

2017-05-26 19:15:46    111    0    0
  1. //目的、动态切换逻辑
  2. //封闭变化的程序
  3. //动态切换数据库等
  4. //根据字符串、实例化指定程序集下命名空间下的类
  5. Assembly.Load("程序集").CreateInstance("命名空间.类名");
  6. //配合Interface使用
  7. 实例.GetType();//获取类型的类型
  8. typeof(Class); //等效和 实例.GetType(); 等效
  9. type.GetProperties(); //属性
  10. type.GetMethods();//方法
  11. type.GetMembers();//成员 字段
  12. type.GetEvents();//事件
  13. Activator.CreateInstance(Type type);//动态实例化一个指定类型的实体类
  14. ///反射获取常量的值
  15. var mfield = itype.GetField(常量名);
  16. mb.SortName = mfield.GetValue(对象object).ToString();
  17. //获取方法 不考虑父级成员
  18. //加上BindingFlags.DeclaredOnly 即可
  19. MethodInfo[] MethodItem = itype.GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly);
2017-06-06 15:30:05    88    0    0
  1. foreach (var i in Assembly.Load("你的程序集").GetTypes())
  2. {
  3. Console.Write(i.FullName);
  4. Console.Write("|");
  5. Console.WriteLine(i.Name);
  6. }
2017-05-28 18:00:47    354    0    0

网上也有很多朋友遇到这种问题
做服务端的盆友、要求给APP端的数据
不要带Null、 APP端处理麻烦
且不是过滤Null属性、需要保留字段、Null给成空字符串。
或者做其他你需要的自定义的处理
比如直接全局Json 序列化 性别 成 “汉子”“妹子”
全局区别数据格式对应不同平台等,
等高级DIV序列化方式

有些朋友、使用在实体类去标记初始值的方式。
有些朋友、使用重写Json.Net/Newtonsoft.Json的方法
还有些朋友、用其他的方式、
但是效率、以及方不方便上
不是很理想和实用

所以还是用反射实现好了、效率上也比较理想,
完美递归复杂实体类之后、再进行Json序列化、
实验证明这样达到目的效率更高、
方式最终精简如下

By 皓月

范例如下:

  1. public static T MySet<T>(T newi)
  2. {
  3. var t1 = newi.GetType();//
  4. //typeof(Class) //获取类型的类型
  5. var t1Properties = t1.GetProperties(); //属性集合
  6. //var t1Members = t1.GetMembers();//成员 字段
  7. //var t1m = t1.GetMethods();//类型的方法的类型
  8. //t1.GetEvents();//类型的事件
  9. foreach (var t in t1Properties)//遍历属性
  10. {
  11. Type t_type = t.GetType();
  12. object t_Value = t.GetValue(newi, null);
  13. if (t_Value == null)//判断是否为空
  14. {
  15. //此处添加任何你需要的自定处理
  16. if (
2017-05-23 10:50:07    316    0    0
  1. public static T SetReflectionObject<T>(T t)
  2. {
  3. System.Reflection.PropertyInfo[]
  4. //properties = t.GetType().GetProperties(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public);
  5. properties = t.GetType().GetProperties();
  6. if (t.GetType().Name.StartsWith("List"))
  7. {
  8. System.Collections.ICollection MyIlist = t as System.Collections.ICollection;
  9. foreach (var l in MyIlist)
  10. {
  11. SetReflectionObject(l);
  12. }
  13. return t;
  14. }
  15. foreach (System.Reflection.PropertyInfo item in properties)
  16. {
  17. if (item.GetValue(t, null) == null)
  18. {
  19. if (item.PropertyType.Name.StartsWith("String"))
  20. {
  21. item.SetValue(t, "");
  22. }
  23. if (item.PropertyType.Name.StartsWith("List"))
  24. {
  25. item.SetValue(t, Activator.CreateInstance(item.PropertyType));
  26. }
  27. }
  28. else if (item.PropertyType.Name.StartsWith("List"))
  29. {
  30. System.Collections.ICollection Ilist = item.GetValue(t, null) as System.Collections.ICollection;
  31. foreach (var l in Ilist)
  32. {
  33. SetReflectionObject(l);
  34. }
  35. }
  36. }
  37. return t;
  38. }
2017-01-11 16:35:43    143    0    0

using System;
using System.Runtime.InteropServices;

namespace CrtAsmOfEmbeded_x86
{
static partial class Program
{
[DllImport("kernel32.dll", SetLastError = true)]
private static extern bool VirtualProtect(byte[] lpAddress, int dwSize, uint flNewProtect, out uint lpflOldProtect);

  1. [DllImport("user32.dll", SetLastError = true)]
  2. private static extern IntPtr CallWindowProc(byte[] lpPrevWndFunc, int hWnd, int Msg, int wParam, int lParam);
  3. private const int NULL = 0;
  4. private const int PAGE_EXECUTE_READWRITE = 64;
  5. }
  6. static partial class Program
  7. {
  8. private static readonly byte[] buf_asm = { 85, 139, 236, 129, 236, 192, 0, 0, 0, 83, 86, 87, 141, 189, 64, 255, 255, 255, 185, 48, 0, 0, 0, 184, 204, 204, 204, 204, 243, 171, 184, 0, 0, 0, 0, 51, 210, 15, 162, 137, 85, 252, 137, 69, 248, 184, 1, 0, 0, 0, 51, 201, 51, 210, 15, 162, 137, 85, 244, 137, 69, 240, 139, 69, 252, 137, 69, 236, 139, 69, 24
2017-05-22 11:46:26    131    0    0

http://www.52pojie.cn/thread-289232-1-1.html

 

 

 

 

 

这里就需要修复了 
看了论坛的修复教程  很麻烦  

这里我们只需要CFF Explorer


打开CFF Explorer 


拖入dump完成的文件  

 

2017-05-17 17:40:00    141    0    0

class A1
{
public A1()
{ Console.WriteLine("1"); }
~A1()
{ Console.WriteLine("1"); }
}
class A2
{
public A2()
{ Console.WriteLine("2"); }
~A2()
{ Console.WriteLine("2"); }
}
class A3
{
public A3()
{ Console.WriteLine("3"); }
~A3()
{ Console.WriteLine("3"); }
}

  1. class Test
  2. {
  3. public void Get23333()
  4. {
  5. new A1();
  6. new A2();
  7. new A3();
  8. GC.Collect();
  9. }
  10. }
2017-01-19 17:14:32    119    0    0
  1. [DllImport("NvTemp.dll", EntryPoint = "GetTemperature")]
  2. public static extern bool GetTemperature(ulong[] temp);
2017-01-16 16:14:14    84    0    0
  1. ~ClassName() //
  2. {
  3. }
2017-01-16 16:12:16    204    0    0
  1. //反调试 程序一旦被调试 则跳出
  2. if (System.Diagnostics.Debugger.IsAttached)
  3. {
  4. //也可以添加其他操作
  5. Application.Current.Shutdown();//比如关闭WPF程序
  6. }
3/3