Skip to content

Commit d1ca67e

Browse files
authored
docsp-32855 - poco analysis (#53)
1 parent ae9b7d8 commit d1ca67e

File tree

7 files changed

+155
-31
lines changed

7 files changed

+155
-31
lines changed

source/analyze-code.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,17 @@ Analyze Your Code
1414

1515
/code-type/builders
1616
/code-type/linq
17+
/code-type/pocos
1718

1819
Overview
1920
--------
2021

2122
Learn how to use the {+product+} to analyze your {+driver-long+} code.
22-
The {+product+} can analyze expressions created with the following frameworks:
23+
The {+product+} can analyze expressions created with the following patterns:
2324

2425
- :ref:`Builders Class <mongodb-analyzer-analyze-builders>`
2526
- :ref:`Language Integrated Query (LINQ) <mongodb-analyzer-analyze-linq>`
27+
- :ref:`Plain Old CLR/Class Objects (POCOs) <mongodb-analyzer-analyze-pocos>`
2628

2729
Use the {+product+} From the Command Line
2830
----------------------------------------------

source/code-type/pocos.txt

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
.. _mongodb-analyzer-analyze-pocos:
2+
3+
=============
4+
Analyze POCOs
5+
=============
6+
7+
.. contents:: On this page
8+
:local:
9+
:backlinks: none
10+
:depth: 2
11+
:class: singlecol
12+
13+
Overview
14+
--------
15+
16+
Plain old CLR objects, or plain old class objects (POCOs), are
17+
simple class objects that don't
18+
inherit features from any framework-specific base classes or interfaces.
19+
If your application uses POCOs, you can use the {+product+} to preview them as JSON
20+
objects.
21+
22+
To learn more about POCOs, see the :wikipedia:`POCOs page on Wikipedia <Plain_old_CLR_object>`
23+
and the `Work with POCOs <{+driver-docs+}/fundamentals/data-formats/poco/>`__ page in the
24+
{+driver-short+} documentation.
25+
26+
Preview as JSON
27+
---------------
28+
29+
The following code sample shows an example of a POCO class definition
30+
and its corresponding JSON translation. By previewing your
31+
POCOs in JSON, you can see how BSON serialization attributes, such as ``BsonId`` and
32+
``BsonElement``, change the shape of the resulting BSON during serialization.
33+
34+
.. io-code-block::
35+
:copyable: false
36+
37+
.. input::
38+
:language: csharp
39+
40+
class Order
41+
{
42+
[BsonId]
43+
public int OrderNumber { get; set; }
44+
45+
[BsonElement("customer_id")]
46+
public int CustomerId { get; set; }
47+
48+
public string Date { get; set; }
49+
50+
[BsonIgnore]
51+
public string Email { get; set; }
52+
}
53+
54+
.. output::
55+
:language: json
56+
57+
{
58+
"_id": 6783456,
59+
"customer_id": 678234,
60+
"Date": "06/03/2023"
61+
}
62+
63+
.. tip:: Sample Data
64+
65+
The {+product+} includes predefined sample values for certain common property names.
66+
If you use
67+
these property names in your POCO, the Analyzer uses the sample values in the JSON
68+
output. For any property names without predefined sample values, the Analyzer uses a
69+
random value that matches the property's data type.
70+
71+
For a list of property names with sample values, see the
72+
`JSON sample value file <{+product-source-repo+}/blob/main/src/MongoDB.Analyzer/Core/Poco/Data/data.json>`__
73+
in the {+product+} GitHub repo.
74+
75+
Preview POCOs in Visual Studio
76+
------------------------------
77+
78+
To preview your POCOs in Visual Studio, perform the following actions:
79+
80+
1. Install the {+product+} as described in the :ref:`mongodb-analyzer-install`
81+
guide.
82+
#. Define a POCO class.
83+
#. Move your cursor over the :guilabel:`...` ellipsis annotation beneath the first
84+
word of your class definition to display an information message that contains
85+
the JSON translation.
86+
87+
Click on the following corresponding tab to see a POCO class definition
88+
with or without an information message displayed:
89+
90+
.. tabs::
91+
92+
.. tab:: Without Information Message
93+
:tabid: no-message
94+
95+
.. figure:: /includes/images/poco.png
96+
:alt: Screenshot of POCO definition with an ellipsis annotation in Visual Studio
97+
98+
.. tab:: With Information Message
99+
:tabid: message
100+
101+
.. figure:: /includes/images/poco-popup.png
102+
:alt: Screenshot of POCO definition with an information message displayed in Visual Studio
103+
104+
.. tip:: Rule ID
105+
106+
The information message begins with the {+product+} Rule ID that generated the
107+
popup. In the previous example, the Rule ID is ``MAPoco1001``, indicating
108+
the POCO is valid.

source/configuration.txt

Lines changed: 38 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -81,88 +81,99 @@ by the {+product+}:
8181
* - | **DefaultLinqVersion**
8282
- | **Type:** string
8383
|
84-
| **Description:**
85-
| The LINQ provider the {+product+} uses.
84+
| **Description:** The LINQ provider the {+product+} uses.
8685

8786
.. tip::
8887

8988
To learn more about LINQ, see the
9089
:ref:`Analyze Your Code <mongodb-analyzer-analyze-linq>`
9190
page.
9291

93-
| **Default**: ``"V2"``
9492
| **Accepted Values**: ``"V2"`` or ``"V3"``
93+
| **Default**: ``"V2"``
9594

9695
* - | **EnableVariableTracking**
9796
- | **Type:** boolean
9897
|
99-
| **Description:**
100-
| Specifies if the {+product+} tracks and composes builder expression variables.
98+
| **Description:** Specifies if the {+product+} tracks and composes builder
99+
expression variables.
101100

102101
.. tip::
103102

104103
To learn more about builder expressions, see the
105104
:ref:`Analyze Your Code <mongodb-analyzer-analyze-builders>`
106105
page.
107106

108-
| **Default**: ``true``
109107
| **Accepted Values**: ``true`` or ``false``
108+
| **Default**: ``true``
109+
110+
* - | **LogFileName**
111+
- | **Type:** string
112+
|
113+
| **Description:** Specifies the path to which the {+product+} writes its
114+
internal logs.
115+
116+
.. include:: includes/logging-admonition.rst
117+
118+
| **Accepted Values**: A valid file path
119+
| **Default**: ``""``
110120

111121
* - | **OutputDriverVersion**
112122
- | **Type:** boolean
113123
|
114-
| **Description:**
115-
| Specifies if the {+product+} includes your {+driver-short+} version in diagnostic messages.
124+
| **Description:** Specifies if the {+product+} includes your {+driver-short+}
125+
version in diagnostic messages.
116126
|
117-
| **Default**: ``false``
118127
| **Accepted Values**: ``true`` or ``false``
128+
| **Default**: ``false``
119129

120130
* - | **OutputInternalExceptions**
121131
- | **Type:** boolean
122132
|
123-
| **Description:**
124-
| Specifies if the {+product+} includes internal exceptions in diagnostic messages.
133+
| **Description:** Specifies if the {+product+} includes internal exceptions in
134+
diagnostic messages.
125135
|
126-
| **Default**: ``false``
127136
| **Accepted Values**: ``true`` or ``false``
137+
| **Default**: ``false``
128138

129139
* - | **OutputInternalLogsToFile**
130140
- | **Type:** boolean
131141
|
132-
| **Description:**
133-
| Specifies if the {+product+} writes its internal logs to a file.
142+
| **Description:** Specifies if the {+product+} writes its internal logs to a file.
134143

135144
.. include:: includes/logging-admonition.rst
136145

137-
| **Default**: ``false``
138146
| **Accepted Values**: ``true`` or ``false``
147+
| **Default**: ``false``
139148

140-
* - | **LogFileName**
149+
* - | **PocoAnalysisVerbosity**
141150
- | **Type:** string
142151
|
143-
| **Description:**
144-
| Specifies the path to which the {+product+} writes its internal logs.
152+
| **Description:** Specifies which POCOs the {+product+} previews as JSON. You can
153+
set this option to one of the following values:
145154

146-
.. include:: includes/logging-admonition.rst
147-
148-
| **Default**: ``""``
149-
| **Accepted Values**: A valid file path
155+
- ``"All"``: Preview all POCOs
156+
- ``"Medium"``: Preview only POCOs that are part of a LINQ or builders expression
157+
or have BSON attributes
158+
- ``"None"``: Do not preview POCOs
159+
160+
| **Accepted Values**: ``"All"``, ``"Medium"``, or ``"None"``
161+
| **Default**: ``"Medium"``
162+
150163
* - | **SendTelemetry**
151164
- | **Type:** boolean
152165
|
153-
| **Description:**
154-
| Specifies if the {+product+} collects and sends anonymized information
155-
to MongoDB Inc. to improve products.
166+
| **Description:** Specifies if the {+product+} collects and sends anonymized
167+
information to MongoDB Inc. to improve products.
156168

157169
.. tip::
158170

159171
To learn more about telemetry in the {+product+}, see the
160172
:ref:`<mongodb-analyzer-configuration-telemetry>`
161173
section of this guide.
162174

163-
| **Default**: ``true``
164175
| **Accepted Values**: ``true`` or ``false``
165-
176+
| **Default**: ``true``
166177

167178
To learn more about the configuration options the {+product+} supports,
168179
see the :github:`{+product+} source code </master/src/MongoDB.Analyzer/Core/Settings/SettingsHelper.cs>`.

source/includes/images/poco-popup.png

166 KB
Loading

source/includes/images/poco.png

133 KB
Loading

source/index.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,14 @@ code:
2828

2929
- How your code translates into the {+query-api+}
3030
- If your code includes unsupported LINQ or builder expressions
31+
- How your POCOs serialize to JSON
3132

32-
The {+product+} can analyze the following groups of {+driver-short+} expressions:
33+
The {+product+} can analyze the following groups of {+driver-short+} expressions and
34+
classes:
3335

3436
- `Builders <{+driver-docs+}/fundamentals/builders/>`__
3537
- `LINQ <{+driver-docs+}/fundamentals/linq/>`__
38+
- `POCOs <{+driver-docs+}/fundamentals/data-formats/poco/>`__
3639

3740
Read the following sections of this guide to learn how to install the
3841
{+product+}, how to use its features, and how to configure it:

source/install.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ command from the root directory of your .NET project:
2222

2323
.. code-block:: shell
2424

25-
Install-Package {+product-package-name+} -Version {+product-version-full+}
25+
dotnet add package {+product-package-name+} -v {+product-version-full+}
2626

2727
To view the NuGet page for the {+product+}, see
2828
`{+product-package-name+} <{+product-nuget-link+}>`__ on NuGet Gallery.
2929

3030
To learn more about installing NuGet packages from the command line, see
31-
`NuGet Powershell Reference <https://docs.microsoft.com/en-us/nuget/reference/powershell-reference>`__
31+
`NuGet CLI Reference <https://docs.microsoft.com/en-us/nuget/consume-packages/install-use-packages-dotnet-cli>`__
3232
from Microsoft.
3333

3434
To learn more about installing NuGet packages from Visual Studio, see

0 commit comments

Comments
 (0)