Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Reflection;
- using System.Reflection.Emit;
- public class B
- {
- private Type _gtype;
- public void AssignWhatTypeWeWantToWtf(Type t)
- {
- _gtype = t;
- }
- private Dictionary<string, Type> getWtfFields()
- {
- var t = _gtype.GetFields();
- var dic = new Dictionary<string, Type>();
- for (int i = 0; i < t.Length; i++)
- {
- dic.Add(t[i].Name+"1", t[i].FieldType);
- dic.Add(t[i].Name+"2", t[i].FieldType);//sorka za takie podwajanie ale juz nie wiem co ja pisze i stracilem wiare w sens tego programu
- }
- return dic;
- }
- private string getWtfName()
- {
- return nameof(_gtype);
- }
- public void WtfWtfWtf()
- {
- AssemblyName wtfName = new AssemblyName("wtf");
- AssemblyBuilder ab =
- AppDomain.CurrentDomain.DefineDynamicAssembly(
- wtfName,
- AssemblyBuilderAccess.RunAndSave);
- ModuleBuilder mb =
- ab.DefineDynamicModule(wtfName.Name, wtfName.Name + ".dll");
- TypeBuilder tb = mb.DefineType(getWtfName(),
- TypeAttributes.Public);
- foreach (var item in getWtfFields())
- {
- tb.DefineField(
- item.Key,
- item.Value,
- FieldAttributes.Public);
- }
- Type t = tb.CreateType();
- ab.Save(wtfName.Name + ".dll");
- object wtfUFOKURWALECI = Activator.CreateInstance(t);
- //można se stworzyć i zastanowić się ,przyjrzeć pomyśleć jakie to kurwa brzydkie i potem ... nie wiem
- }
- }
- public class A
- {
- public int a1;
- public string a2;
- }
- class WtfBuilder
- {
- public static void Main()
- {
- var typA = typeof(A);
- var typB = new B();
- typB.AssignWhatTypeWeWantToWtf(typA);
- typB.WtfWtfWtf();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement