Skip to content

Commit

Permalink
New Analyzer: Do not call Enumerable.Cast<T> or Enumerable.OfType<T> …
Browse files Browse the repository at this point in the history
…ith incompatible types
  • Loading branch information
fowl2 authored and James May committed Jan 9, 2023
1 parent 0b2bc22 commit 567cd4c
Show file tree
Hide file tree
Showing 17 changed files with 1,504 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/NetAnalyzers/Core/AnalyzerReleases.Unshipped.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ CA1856 | Performance | Error | ConstantExpectedAnalyzer, [Documentation](https:/
CA1857 | Performance | Warning | ConstantExpectedAnalyzer, [Documentation](https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1857)
CA1858 | Performance | Info | UseStartsWithInsteadOfIndexOfComparisonWithZero, [Documentation](https://docs.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1858)
CA1859 | Performance | Info | UseConcreteTypeAnalyzer, [Documentation](https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1859)
CA2019 | Reliability | Warning | DoNotCallEnumerableCastOrOfTypeWithIncompatibleTypesAnalyzer, [Documentation](https://docs.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2017)

### Removed Rules

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1008,6 +1008,12 @@
<data name="DoNotAddArchiveItemPathToTheTargetFileSystemPathMessage" xml:space="preserve">
<value>When creating path for '{0} in method {1}' from relative archive item path to extract file and the source is an untrusted zip archive, make sure to sanitize relative archive item path '{2} in method {3}'</value>
</data>
<data name="DoNotCallEnumerableCastOrOfTypeWithIncompatibleTypesTitle" xml:space="preserve">
<value>Do not call Enumerable.Cast&lt;T&gt; or Enumerable.OfType&lt;T&gt; with incompatible types</value>
</data>
<data name="DoNotCallEnumerableCastOrOfTypeWithIncompatibleTypesMessageOfType" xml:space="preserve">
<value>This call will always result in an empty sequence because type '{0}' is incompatible with type '{1}'</value>
</data>
<data name="DoNotCreateTasksWithoutPassingATaskSchedulerTitle" xml:space="preserve">
<value>Do not create tasks without passing a TaskScheduler</value>
</data>
Expand Down Expand Up @@ -1722,6 +1728,15 @@
<data name="ModuleInitializerAttributeShouldNotBeUsedInLibrariesTitle" xml:space="preserve">
<value>The 'ModuleInitializer' attribute should not be used in libraries</value>
</data>
<data name="DoNotCallEnumerableCastOrOfTypeWithIncompatibleTypesDescription" xml:space="preserve">
<value>Enumerable.Cast&lt;T&gt; and Enumerable.OfType&lt;T&gt; require compatible types to function expectedly.
The generic cast (IL 'unbox.any') used by the sequenced returned by Enumerable.Cast&lt;T&gt; will throw InvalidCastException at runtime on elements of the types specified.
The generic type check (C# 'is' operator/IL 'isinst') used by Enumerable.OfType&lt;T&gt; will never succeed with elements of types specified, resulting in an empty sequence.
Widening and user defined conversions are not supported with generic types.</value>
</data>
<data name="DoNotCallEnumerableCastOrOfTypeWithIncompatibleTypesMessageCast" xml:space="preserve">
<value>Type '{0}' is incompatible with type '{1}' and cast attempts will throw InvalidCastException at runtime</value>
</data>
<data name="UseAsyncMethodInAsyncContextMessage" xml:space="preserve">
<value>'{0}' synchronously blocks. Await '{1}' instead.</value>
</data>
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,47 @@
<target state="translated">Při deserializaci instance třídy {0} může metoda {1} volat nebezpečnou metodu {2}. Možná volání metod: {3}</target>
<note />
</trans-unit>
<trans-unit id="DoNotCallEnumerableCastOrOfTypeWithIncompatibleTypesDescription">
<source>Enumerable.Cast&lt;T&gt; and Enumerable.OfType&lt;T&gt; require compatible types to function expectedly.
The generic cast (IL 'unbox.any') used by the sequenced returned by Enumerable.Cast&lt;T&gt; will throw InvalidCastException at runtime on elements of the types specified.
The generic type check (C# 'is' operator/IL 'isinst') used by Enumerable.OfType&lt;T&gt; will never succeed with elements of types specified, resulting in an empty sequence.
Widening and user defined conversions are not supported with generic types.</source>
<target state="new">Enumerable.Cast&lt;T&gt; and Enumerable.OfType&lt;T&gt; require compatible types to function expectedly.
The generic cast (IL 'unbox.any') used by the sequenced returned by Enumerable.Cast&lt;T&gt; will throw InvalidCastException at runtime on elements of the types specified.
The generic type check (C# 'is' operator/IL 'isinst') used by Enumerable.OfType&lt;T&gt; will never succeed with elements of types specified, resulting in an empty sequence.
Widening and user defined conversions are not supported with generic types.</target>
<note />
</trans-unit>
<trans-unit id="DoNotCallEnumerableCastOrOfTypeWithIncompatibleTypesMessageCast">
<source>Type '{0}' is incompatible with type '{1}' and cast attempts will throw InvalidCastException at runtime</source>
<target state="new">Type '{0}' is incompatible with type '{1}' and cast attempts will throw InvalidCastException at runtime</target>
<note />
</trans-unit>
<trans-unit id="DoNotCallEnumerableCastOrOfTypeWithIncompatibleTypesMessageOfType">
<source>This call will always result in an empty sequence because type '{0}' is incompatible with type '{1}'</source>
<target state="new">This call will always result in an empty sequence because type '{0}' is incompatible with type '{1}'</target>
<note />
</trans-unit>
<trans-unit id="DoNotCallEnumerableCastOrOfTypeWithIncompatibleTypesTitle">
<source>Do not call Enumerable.Cast&lt;T&gt; or Enumerable.OfType&lt;T&gt; with incompatible types</source>
<target state="new">Do not call Enumerable.Cast&lt;T&gt; or Enumerable.OfType&lt;T&gt; with incompatible types</target>
<note />
</trans-unit>
<trans-unit id="DoNotCallOverridableMethodsInConstructorsDescription">
<source>When a constructor calls a virtual method, the constructor for the instance that invokes the method may not have executed.</source>
<target state="translated">Když konstruktor zavolá virtuální metodu, konstruktor dané instance, která metodu vyvolala, se nemusí spustit.</target>
<note />
</trans-unit>
<trans-unit id="DoNotCallOverridableMethodsInConstructorsMessage">
<source>Do not call overridable methods in constructors</source>
<target state="translated">Nevolejte přepsatelné metody v konstruktorech</target>
<note />
</trans-unit>
<trans-unit id="DoNotCallOverridableMethodsInConstructorsTitle">
<source>Do not call overridable methods in constructors</source>
<target state="translated">Nevolejte přepsatelné metody v konstruktorech</target>
<note />
</trans-unit>
<trans-unit id="DoNotCallToImmutableCollectionOnAnImmutableCollectionValueMessage">
<source>Do not call {0} on an {1} value</source>
<target state="translated">Nevolejte {0} pro hodnotu {1}.</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,47 @@
<target state="translated">Durante la deserializzazione di un'istanza della classe {0} il metodo {1} può chiamare il metodo pericoloso {2}. Le potenziali chiamate al metodo sono: {3}.</target>
<note />
</trans-unit>
<trans-unit id="DoNotCallEnumerableCastOrOfTypeWithIncompatibleTypesDescription">
<source>Enumerable.Cast&lt;T&gt; and Enumerable.OfType&lt;T&gt; require compatible types to function expectedly.
The generic cast (IL 'unbox.any') used by the sequenced returned by Enumerable.Cast&lt;T&gt; will throw InvalidCastException at runtime on elements of the types specified.
The generic type check (C# 'is' operator/IL 'isinst') used by Enumerable.OfType&lt;T&gt; will never succeed with elements of types specified, resulting in an empty sequence.
Widening and user defined conversions are not supported with generic types.</source>
<target state="new">Enumerable.Cast&lt;T&gt; and Enumerable.OfType&lt;T&gt; require compatible types to function expectedly.
The generic cast (IL 'unbox.any') used by the sequenced returned by Enumerable.Cast&lt;T&gt; will throw InvalidCastException at runtime on elements of the types specified.
The generic type check (C# 'is' operator/IL 'isinst') used by Enumerable.OfType&lt;T&gt; will never succeed with elements of types specified, resulting in an empty sequence.
Widening and user defined conversions are not supported with generic types.</target>
<note />
</trans-unit>
<trans-unit id="DoNotCallEnumerableCastOrOfTypeWithIncompatibleTypesMessageCast">
<source>Type '{0}' is incompatible with type '{1}' and cast attempts will throw InvalidCastException at runtime</source>
<target state="new">Type '{0}' is incompatible with type '{1}' and cast attempts will throw InvalidCastException at runtime</target>
<note />
</trans-unit>
<trans-unit id="DoNotCallEnumerableCastOrOfTypeWithIncompatibleTypesMessageOfType">
<source>This call will always result in an empty sequence because type '{0}' is incompatible with type '{1}'</source>
<target state="new">This call will always result in an empty sequence because type '{0}' is incompatible with type '{1}'</target>
<note />
</trans-unit>
<trans-unit id="DoNotCallEnumerableCastOrOfTypeWithIncompatibleTypesTitle">
<source>Do not call Enumerable.Cast&lt;T&gt; or Enumerable.OfType&lt;T&gt; with incompatible types</source>
<target state="new">Do not call Enumerable.Cast&lt;T&gt; or Enumerable.OfType&lt;T&gt; with incompatible types</target>
<note />
</trans-unit>
<trans-unit id="DoNotCallOverridableMethodsInConstructorsDescription">
<source>When a constructor calls a virtual method, the constructor for the instance that invokes the method may not have executed.</source>
<target state="translated">Quando un costruttore chiama un metodo virtuale, è possibile che il costruttore per l'istanza che richiama il metodo non sia stato eseguito.</target>
<note />
</trans-unit>
<trans-unit id="DoNotCallOverridableMethodsInConstructorsMessage">
<source>Do not call overridable methods in constructors</source>
<target state="translated">Non chiamare metodi sottoponibili a override nei costruttori</target>
<note />
</trans-unit>
<trans-unit id="DoNotCallOverridableMethodsInConstructorsTitle">
<source>Do not call overridable methods in constructors</source>
<target state="translated">Non chiamare metodi sottoponibili a override nei costruttori</target>
<note />
</trans-unit>
<trans-unit id="DoNotCallToImmutableCollectionOnAnImmutableCollectionValueMessage">
<source>Do not call {0} on an {1} value</source>
<target state="translated">Non chiamare {0} su un valore {1}</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,47 @@
<target state="translated">クラス {0} のインスタンスを逆シリアル化すると、メソッド {1} によって危険なメソッド {2} を呼び出されるおそれがあります。考えられるメソッド呼び出し: {3}。</target>
<note />
</trans-unit>
<trans-unit id="DoNotCallEnumerableCastOrOfTypeWithIncompatibleTypesDescription">
<source>Enumerable.Cast&lt;T&gt; and Enumerable.OfType&lt;T&gt; require compatible types to function expectedly.
The generic cast (IL 'unbox.any') used by the sequenced returned by Enumerable.Cast&lt;T&gt; will throw InvalidCastException at runtime on elements of the types specified.
The generic type check (C# 'is' operator/IL 'isinst') used by Enumerable.OfType&lt;T&gt; will never succeed with elements of types specified, resulting in an empty sequence.
Widening and user defined conversions are not supported with generic types.</source>
<target state="new">Enumerable.Cast&lt;T&gt; and Enumerable.OfType&lt;T&gt; require compatible types to function expectedly.
The generic cast (IL 'unbox.any') used by the sequenced returned by Enumerable.Cast&lt;T&gt; will throw InvalidCastException at runtime on elements of the types specified.
The generic type check (C# 'is' operator/IL 'isinst') used by Enumerable.OfType&lt;T&gt; will never succeed with elements of types specified, resulting in an empty sequence.
Widening and user defined conversions are not supported with generic types.</target>
<note />
</trans-unit>
<trans-unit id="DoNotCallEnumerableCastOrOfTypeWithIncompatibleTypesMessageCast">
<source>Type '{0}' is incompatible with type '{1}' and cast attempts will throw InvalidCastException at runtime</source>
<target state="new">Type '{0}' is incompatible with type '{1}' and cast attempts will throw InvalidCastException at runtime</target>
<note />
</trans-unit>
<trans-unit id="DoNotCallEnumerableCastOrOfTypeWithIncompatibleTypesMessageOfType">
<source>This call will always result in an empty sequence because type '{0}' is incompatible with type '{1}'</source>
<target state="new">This call will always result in an empty sequence because type '{0}' is incompatible with type '{1}'</target>
<note />
</trans-unit>
<trans-unit id="DoNotCallEnumerableCastOrOfTypeWithIncompatibleTypesTitle">
<source>Do not call Enumerable.Cast&lt;T&gt; or Enumerable.OfType&lt;T&gt; with incompatible types</source>
<target state="new">Do not call Enumerable.Cast&lt;T&gt; or Enumerable.OfType&lt;T&gt; with incompatible types</target>
<note />
</trans-unit>
<trans-unit id="DoNotCallOverridableMethodsInConstructorsDescription">
<source>When a constructor calls a virtual method, the constructor for the instance that invokes the method may not have executed.</source>
<target state="translated">コンストラクターが仮想メソッドを呼び出すときに、メソッドを呼び出すインスタンスのコンストラクターは実行されていない可能性があります。</target>
<note />
</trans-unit>
<trans-unit id="DoNotCallOverridableMethodsInConstructorsMessage">
<source>Do not call overridable methods in constructors</source>
<target state="translated">コンストラクターのオーバーライド可能なメソッドを呼び出しません</target>
<note />
</trans-unit>
<trans-unit id="DoNotCallOverridableMethodsInConstructorsTitle">
<source>Do not call overridable methods in constructors</source>
<target state="translated">コンストラクターのオーバーライド可能なメソッドを呼び出しません</target>
<note />
</trans-unit>
<trans-unit id="DoNotCallToImmutableCollectionOnAnImmutableCollectionValueMessage">
<source>Do not call {0} on an {1} value</source>
<target state="translated">{1} 値で {0} を呼び出さないでください</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,47 @@
<target state="translated">{0} 클래스의 인스턴스를 역직렬화할 때 {1} 메서드가 위험한 메서드 {2}을(를) 호출할 수 있습니다. 잠재적인 메서드 호출은 {3}입니다.</target>
<note />
</trans-unit>
<trans-unit id="DoNotCallEnumerableCastOrOfTypeWithIncompatibleTypesDescription">
<source>Enumerable.Cast&lt;T&gt; and Enumerable.OfType&lt;T&gt; require compatible types to function expectedly.
The generic cast (IL 'unbox.any') used by the sequenced returned by Enumerable.Cast&lt;T&gt; will throw InvalidCastException at runtime on elements of the types specified.
The generic type check (C# 'is' operator/IL 'isinst') used by Enumerable.OfType&lt;T&gt; will never succeed with elements of types specified, resulting in an empty sequence.
Widening and user defined conversions are not supported with generic types.</source>
<target state="new">Enumerable.Cast&lt;T&gt; and Enumerable.OfType&lt;T&gt; require compatible types to function expectedly.
The generic cast (IL 'unbox.any') used by the sequenced returned by Enumerable.Cast&lt;T&gt; will throw InvalidCastException at runtime on elements of the types specified.
The generic type check (C# 'is' operator/IL 'isinst') used by Enumerable.OfType&lt;T&gt; will never succeed with elements of types specified, resulting in an empty sequence.
Widening and user defined conversions are not supported with generic types.</target>
<note />
</trans-unit>
<trans-unit id="DoNotCallEnumerableCastOrOfTypeWithIncompatibleTypesMessageCast">
<source>Type '{0}' is incompatible with type '{1}' and cast attempts will throw InvalidCastException at runtime</source>
<target state="new">Type '{0}' is incompatible with type '{1}' and cast attempts will throw InvalidCastException at runtime</target>
<note />
</trans-unit>
<trans-unit id="DoNotCallEnumerableCastOrOfTypeWithIncompatibleTypesMessageOfType">
<source>This call will always result in an empty sequence because type '{0}' is incompatible with type '{1}'</source>
<target state="new">This call will always result in an empty sequence because type '{0}' is incompatible with type '{1}'</target>
<note />
</trans-unit>
<trans-unit id="DoNotCallEnumerableCastOrOfTypeWithIncompatibleTypesTitle">
<source>Do not call Enumerable.Cast&lt;T&gt; or Enumerable.OfType&lt;T&gt; with incompatible types</source>
<target state="new">Do not call Enumerable.Cast&lt;T&gt; or Enumerable.OfType&lt;T&gt; with incompatible types</target>
<note />
</trans-unit>
<trans-unit id="DoNotCallOverridableMethodsInConstructorsDescription">
<source>When a constructor calls a virtual method, the constructor for the instance that invokes the method may not have executed.</source>
<target state="translated">생성자에서 가상 메서드를 호출하면 메서드를 호출하는 인스턴스에 대한 생성자가 실행되지 않을 수 있습니다.</target>
<note />
</trans-unit>
<trans-unit id="DoNotCallOverridableMethodsInConstructorsMessage">
<source>Do not call overridable methods in constructors</source>
<target state="translated">생성자에서 재정의 가능한 메서드를 호출하지 마세요.</target>
<note />
</trans-unit>
<trans-unit id="DoNotCallOverridableMethodsInConstructorsTitle">
<source>Do not call overridable methods in constructors</source>
<target state="translated">생성자에서 재정의 가능한 메서드를 호출하지 마세요.</target>
<note />
</trans-unit>
<trans-unit id="DoNotCallToImmutableCollectionOnAnImmutableCollectionValueMessage">
<source>Do not call {0} on an {1} value</source>
<target state="translated">{1} 값의 {0}을(를) 호출하지 마세요.</target>
Expand Down
Loading

0 comments on commit 567cd4c

Please sign in to comment.