View Books.cshtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@page "/books" | |
@using BooksLib | |
@inject HttpClient Http | |
<h1>Books Sample</h1> | |
<p>This component demonstrates fetching data from Azure Functions.</p> | |
<p>Status: @message</p> |
View BooksFunction.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class BooksFunction | |
{ | |
[FunctionName("BooksFunction")] | |
public static IActionResult Run( | |
[HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)]HttpRequest req, TraceWriter log) | |
{ | |
log.Info("C# HTTP trigger function processed a request."); | |
return new OkObjectResult(GetBooks()); | |
} |
View Book.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Book | |
{ | |
public Book() { } | |
public Book(int bookId, string title, string publisher) | |
=> (BookId, Title, Publisher) = (bookId, title, publisher); | |
public int BookId { get; set; } | |
public string Title { get; set; } | |
public string Publisher { get; set; } |
View Program.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static string M3(Shape shape) | |
=> shape switch | |
{ | |
CombinedShape (var shape1, var (pos, _)) => $"combined shape - shape1: {shape1.Name}, pos of shape2: {pos}", | |
{ Size: (200, 200), Position: var pos } => $"shape with size 200x200 at position {pos.x}:{pos.y}", | |
Ellipse (var pos, var size) => $"Ellipse with size {size} at position {pos}", | |
Rectangle (_, var size) => $"Rectangle with size {size}", | |
_ => "another shape" | |
}; |
View Program.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static string M2(Shape shape) | |
=> shape switch | |
{ | |
Shape s when s.Size.height > 100 => $"large shape with size {s.Size} at position {s.Position}", | |
Ellipse e => $"Ellipse with size {e.Size} at position {e.Position}", | |
Rectangle r => $"Rectangle with size {r.Size} at position {r.Position}", | |
_ => "another shape" | |
}; |
View Program.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static void Main() | |
{ | |
var r1 = new Rectangle(position: (200, 200), size: (200, 200)); | |
var e1 = new Ellipse(position: (80, 1400), size: (80, 140)); | |
var shapes = new Shape[] | |
{ | |
r1, | |
e1, | |
new Circle((40, 60), 90), | |
new CombinedShape(r1, e1) |
View Shape.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public abstract class Shape | |
{ | |
public (int x, int y) Position { get; } | |
public (int height, int width) Size { get; } | |
public Shape((int x, int y) position, (int height, int width) size) | |
=> (Position, Size) = (position, size); | |
public void Deconstruct(out (int x, int y) position, out (int x, int y) size) | |
=> (position, size) = (Position, Size); |
View Program.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static string M1(Shape shape) | |
{ | |
switch (shape) | |
{ | |
case Shape s when s.Size.height > 100: | |
return $"large shape with size {s.Size} at position {s.Position}"; | |
case Ellipse e: | |
return $"Ellipse with size {e.Size} at position {e.Position}"; | |
case Rectangle r: | |
return $"Rectangle with size {r.Size} at position {r.Position}"; |
View Program.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var glory = new NewAndGlory(); | |
string s1 = glory.GetANullString(); | |
string s2 = glory.GetAString(); | |
string s3 = glory.PassAString(null); // having a NullReferenceException here! |
View Program.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public string GetIsbn2(Book book) | |
=> book.Isbn ?? string.Empty; |
NewerOlder