예제 #1
0
 public static bool HasExplicitOrImplicitDefaultConstructor(this TypeDesc type)
 {
     return(type.IsValueType || type.GetDefaultConstructor() != null);
 }
        private TypeDesc EmitSafeHandleReturnValueMarshalling(TypeDesc type)
        {
            var nativeType = _context.GetWellKnownType(WellKnownType.IntPtr);

            var vSafeHandle = _emitter.NewLocal(type);
            var vReturnValue = _emitter.NewLocal(nativeType);

            _marshallingCodeStream.Emit(ILOpcode.newobj, _emitter.NewToken(type.GetDefaultConstructor()));
            _marshallingCodeStream.EmitStLoc(vSafeHandle);

            _returnValueMarshallingCodeStream.EmitStLoc(vReturnValue);

            _returnValueMarshallingCodeStream.EmitLdLoc(vSafeHandle);
            _returnValueMarshallingCodeStream.EmitLdLoc(vReturnValue);
            _returnValueMarshallingCodeStream.Emit(ILOpcode.call, _emitter.NewToken(
                this.SafeHandleType.GetKnownMethod("SetHandle", null)));

            _returnValueMarshallingCodeStream.EmitLdLoc(vSafeHandle);

            return nativeType;
        }