Skip to content

Conversation

@ChrSteinert
Copy link
Contributor

@ChrSteinert ChrSteinert commented Jun 6, 2018

It is not much text, but I hope it conveys the concept. For the example I was looking at existing builders and an easy, understandable example.

Fixes #5769

@ChrSteinert ChrSteinert requested a review from cartermp as a code owner June 6, 2018 06:56
@rpetrusha
Copy link
Contributor

@cartermp, can you take a look at this PR?

@mairaw mairaw changed the title Add section about extending Computation Expression Builders. #5769 Add section about extending Computation Expression Builders Jul 9, 2018
Copy link
Contributor

@cartermp cartermp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @ChrSteinert!

Copy link
Contributor

@mairaw mairaw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @ChrSteinert. Left a few comments to be addressed.

## Custom Operations
You can define a custom operation on a computation expression and use a custom operation as an operator in a computation expression. For example, you can include a query operator in a query expression. When you define a custom operation, you must define the Yield and For methods in the computation expression. To define a custom operation, put it in a builder class for the computation expression, and then apply the [`CustomOperationAttribute`](https://msdn.microsoft.com/library/199f3927-79df-484b-ba66-85f58cc49b19). This attribute takes a string as an argument, which is the name to be used in a custom operation. This name comes into scope at the start of the opening curly brace of the computation expression. Therefore, you shouldn’t use identifiers that have the same name as a custom operation in this block. For example, avoid the use of identifiers such as `all` or `last` in query expressions.

### Extending existing Builders with new Custom Operatios
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo: Operatios

### Extending existing Builders with new Custom Operatios
If you already have a builder class, its custom operations can be extended from outside of this builder class. Extensions must be declared in modules. Namespaces cannot contain extension members except in the same file and namespace declaration group where the type is defined.

For instance extending the existing `Microsoft.FSharp.Linq.QueryBuilder` class.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would probably be better to say something like:

"The following example shows how to extend an existing Microsoft.FSharp.Linq.QueryBuilder class:"

You can define a custom operation on a computation expression and use a custom operation as an operator in a computation expression. For example, you can include a query operator in a query expression. When you define a custom operation, you must define the Yield and For methods in the computation expression. To define a custom operation, put it in a builder class for the computation expression, and then apply the [`CustomOperationAttribute`](https://msdn.microsoft.com/library/199f3927-79df-484b-ba66-85f58cc49b19). This attribute takes a string as an argument, which is the name to be used in a custom operation. This name comes into scope at the start of the opening curly brace of the computation expression. Therefore, you shouldn’t use identifiers that have the same name as a custom operation in this block. For example, avoid the use of identifiers such as `all` or `last` in query expressions.

### Extending existing Builders with new Custom Operatios
If you already have a builder class, its custom operations can be extended from outside of this builder class. Extensions must be declared in modules. Namespaces cannot contain extension members except in the same file and namespace declaration group where the type is defined.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

adding the word same in front of namespace declaration group would probably make it easier to understand

@ChrSteinert
Copy link
Contributor Author

Sure!
Happy to adjust!

Copy link
Contributor

@mairaw mairaw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes look good. Thanks @ChrSteinert!

@mairaw mairaw merged commit e73d849 into dotnet:master Jul 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants