public DefineExplicitInterfaceImplementation ( |
||
baseMethod | ||
return | ILGen |
private ILGen MakeRawKeysMethod() { FieldBuilder rawKeysCache = TypeGen.AddStaticField(typeof(SymbolId[]), "ExtraKeysCache"); ILGen init = TypeGen.TypeInitializer; init.EmitInt(_fields.Count); init.Emit(OpCodes.Newarr, typeof(SymbolId)); int current = 0; foreach (GlobalVariableExpression variable in _fields.Keys) { init.Emit(OpCodes.Dup); init.EmitInt(current++); EmitSymbolId(init, SymbolTable.StringToId(variable.Name)); init.EmitStoreElement(typeof(SymbolId)); } init.Emit(OpCodes.Stsfld, rawKeysCache); MethodInfo baseMethod = typeof(CustomSymbolDictionary).GetMethod("GetExtraKeys", BindingFlags.Public | BindingFlags.Instance); ILGen cg = TypeGen.DefineExplicitInterfaceImplementation(baseMethod); cg.Emit(OpCodes.Ldsfld, rawKeysCache); cg.Emit(OpCodes.Ret); return(cg); }
private void MakeInitialization() { TypeGen.TypeBuilder.AddInterfaceImplementation(typeof(IModuleDictionaryInitialization)); MethodInfo baseMethod = typeof(IModuleDictionaryInitialization).GetMethod("InitializeModuleDictionary"); ILGen cg = TypeGen.DefineExplicitInterfaceImplementation(baseMethod); Label ok = cg.DefineLabel(); cg.EmitFieldGet(_contextField); cg.Emit(OpCodes.Ldnull); cg.Emit(OpCodes.Ceq); cg.Emit(OpCodes.Brtrue_S, ok); cg.EmitNew(typeof(InvalidOperationException), Type.EmptyTypes); cg.Emit(OpCodes.Throw); cg.MarkLabel(ok); // arg0 -> this // arg1 -> MyModuleDictType.ContextSlot cg.EmitLoadArg(1); cg.EmitFieldSet(_contextField); ConstructorInfo wrapperCtor = typeof(ModuleGlobalWrapper).GetConstructor(new Type[] { typeof(CodeContext), typeof(SymbolId) }); foreach (KeyValuePair <GlobalVariableExpression, FieldBuilder> kv in _fields) { // wrapper = new ModuleGlobalWrapper(context, name); cg.EmitLoadArg(1); EmitSymbolId(cg, SymbolTable.StringToId(kv.Key.Name)); cg.Emit(OpCodes.Newobj, wrapperCtor); cg.Emit(OpCodes.Stsfld, kv.Value); } cg.Emit(OpCodes.Ret); }