?-6ren"> ?-方法签名如下: public interface TestInterface { void SampleMethodOut(out int? nullableInt); void Sa-6ren">
gpt4 book ai didi

c# - 如果方法参数也是 "out"参数,如何使用反射检查方法参数是否为 Nullable<>?

转载 作者:行者123 更新时间:2023-11-30 22:29:45 25 4
gpt4 key购买 nike

方法签名如下:

public interface TestInterface
{
void SampleMethodOut(out int? nullableInt);
void SampleMethod(int? nullableInt);
}

我正在使用 typeof(TestInterface).GetMethods()[1].GetParameters()[0].ParameterType 获取类型,然后检查 IsGenericTypeNullable.GetUnderlyingType。如何使用带有 out 参数的方法执行此操作?

最佳答案

哎呀,无视我之前的回答

您使用 Type.IsByRef,如果是,则调用 Type.GetElementType():

var type = method.GetParameters()[0].ParameterType;
if (type.IsByRef)
{
// Remove the ref/out-ness
type = type.GetElementType();
}

关于c# - 如果方法参数也是 "out"参数,如何使用反射检查方法参数是否为 Nullable<>?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10032162/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com