Skip to content

Proposal: It is hoped that the CastExtensions.As<T>() extension method can be consistent with the .NET as keyword behavior #2148

@Gaoyifei1011

Description

@Gaoyifei1011

Summary

It is hoped that the CastExtensions.As<T>() extension method can be consistent with the .NET as keyword behavior

--------------------------------------------

希望能把 CastExtensions.As<T>() 扩展方法与 .NET as 关键字行为保持一致

Rationale

As shown in the figure, if the as keyword in .NET encounters a type that cannot be converted, it returns null, while the CastExtension.As<T> extension method in WinRT throws an exception. Can the behavior of the as keyword in .NET be consistent in the future? Or provide an extension method similar to TryAs, with a Boolean return value, and return the relevant object through the out parameter?

--------------------------------------------

如图所示,.NETas 关键字,如果遇到转换不过去的类型,返回 null,而 WinRTCastExtension.As<T> 扩展方法抛出异常,未来能与 .NET as 关键字行为保持一致吗?或者提供一个类似 TryAs 的扩展方法,返回值为布尔值,通过 out 参数返回相关对象?


Image

Important Notes

None

Open Questions

None

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions