Zum Hauptinhalt springen
tsecurity.de LIVE
Echtzeit-Radar & Feeds
Alle RSS Feeds ➔
👥 Community & Social
YouTube Security VideosGoogle Cloud Tech: Gemini is coming to your city(24.09.2026 um 15:00 Uhr)
•
AI & KI NachrichtenGoogle’s latest moonshot to put machine learning in space(24.09.2026 um 15:12 Uhr)
•
Windows Tipps & SecurityPoll: What's your favorite Surface of 2026?(24.09.2026 um 14:58 Uhr)
•••
Sichere ProgrammierungStreaming Materialized Views for Live Read Models (2026)(24.09.2026 um 15:02 Uhr)
•
Sichere ProgrammierungA Day Is Not 86400 Seconds: The DST Bug in Your Date Math(24.09.2026 um 15:02 Uhr)
•
Sichere ProgrammierungSetting up Traefik: reverse proxy with automatic HTTPS(24.09.2026 um 15:02 Uhr)
•
Sichere ProgrammierungA 200 OK response does not prove a secret leak(24.09.2026 um 15:02 Uhr)
•
Sichere ProgrammierungHow hot do you like it?(24.09.2026 um 15:05 Uhr)
•
YouTube Security VideosGoogle Cloud Tech: Gemini is coming to your city(24.09.2026 um 15:00 Uhr)
•
AI & KI NachrichtenGoogle’s latest moonshot to put machine learning in space(24.09.2026 um 15:12 Uhr)
•
Windows Tipps & SecurityPoll: What's your favorite Surface of 2026?(24.09.2026 um 14:58 Uhr)
•••
Sichere ProgrammierungStreaming Materialized Views for Live Read Models (2026)(24.09.2026 um 15:02 Uhr)
•
Sichere ProgrammierungA Day Is Not 86400 Seconds: The DST Bug in Your Date Math(24.09.2026 um 15:02 Uhr)
•
Sichere ProgrammierungSetting up Traefik: reverse proxy with automatic HTTPS(24.09.2026 um 15:02 Uhr)
•
Sichere ProgrammierungA 200 OK response does not prove a secret leak(24.09.2026 um 15:02 Uhr)
•
Sichere ProgrammierungHow hot do you like it?(24.09.2026 um 15:05 Uhr)
•
Intelligence View
⚡ tsecurity.de Intelligence

Conditional application of chained LINQ queries

I write C# and I'm a big fan of using LINQ to create nice, readable chains of operations to filter and transform data in a functional style. int HighestEvenNumber(IEnumerable<int> numbers) => numbers .Where(x =>…

0
↗ Quelle (dev.to)
Reagiere als Erste:r — dein Feedback zählt!

I write C# and I'm a big fan of using LINQ to create nice, readable chains of operations to filter and transform data in a functional style.




int HighestEvenNumber(IEnumerable<int> numbers)
=> numbers
.Where(x => x % 2 == 0)
.OrderByDescending(x => x)
.FirstOrDefault();






Sometimes though, there are conditions where parts of the chain should be included or omitted, but breaking the chain to add an if-statement feels wrong and disruptive.



Let's say our previous example should throw an exception if there are no even numbers in the sequence instead of returning the default int value of 0.




int HighestEvenNumber(IEnumerable<int> numbers)
{
int[] evenNumbers = numbers
.Where(x => x % 2 == 0)
.ToArray();

if (evenNumbers.Length == 0)
{
throw new ArgumentException("No even numbers in sequence");
}

return evenNumbers
.OrderByDescending(x => x)
.First();
}






Thankfully it can be improved with a simple extension method (thanks, C#):




public static T If<T>(this T source, Func<T, bool> condition, Func<T, T> then)
=> condition(source) ? then(source) : source;






With this extension method in place, we can now write the LINQ query like this:




int HighestEvenNumber(IEnumerable<int> numbers)
=> numbers
.Where(x => x % 2 == 0)
.ToArray()
.If(evenNumbers => evenNumbers.Length == 0,
_ => throw new ArgumentException("No even numbers in sequence"))
.OrderByDescending(x => x)
.First();






And it just feels so much better, right?



This example might not seem very impressive, so let's try another:




string[] QueryMovieTitles(IEnumerable<Movie> movies, string? search = null, bool orderDesc = false, int limit = 10)
=> movies
.Select(movie => movie.Title)
.If(!string.IsNullOrEmpty(search),
titles => titles.Where(s => s.Contains(search, StringComparison.OrdinalIgnoreCase)))
.If(orderDesc,
titles => titles.OrderByDescending(s => s),
titles => titles.OrderBy(s => s))
.Take(limit)
.ToArray();






Of course, this is not simply an aesthetic improvement. The whole LINQ query is now a single expression which has some nice benefits, including:




  • You don't have to introduce temporary variables to store intermediate results

  • It can be used in an Expression lambda



The complete set of extension methods to cover most use-cases:




public static class IfExtensions
{
public static T If<T>(this T source, bool condition, Func<T, T> then)
=> condition ? then(source) : source;

public static TOut If<TIn, TOut>(this TIn source, bool condition, Func<TIn, TOut> then, Func<TIn, TOut> @else)
=> condition ? then(source) : @else(source);

public static T If<T>(this T source, Func<T, bool> condition, Func<T, T> then)
=> condition(source) ? then(source) : source;

public static TOut If<TIn, TOut>(this TIn source, Func<TIn, bool> condition, Func<TIn, TOut> then, Func<TIn, TOut> @else)
=> condition(source) ? then(source) : @else(source);
}






Enjoy!

SOC Incident Playbook: Remote Code Execution (RCE) Defense
title: Detect Exploitation - Conditional application of chained LINQ queries
id: ca8443b4-a669-4cfe-96d1-a9c0855ec59d
status: experimental
description: Automatisch generierte SIEM-Erkennungsregel basierend auf CTI Intelligence
references:
  - https://tsecurity.de/
author: iShareStuff CTI Automated Detection Engine
date: 2026-09-24
logsource:
  category: network_connection
  product: any
detection:
  selection:
      CommandLine|contains:
        - 'exploit'
  condition: selection
falsepositives:
  - Legitime administrative Zugriffe oder Penetrationstests
level: high
tags:
  - attack.initial_access
rule CTI_Threat_Indicator {
    meta:
        author = "iShareStuff CTI Automated Detection Engine"
        date = "2026-09-24"
        description = "YARA Signature for "
    strings:
        $str = "Conditional application of cha" ascii wide
    condition:
        any of them
}
tsecurity.de Cognitive Threat RAG
Fokus-Vektor:

Kognitive Analyse für identifizierte Bedrohung: Erhöhte Bedrohungslage im Bereich Conditional application of chained LINQ .... Basierend auf 368k Vektor-Korrelationen werden sofortige Isolationsmaßnahmen für betroffene Endpunkte empfohlen.

🛡️ Angriffsfläche & Exposure

Netzwerk/Remote-Zugriff ohne Vorauthentifizierung möglich.

⚡ Empfohlene Sofortmaßnahmen
  • 1. Perimeter-Inspektion: Relevante Portfreigaben und exponierte Endpunkte unverzüglich scannen.
  • 2. Patch-Applikation: Hersteller-Hotfix einspielen oder betroffene Daemons in isolierte DMZ-Segmente überführen.
  • 3. Telemetrie & EDR-Alerts: Prozessaufrufe und Child-Processes auf anomale Shell-Spawns überwachen.
🔗 Semantisch verwandte Zero-Days MariaDB 11.7 VEC
Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten Conditional application of chained LINQ queries

Thematisch verwandte Begriffe: Conditional, application, chained, LINQ · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Zum Aktualisieren ziehen
ZERO-DAY CVE-2026-97152 | Nanomsg versions 0.5-beta through 1.x before 1.2.3 has a remotely exploi…
Advisory →
TTS Reader • tsecurity.de Voice
tsecurity.de Icon
tsecurity.de App
Offline-Lesen, Eilmeldungen & 0ms Ladezeit

Installiere tsecurity.de direkt auf deinen Home-Bildschirm für das ultimative Vollbild-Magazinerlebnis ohne Browser-Leisten.

Nächster Beitrag
Themen-Radar & Intelligence Matrix
Echtzeit-Taxonomie nach Angriffsvektoren & Plattformen

tsecurity.de Live Threat Radar

🔴 LIVE RADAR
MONITORING
AKTIV
CVE-DATENBANK
LIVE
🔍
Community Radar & Live Chat
Sentinel Bot online • Live-Stream
Dein Cluster: Security Explorer
Match:
lädt…
Verbindung zum Community-Stream wird aufgebaut...
Bearbeitungsmodus — Senden überschreibt deine Nachricht
Community-Puls — was gerade passiert
lädt…
Aktivitäten deiner Analysten
lädt…
Neues Thema oder Eilmeldung einreichen

Reiche interessante Links, Zero-Days oder Debatten ein. Die Community entscheidet per Upvote über die Veröffentlichung.

Heiß diskutierte Einreichungen
🔖 Gespeicherte Artikel
📂 Keine gespeicherten Artikel vorhanden.
Zurück Ziehen Vor
Links: vorheriger Artikel • Rechts: nächster Artikel • unten: schließen
News NIS-2 Frühwarnung Tier-1 Intel TTP ⏱️ 3 Min vor 10 Min
Artikeldaten werden geladen...

Zurück: vorheriger • Vor: nächster
↗ Original-Quelle
Social Reaktionen Deine Reaktion zählt
Einstufung & Relevanz-Poll 0 Stimmen
In sozialen Netzwerken teilen 1-Klick