Skip to content

Commit e73ab00

Browse files
authored
Fixing code samples to C# with VS2015 highlighting (#108)
1 parent 61860cf commit e73ab00

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+162
-160
lines changed

docs/src/Assembly-Scanning.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
By default, the assembly in which a base type is declared is searched for derived types. If there are additional assemblies which should be searched, use:
22

3-
```C#
3+
```cs
44
Mapper.WhenMapping.LookForDerivedTypesIn(
55
typeof(DerivedType1).Assembly,
66
typeof(DerivedType2).Assembly);

docs/src/Cloning-Mappers.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Mappers can be cloned, to enable 'derived' mappers to inherit, add to and override a 'root' configuration:
22

3-
``` C#
3+
```cs
44
var baseMapper = Mapper.CreateNew();
55

66
// Setup the base configuration:

docs/src/Collections.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Generic `List<T>` instances are created for interface-type members except `ISet<
2323

2424
By default, if the source collection matching a target collection is null, the target collection is populated with an empty collection. You can configure setting the target collection to null instead like this:
2525

26-
```C#
26+
```cs
2727
// Map null-source collections to null for all source
2828
// and target types:
2929
Mapper.WhenMapping.MapNullCollectionsToNull();

docs/src/Configuration-Classes.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Multiple, dedicated configuration classes can be created by deriving from the ab
66

77
Mapper configuration is set up by implementing the abstract `Configure` method:
88

9-
```C#
9+
```cs
1010
public class ProductMappingConfiguration : MapperConfiguration
1111
{
1212
protected override void Configure()
@@ -34,21 +34,21 @@ In this example the default mapper is configured - the one used via the [static]
3434

3535
To apply a particular `MapperConfiguration` Type, supply it explicitly:
3636

37-
```C#
37+
```cs
3838
Mapper.WhenMapping
3939
.UseConfigurations.From<ProductMappingConfiguration>();
4040
```
4141

4242
To apply all `MapperConfiguration` Types from an Assembly, supply a Type from that Assembly:
4343

44-
```C#
44+
```cs
4545
Mapper.WhenMapping
4646
.UseConfigurations.FromAssemblyOf<Product>();
4747
```
4848

4949
To apply all `MapperConfiguration` Types from multiple Assemblies, supply the Assemblies:
5050

51-
```C#
51+
```cs
5252
// Scan all Assemblies from the AppDomain:
5353
Mapper.WhenMapping
5454
.UseConfigurations.From(assembly1, assembly2, assembly3);
@@ -63,7 +63,7 @@ Mapper.WhenMapping
6363

6464
To apply all `MapperConfiguration` Types from the Assemblies current loaded into the `AppDomain`, use:
6565

66-
```C#
66+
```cs
6767
// Scan all Assemblies from the AppDomain:
6868
Mapper.WhenMapping
6969
.UseConfigurations.FromCurrentAppDomain();
@@ -79,7 +79,7 @@ Mapper.WhenMapping
7979

8080
Calling `GetPlansFor<Source>().To<Target>()` caches the mapping function at the point you call it. If Types configured in the object graph are configured in more than one `MapperConfiguration`, you might need to define an order in which configuration classes are applied. Use:
8181

82-
```C#
82+
```cs
8383
// Configure aspects of Parent -> Parent mapping, which includes
8484
// mapping Child -> Child. Automatically apply ChildMapperConfiguration,
8585
// then apply this configuration afterwards.
@@ -100,7 +100,7 @@ Chains of `ApplyAfter` attributes will be followed, with all configurations auto
100100

101101
[Configured Service Providers](Dependency-Injection) are available to `MapperConfiguration` classes. For example:
102102

103-
```C#
103+
```cs
104104
// Get a Dependency Injection container:
105105
var diContainer = GetDiContainer();
106106

@@ -114,7 +114,7 @@ Mapper.WhenMapping
114114

115115
...the DI container and its registered services are now available to the `MapperConfiguration` class via the `GetService<TService>()` and `GetServiceProvider<TContainer>()` methods:
116116

117-
```C#
117+
```cs
118118
public class MyMappingConfiguration : MapperConfiguration
119119
{
120120
protected override void Configure()

docs/src/Configuring-Constructor-Arguments.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Constructor arguments can be configured by type or name, and constant values or
44

55
For example, to configure mapping these types:
66

7-
```C#
7+
```cs
88
public class CustomerDto
99
{
1010
public string CustomerNum { get; set; }
@@ -21,7 +21,7 @@ public class Customer
2121

2222
...use:
2323

24-
```C#
24+
```cs
2525
Mapper.WhenMapping
2626
.From<CustomerDto>() // Apply to CustomerDto mappings
2727
.ToANew<Customer>() // Apply to Customer creations
@@ -34,7 +34,7 @@ Mapper.WhenMapping
3434

3535
...or, if inline configuration is preferred:
3636

37-
```C#
37+
```cs
3838
// Source, target and mapping types are implicit from the mapping:
3939
Mapper
4040
.Map(customerDto).ToANew<Customer>(cfg => cfg

docs/src/Configuring-Exception-Handling.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
By default, an `Exception` thrown during a mapping is wrapped in a [`MappingException`](/agileobjects/AgileMapper/blob/master/AgileMapper/MappingException.cs) and rethrown. To configure a mapper to swallow exceptions and return null instead, use:
22

3-
```C#
3+
```cs
44
Mapper.WhenMapping
55
.SwallowAllExceptions();
66
```
77

88
Alternatively, to have a mapper call a callback in the event of an exception use:
99

10-
```C#
10+
```cs
1111
Mapper.WhenMapping
1212
.PassExceptionsTo(ctx =>
1313
{
@@ -23,7 +23,7 @@ Mapper.WhenMapping
2323

2424
To only swallow exceptions thrown when mapping particular types, use:
2525

26-
```C#
26+
```cs
2727
Mapper.WhenMapping
2828
.From<PersonViewModel>() // Apply to PersonViewModel mappings (optional)
2929
.To<Person>() // Apply to Person creation, updates and merges
@@ -32,7 +32,7 @@ Mapper.WhenMapping
3232

3333
...and to have a callback called for a particular type, use:
3434

35-
```C#
35+
```cs
3636
Mapper.WhenMapping
3737
.To<Person>()
3838
.PassExceptionsTo(ctx =>

docs/src/Configuring-Mapping-Callbacks.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ You can configure code to be executed at specific points in a mapping - conditio
22

33
Before mapping of a specified type begins:
44

5-
```C#
5+
```cs
66
mapper.WhenMapping
77
.To<Customer>() // Apply to Customer creation, updates and merges
88
.Before
@@ -13,7 +13,7 @@ mapper.WhenMapping
1313

1414
Before an instance of a specified type is created:
1515

16-
```C#
16+
```cs
1717
mapper.WhenMapping
1818
.From<AddressDto>() // Apply to AddressDto mappings
1919
.ToANew<Address>() // Apply to Address creation
@@ -24,7 +24,7 @@ mapper.WhenMapping
2424

2525
After an instance of a specified type is created:
2626

27-
```C#
27+
```cs
2828
mapper
2929
.After
3030
.CreatingInstancesOf<Address>()
@@ -34,7 +34,7 @@ mapper
3434

3535
On either side of the mapping of a particular member:
3636

37-
```C#
37+
```cs
3838
mapper.WhenMapping
3939
.From<Person>() // Apply to Person mappings
4040
.Over<PersonVm>() // Apply to PersonVm updates
@@ -49,7 +49,7 @@ mapper.WhenMapping
4949

5050
At the end of any mapping (conditionally):
5151

52-
```C#
52+
```cs
5353
Mapper
5454
.After
5555
.MappingEnds

docs/src/Configuring-Member-Name-Patterns.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
If a naming convention prevents normal [member matching](Member-Matching), you can configure naming patterns to use to match names up. For example:
22

3-
```C#
3+
```cs
44
public class ProductDto
55
{
66
public string strName { get; set; }
@@ -15,21 +15,21 @@ public class Product
1515

1616
To have the name prefixes `str` and `dec` ignored when matching member names, use:
1717

18-
```C#
18+
```cs
1919
Mapper.WhenMapping
2020
.UseNamePrefixes("str", "dec");
2121
```
2222

2323
You can also configure name suffixes:
2424

25-
```C#
25+
```cs
2626
Mapper.WhenMapping
2727
.UseNameSuffix("Value"); // Match 'PriceValue' to 'Price'
2828
```
2929

3030
...or a regex pattern:
3131

32-
```C#
32+
```cs
3333
Mapper.WhenMapping
3434
.UseNamePattern("^_(.+)Value$"); // Match '_PriceValue' to 'Price'
3535
```
@@ -38,7 +38,7 @@ Configured regex patterns must start with `^` and end with `$`, contain the capt
3838

3939
Naming patterns can also be configured [inline](Inline-Configuration)
4040

41-
```C#
41+
```cs
4242
var anonSource = new { _PriceValue = default(double) };
4343

4444
// Source, target and mapping types are implicit from the mapping:
@@ -49,7 +49,7 @@ Mapper
4949

5050
...or for specific source and target types:
5151

52-
```C#
52+
```cs
5353
var anonSource = new { _PriceValue = default(double) };
5454

5555
Mapper.WhenMapping

docs/src/Configuring-Member-Values.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ There are several ways of configuring a custom data source for a target member.
22

33
**A source member**:
44

5-
```C#
5+
```cs
66
Mapper.WhenMapping
77
.From<ProductDto>() // Apply to ProductDto mappings
88
.To<Product>() // Apply to Product creation, updates and merges
@@ -18,7 +18,7 @@ Mapper.WhenMapping
1818

1919
**A source expression** (in this example, supplied [inline](Inline-Configuration)):
2020

21-
```C#
21+
```cs
2222
// Source, target and mapping types are implicit from the mapping:
2323
Mapper.Map(productDto).ToANew<Product>(cfg => cfg
2424
.Map(ctx => "$" + ctx.Source.Price) // ctx.Source is the ProductDto
@@ -27,7 +27,7 @@ Mapper.Map(productDto).ToANew<Product>(cfg => cfg
2727

2828
**A constant value**:
2929

30-
```C#
30+
```cs
3131
Mapper.WhenMapping
3232
.From<ProductDto>() // Apply to ProductDto mappings
3333
.OnTo<Product>() // Apply to Product merges only
@@ -42,7 +42,7 @@ Mapper.WhenMapping
4242

4343
**A value from an [injected service](Dependency-Injection)**:
4444

45-
```C#
45+
```cs
4646
// Retrieve an IDateTimeProvider instance from a configured
4747
// service provider, and use its UtcNow value:
4848
Mapper.WhenMapping
@@ -54,7 +54,7 @@ Mapper.WhenMapping
5454

5555
**The result of a function call** ([inline](Inline-Configuration)):
5656

57-
```C#
57+
```cs
5858
Func<ProductDto, Product, string> companyNameFactory =
5959
(dto, p) => dto.ManufaturerName + " Ltd";
6060

@@ -68,7 +68,7 @@ Mapper.Map(productDto).ToANew<Product>(cfg => cfg
6868

6969
Any of these methods can be configured to be conditional:
7070

71-
```C#
71+
```cs
7272
Mapper.WhenMapping
7373
.From<ProductDto>() // Apply to ProductDto mappings
7474
.ToANew<Product>() // Apply to Product creation only
@@ -79,7 +79,7 @@ Mapper.WhenMapping
7979

8080
And in an [inline](Inline-Configuration) example:
8181

82-
```C#
82+
```cs
8383
Mapper.Map(productDto).ToANew<Product>(cfg => cfg
8484
.If((dto, p) => dto.CompanyId == 0) // Apply only if CompanyId is 0
8585
.Map("No-one") // Always the same value
@@ -92,21 +92,21 @@ By default, configured data sources only apply in the direction configured - con
9292

9393
To make every source- to target-member pairing you configure apply to mappings in either direction, use:
9494

95-
```C#
95+
```cs
9696
Mapper.WhenMapping.AutoReverseConfiguredDataSources();
9797
```
9898

9999
To make every source- to target-member pairing you configure for a particular pair of Types apply to mappings in either direction, use:
100100

101-
```C#
101+
```cs
102102
Mapper.WhenMapping
103103
.From<Product>().To<ProductDto>()
104104
.AutoReverseConfiguredDataSources();
105105
```
106106

107107
To make a source- to target-member pairing you configure apply to mappings in either direction, use:
108108

109-
```C#
109+
```cs
110110
Mapper.WhenMapping
111111
.From<Product>().To<ProductDto>()
112112
.Map(p => p.Specification, dto => dtp.Spec)
@@ -117,7 +117,7 @@ Mapper.WhenMapping
117117

118118
If you use the mapper-level `AutoReverseConfiguredDataSources()` to set the default behaviour, source- to target-member pairings you configure for a particular pair of Types can opt out using:
119119

120-
```C#
120+
```cs
121121
// Set the default behaviour:
122122
Mapper.WhenMapping.AutoReverseConfiguredDataSources();
123123

@@ -129,7 +129,7 @@ Mapper.WhenMapping
129129

130130
...and individual source- to target-member pairings can opt out with:
131131

132-
```C#
132+
```cs
133133
Mapper.WhenMapping
134134
.From<Product>().To<ProductDto>()
135135
.Map(p => p.Specification, dto => dtp.Spec)
@@ -140,7 +140,7 @@ Mapper.WhenMapping
140140

141141
To map a data source to the root target object, use, *e.g*:
142142

143-
```C#
143+
```cs
144144
// Source class - has a nested member 'Statistics':
145145
class Video
146146
{

docs/src/Configuring-Object-Construction.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Configure a custom factory for a particular type using:
22

3-
```C#
3+
```cs
44
Mapper.WhenMapping
55
.InstancesOf<Customer>() // Apply to Customer creation, updates and merges
66
.CreateUsing(ctx => new Customer
@@ -11,7 +11,7 @@ Mapper.WhenMapping
1111

1212
Configure a custom factory for a particular type when mapping between particular types using:
1313

14-
```C#
14+
```cs
1515
Mapper.WhenMapping
1616
.From<PersonViewModel>() // Apply to PersonViewModel mappings
1717
.To<Customer>() // Apply to Customer creation, updates and merges
@@ -23,7 +23,7 @@ Mapper.WhenMapping
2323

2424
Configure a conditional custom factory using ([inline](Inline-Configuration) example):
2525

26-
```C#
26+
```cs
2727
Mapper.Map(customerViewModels).ToANew<Customer[]>(cfg => cfg
2828
.WhenMapping
2929
.From<CustomerViewModel>()

0 commit comments

Comments
 (0)