microsoft / microsoft/CsWinRT

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

Open
#2,148 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C#
Stars
665
Forks
134
Avg merge
1d 3h
Merged PRs (30d)
32

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the CastExtensions.As() extension method and compare its exception behavior with the .NET as keyword described in the issue. Determine whether the desired result is null on an unsuccessful conversion or a TryAs-style Boolean and out-parameter API; the work is done when the chosen behavior is implemented and covered by relevant tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
desktop
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.