Skip to content

Commit

Permalink
add Console agent books
Browse files Browse the repository at this point in the history
  • Loading branch information
conceptdev committed Nov 2, 2016
1 parent 1fb18cb commit 9a273bf
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 29 deletions.
8 changes: 5 additions & 3 deletions Collections/Arrays.workbook
@@ -1,6 +1,8 @@
```json
{"platform":"MacNet45","uti":"com.xamarin.Workbook"}
```
---
uti: com.xamarin.workbook
platforms:
- Console
---

# Collections: Arrays

Expand Down
40 changes: 20 additions & 20 deletions Csharp6/csharp6.workbook
@@ -1,16 +1,23 @@
```json
{"platform":"MacNet45","uti":"com.xamarin.Workbook"}
```
---
uti: com.xamarin.workbook
platforms:
- Console
---

# Using C# 6

Some examples from Xamarin's [intro to C# 6](https://developer.xamarin.com/guides/cross-platform/advanced/csharp_six/).

* Null-conditional operator

* String Interpolation

* Expression-bodied Function Members

* Auto-property Initialization

* Index Initializers

* using static

## Null-conditional operator
Expand Down Expand Up @@ -75,7 +82,6 @@ foreach (var s in values.Select (i => $"The value is {i,10:N2}.")) {
}
```


## Expression-bodied Function Members

The `ToString` override in the following class is an expression-bodied
Expand Down Expand Up @@ -140,13 +146,12 @@ types with a simple object-initializer-like syntax:

```csharp
var userInfo = new Dictionary<string,object> {
["Created"] = NSDate.Now,
["Due"] = NSDate.Now.AddSeconds(60 * 60 * 24),
["Created"] = DateTime.Now,
["Due"] = DateTime.Now.AddSeconds(60 * 60 * 24),
["Task"] = "buy lettuce"
};
```


## using static

Enumerations, and certain classes such as System.Math, are primarily
Expand All @@ -161,8 +166,12 @@ C# 6 code can then reference the static members directly, avoiding
repetition of the class name (eg. `Math.PI` becomes `PI`):

```csharp
using CoreLocation;
static public double MilesBetween(CLLocationCoordinate2D loc1, CLLocationCoordinate2D loc2)
public class Location
{
public Location (double lat, double @long) {Latitude = lat; Longitude = @long;}
public double Latitude = 0; public double Longitude = 0;
}
static public double MilesBetween(Location loc1, Location loc2)
{
double rlat1 = PI * loc1.Latitude / 180;
double rlat2 = PI * loc2.Latitude / 180;
Expand All @@ -178,15 +187,6 @@ static public double MilesBetween(CLLocationCoordinate2D loc1, CLLocationCoordin
}
```



```csharp
MilesBetween (new CLLocationCoordinate2D(-12,22), new CLLocationCoordinate2D(-13,33))
```

```csharp
// requires El Capitan
//var sf = await new CLGeocoder().GeocodeAddressAsync("San Francisco, CA");
//var la = await new CLGeocoder().GeocodeAddressAsync("Los Angeles, CA");
//MilesBetween (sf, la);
```
MilesBetween (new Location(-12,22), new Location(-13,33))
```
85 changes: 85 additions & 0 deletions Visualizers/Visualizers-Console.workbook
@@ -0,0 +1,85 @@
---
uti: com.xamarin.workbook
platforms:
- Console
---

# Visualizers (Console)

Xamarin Workbooks uses a different visualizers for inline code evaluation results:

* String

* Object

* Enumerable

* Exception

* Html

* Help

By default, the results of a code-block will shown as a string representation of the *last-referenced object* in the block. The `Monkey` class below demonstrates this: when the `rupert` object is assigned, the **ToString** representation is printed after the code-block.

```csharp
class Monkey {
public string Name;
public string Species;
public string Habitat;
public DateTime Birthday = DateTime.MinValue;
public override string ToString(){
return $"{Name} the {Species} ({Habitat})"; //C# 6
}
}
var rupert = new Monkey {Name="Rupert", Species = "Xamarin", Habitat="San Francisco"};
```

Use the popup menu to the right of the result to switch to the **Object Members** view. Most code-block results in Workbooks will have both **ToString** and **Object Members** display options.

DateTime values have a number of display options, including a calendar view:

```csharp
rupert.Birthday = new DateTime(2011,05,11);
```

Enumerable collections will be expanded so that you can explore their contents. You can also change the view of each individual object in the collection:

```csharp
var enumerable = new List<string> {"alpha", "beta", "gamma", "delta"};
```

Exceptions have a custom display:

```csharp
new ArgumentNullException ("name");
```

HTML can also be emitted from code-blocks and rendered in the Workbook. This simple example uses string interpolation to customize an HTML string for display using `AsHtml()`:

```csharp
var greeting = "Hello, Workbooks"; // C# 6 string interpolation
$"<html><h2>{greeting}</h2><b>bold</b> <i>italic</i> <u>underline</u></html>".AsHtml()
```

There’s also a `help` command, which just lists some handy tips. The help list is slightly different for each platform supported by Workbooks.

```csharp
help
```

And finally, not really a visualization, but from the help above you can see that it’s possible to affect the culture of the Workbook. These code-blocks show the date rendered in English and then Spanish (after setting the `CurrentCulture`):

```csharp
DateTime.Now.ToLongDateString()
```

```csharp
CurrentCulture = new System.Globalization.CultureInfo("es");
DateTime.Now.ToLongDateString()
```

```csharp
// reset to English
CurrentCulture = new System.Globalization.CultureInfo("en");
```
5 changes: 2 additions & 3 deletions Visualizers/Visualizers-Mac.workbook
Expand Up @@ -43,7 +43,7 @@ class Monkey {
var rupert = new Monkey {Name="Rupert", Species = "Xamarin", Habitat="San Francisco"};
```

Use the popup menu to the right of the result to switch to the **Object Members** view. Most code-block results in Workbooks will have both \*\*ToString \*\*and **Object Members** display options.
Use the popup menu to the right of the result to switch to the **Object Members** view. Most code-block results in Workbooks will have both **ToString** and **Object Members** display options.

Color types are rendered with an example of the color:

Expand Down Expand Up @@ -109,5 +109,4 @@ DateTime.Now.ToLongDateString()
```csharp
// reset to English
CurrentCulture = new System.Globalization.CultureInfo("en");
```

```
6 changes: 3 additions & 3 deletions Visualizers/Visualizers-iOS.workbook
@@ -1,7 +1,7 @@
---
uti: com.xamarin.workbook
platform: iOS
packages: []
platforms:
- iOS
---

# Visualizers for iOS
Expand Down Expand Up @@ -43,7 +43,7 @@ class Monkey {
var rupert = new Monkey {Name="Rupert", Species = "Xamarin", Habitat="San Francisco"};
```

Use the popup menu to the right of the result to switch to the **Object Members** view. Most code-block results in Workbooks will have both **ToString **and **Object Members** display options.
Use the popup menu to the right of the result to switch to the **Object Members** view. Most code-block results in Workbooks will have both \*\*ToString \*\*and **Object Members** display options.

Color types are rendered with an example of the color:

Expand Down

0 comments on commit 9a273bf

Please sign in to comment.