public static void EmitExtended(this ILGenerator il, OpCode opcode, Type type) { TypeConstruct tc = type as TypeConstruct; if (tc != null) { var mb = GetMethodBuilder(il); TypeToken token; if (mb is DynamicMethod) { throw new NotSupportedException(); /*var sig = SignatureTools.GetSigHelper(null); * sig.AddArgumentSignature(type); * object scope = GetDynamicScope(il); * int tok = GetTokenFor(scope, sig.GetSignature()); * tok &= 0x00FFFFFF; * tok |= 0x1b000000; * token = NewTypeToken(tok);*/ } else { token = GetTypeTokenExtended((ModuleBuilder)((MethodBuilder)mb).Module, type); } Emit(il, opcode, token); } else { il.Emit(opcode, type); } }
public static CorElementType GetCorElementType(this Type type) { TypeConstruct tc = type as TypeConstruct; if (tc != null) { return(tc.CorElementType); } else { return(GetCorElType.Invoke(type)); } }
public static TypeToken GetTypeTokenExtended(this ModuleBuilder builder, Type type) { TypeConstruct tc = type as TypeConstruct; if (tc != null || builder == null) { var sig = SignatureTools.GetSigHelper(builder); sig.AddArgumentSignature(type); return(GetTokenFromTypeSpec(builder, sig.GetSignature())); } else { return(builder.GetTypeToken(type)); } }
/// <summary> /// Creates a new field using extended field type. /// </summary> /// <param name="builder">The TypeBuilder where the field will be created.</param> /// <param name="name">The name of the field.</param> /// <param name="type">The extended field type.</param> /// <param name="attributes">The field attributes.</param> /// <returns>The created FieldBuilder.</returns> public static FieldBuilder DefineFieldExtended(this TypeBuilder builder, string name, Type type, FieldAttributes attributes) { TypeConstruct tc = type as TypeConstruct; if (tc == null) { return(builder.DefineField(name, type, attributes)); } var t = TypeOf <FieldBuilder> .TypeID; FieldBuilder fb = (FieldBuilder)FormatterServices.GetUninitializedObject(t); var mod = GetNativeModule((ModuleBuilder)builder.Module); SignatureHelper sig = SignatureHelper.GetFieldSigHelper(builder.Module); sig.AddElement(tc); byte[] sigd = sig.GetSignature(); int tok = DefineFieldInternal.Invoke(mod, builder.TypeToken.Token, name, sigd, sigd.Length, attributes); InitField.Invoke(fb, name, builder, type.UnderlyingSystemType, attributes, tok, NewFieldToken(tok, type.UnderlyingSystemType)); return(fb); }
public static void AddTypeToken(this SignatureHelper signature, Type type) { var mod = get_m_module(signature); TypeConstruct tcon = type as TypeConstruct; if (tcon != null) //generate TypeSpec for custom type { byte[] sig = BuilderTools.GetSignature(mod, tcon); TypeToken token = mod.GetTokenFromTypeSpec(sig); Sig_AddToken(signature, token.Token); } else if (type.IsByRef) //unsupported by GetTypeToken { SignatureHelper sig = SignatureTools.GetSigHelper(mod); sig.AddArgument(type); TypeToken token = mod.GetTokenFromTypeSpec(sig.GetSignature()); Sig_AddToken(signature, token.Token); } else { Sig_AddToken(signature, mod.GetTypeToken(type).Token); } }
public static TypeToken GetTypeToken(this ModuleBuilder builder, TypeConstruct tc) { return(GetTypeTokenExtended(builder, tc)); }