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?
--------------------------------------------
如图所示,.NET 的 as 关键字,如果遇到转换不过去的类型,返回 null,而 WinRT 的 CastExtension.As<T> 扩展方法抛出异常,未来能与 .NET as 关键字行为保持一致吗?或者提供一个类似 TryAs 的扩展方法,返回值为布尔值,通过 out 参数返回相关对象?
Important Notes
None
Open Questions
None
Summary
It is hoped that the
CastExtensions.As<T>()extension method can be consistent with the.NET askeyword behavior--------------------------------------------
希望能把
CastExtensions.As<T>()扩展方法与.NET as关键字行为保持一致Rationale
As shown in the figure, if the
askeyword in.NETencounters a type that cannot be converted, it returnsnull, while theCastExtension.As<T>extension method in WinRT throws an exception. Can the behavior of theaskeyword in.NETbe consistent in the future? Or provide an extension method similar toTryAs, with aBooleanreturn value, and return the relevant object through theoutparameter?--------------------------------------------
如图所示,
.NET的as关键字,如果遇到转换不过去的类型,返回null,而WinRT的CastExtension.As<T>扩展方法抛出异常,未来能与.NET as关键字行为保持一致吗?或者提供一个类似TryAs的扩展方法,返回值为布尔值,通过out参数返回相关对象?Important Notes
None
Open Questions
None