none
need help in Emit coding RRS feed

  • Question

  • I want to this

    public void Set(SqlDataReader source, MyRuntimeDynamicClass target)
    {
    target.Field1 = source.Field1; // XXX
    target.Field2 = source.Field2; // XXX
    }
    

    I managed to code up to

          AssemblyName assemblyName = new AssemblyName();
          assemblyName.Name = "DynamicPropertySetterAssembly";
    
          AssemblyBuilder newAssembly = AppDomain.CurrentDomain.DefineDynamicAssembly(assemblyName, AssemblyBuilderAccess.Run);
          ModuleBuilder newModule = newAssembly.DefineDynamicModule("DynamicPropertySetterModule");
          TypeBuilder newClass = newModule.DefineType("DynamicPropertySetterClass", TypeAttributes.Class | TypeAttributes.Public);
          MethodBuilder newMth = newClass.DefineMethod("Set", MethodAttributes.Public, CallingConventions.Standard, null, new Type[] { typeof(SqlDataReader), target.GetType() });
          ILGenerator il = newMth.GetILGenerator();
    
          DataTable schemaTbl = source.GetSchemaTable();
    
          foreach (DataRow row in schemaTbl.Rows)
          {
            string clmNm = (string)row["ColumnName"];
            // XXX
          }
    

     

    how to code the XXX part?

    I guess it involve about 3-4-more il.Emit() ....

     

    Tuesday, June 29, 2010 5:03 AM

Answers