Advertisement
Guest User

Untitled

a guest
Jun 28th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.18 KB | None | 0 0
  1. private class ModifiableTouchLocationState {
  2.  
  3.   delegate void SetFieldDelegate<FieldType>(
  4.     object touchLocationState, FieldType value
  5.   );
  6.  
  7.   /// <summary>Initializes the static members of the class</summary>
  8.   static ModifiableTouchLocationState() {
  9.     touchLocationStateType = typeof(TouchCollection).Assembly.GetType(
  10.       "Microsoft.Xna.Framework.Input.Touch.XNAINPUT_TOUCH_LOCATION_STATE"
  11.     );
  12.  
  13.     BindingFlags publicField = BindingFlags.Instance | BindingFlags.Public;
  14.  
  15.     FieldInfo countField = touchLocationStateType.GetField("Count", publicField);
  16.     FieldInfo id0Field = touchLocationStateType.GetField("Id0", publicField);
  17.     FieldInfo id1Field = touchLocationStateType.GetField("Id1", publicField);
  18.     FieldInfo id2Field = touchLocationStateType.GetField("Id2", publicField);
  19.     FieldInfo id3Field = touchLocationStateType.GetField("Id3", publicField);
  20.     FieldInfo x0Field = touchLocationStateType.GetField("X0", publicField);
  21.     FieldInfo y0Field = touchLocationStateType.GetField("Y0", publicField);
  22.     FieldInfo x1Field = touchLocationStateType.GetField("X1", publicField);
  23.     FieldInfo y1Field = touchLocationStateType.GetField("Y1", publicField);
  24.     FieldInfo x2Field = touchLocationStateType.GetField("X2", publicField);
  25.     FieldInfo y2Field = touchLocationStateType.GetField("Y2", publicField);
  26.     FieldInfo x3Field = touchLocationStateType.GetField("X3", publicField);
  27.     FieldInfo y3Field = touchLocationStateType.GetField("Y3", publicField);
  28.  
  29.     var dynamicMethod = new DynamicMethod(
  30.       "SetCount", null, new Type[] { typeof(int) }
  31.     );
  32.     ILGenerator ilGenerator = dynamicMethod.GetILGenerator();
  33.     ilGenerator.Emit(OpCodes.Ldarg_0);
  34.     ilGenerator.Emit(OpCodes.Stfld, countField);
  35.     ilGenerator.Emit(OpCodes.Ret);
  36.  
  37.        
  38.     //setfielddelegate<int>
  39.     //delegate test = dynamicmethod.createdelegate(typeof(setfielddelegate<int>));
  40.   }
  41.  
  42.   public ModifiableTouchLocationState() {
  43.     this.boxedState = Activator.CreateInstance(touchLocationStateType);
  44.   }
  45.  
  46.   private static Type touchLocationStateType;
  47.   //private static ConstructorInfo constructor;
  48.   //private static FieldInfo countField;
  49.   private object boxedState;
  50.  
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement