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 committed Nov 8, 2021
1 parent 8cc85d9 commit e8942ab
Show file tree
Hide file tree
Showing 21 changed files with 1,433 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/NetAnalyzers/Core/AnalyzerReleases.Unshipped.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ Rule ID | Category | Severity | Notes
--------|----------|----------|-------
CA1849 | Performance | Disabled | UseAsyncMethodInAsyncContext, [Documentation](https://docs.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1849)
CA1850 | Performance | Info | PreferHashDataOverComputeHashAnalyzer, [Documentation](https://docs.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1850)
CA2019 | Reliability | Warning | DoNotCallEnumerableCastOrOfTypeWithIncompatibleTypesAnalyzer, [Documentation](https://docs.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2017)
CA5404 | Security | Disabled | DoNotDisableTokenValidationChecks, [Documentation](https://docs.microsoft.com/visualstudio/code-quality/ca5404)
CA5405 | Security | Disabled | DoNotAlwaysSkipTokenValidationInDelegates, [Documentation](https://docs.microsoft.com/visualstudio/code-quality/ca5405)
Original file line number Diff line number Diff line change
Expand Up @@ -1089,6 +1089,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 @@ -1776,6 +1782,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 @@ -502,6 +502,32 @@
<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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,32 @@
<target state="translated">Wenn eine Instanz der Klasse "{0}" deserialisiert wird, kann die Methode "{1}" die gefährliche Methode "{2}" aufrufen. Mögliche Methodenaufrufe: {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">Wenn ein Konstruktor eine virtuelle Methode aufruft, wurde der Konstruktor für die Instanz, die die Methode aufruft, möglicherweise nicht ausgeführt.</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,32 @@
<target state="translated">Al deserializar una instancia de la clase {0}, el método {1} puede llamar al método peligroso {2}. Invocaciones de métodos posibles: {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">Cuando un constructor llama a un método virtual, es posible que no se haya ejecutado el constructor para la instancia que invoca el método.</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,32 @@
<target state="translated">Quand vous désérialisez une instance de la classe {0}, la méthode {1} peut appeler une méthode dangereuse {2}. Les appels de méthode potentiels sont : {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">Quand un constructeur appelle une méthode virtuelle, le constructeur de l'instance qui appelle la méthode n'a peut-être pas été exécuté.</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,32 @@
<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>
Expand Down
Loading

0 comments on commit e8942ab

Please sign in to comment.