{"id":20666325,"url":"https://github.com/juniorgasparotto/graphexpression","last_synced_at":"2025-07-23T20:05:28.371Z","repository":{"id":93351590,"uuid":"39921397","full_name":"juniorgasparotto/GraphExpression","owner":"juniorgasparotto","description":"This framework aims to implement the concept of graph expression in the .NET language. With this framework it is possible to create any kind of searches on complex or circular objects in a way similar to what JQUERY does in JavaScript.","archived":false,"fork":false,"pushed_at":"2018-11-19T04:20:21.000Z","size":5838,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-07-22T13:34:41.386Z","etag":null,"topics":["ascending","children","complex-types","descendants","deserialization","expression-graph","graph","graph-expression","graph-theory","jquery","mathematical-expressions","object-search","search","search-traversal","serialization","siblings","traverse"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/juniorgasparotto.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-07-29T23:36:59.000Z","updated_at":"2023-08-28T17:30:52.000Z","dependencies_parsed_at":"2023-06-26T00:29:56.317Z","dependency_job_id":null,"html_url":"https://github.com/juniorgasparotto/GraphExpression","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/juniorgasparotto/GraphExpression","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/juniorgasparotto%2FGraphExpression","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/juniorgasparotto%2FGraphExpression/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/juniorgasparotto%2FGraphExpression/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/juniorgasparotto%2FGraphExpression/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/juniorgasparotto","download_url":"https://codeload.github.com/juniorgasparotto/GraphExpression/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/juniorgasparotto%2FGraphExpression/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266738764,"owners_count":23976468,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-23T02:00:09.312Z","response_time":66,"last_error":null,"robots_txt_status":null,"robots_txt_updated_at":null,"robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ascending","children","complex-types","descendants","deserialization","expression-graph","graph","graph-expression","graph-theory","jquery","mathematical-expressions","object-search","search","search-traversal","serialization","siblings","traverse"],"created_at":"2024-11-16T19:36:54.711Z","updated_at":"2025-07-23T20:05:28.336Z","avatar_url":"https://github.com/juniorgasparotto.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"[\n![Inglês](https://github.com/juniorgasparotto/GraphExpression/blob/master/doc/img/en-us.png)\n](https://github.com/juniorgasparotto/GraphExpression)\n[\n![Português](https://github.com/juniorgasparotto/GraphExpression/blob/master/doc/img/pt-br.png)\n](https://github.com/juniorgasparotto/GraphExpression/blob/master/readme-pt-br.md)\n\n# \u003ca name=\"implementation\" /\u003eGraph Expression\n\nThis framework aims to implement the concept of graph expression on .NET language.\n\nIn short, the concept of **graph expression** aims to explore the benefits of a mathematical expression swapping numbers for entities. With this, we can create a new way to carry data and especially create a new kind of research in complex or circular graphs.\n\nWith respect to research, this project was inspired by the `JQuery` implementation for HTML elements, so the concept of graph expression with the `JQuery` ease-of-use for research in graph theory.\n\n_Attention: This document will explain the concept of graph expression, he will focus only on the framework `GraphExpression` ._\n\n**[Click here](https://github.com/juniorgasparotto/GraphExpression/blob/master/doc/concept.md#concept) if you want to know more about the concept of expression of graph.**\n\n# Installation\n\nVia [NuGet](https://www.nuget.org/packages/GraphExpression/):\n\n```\nInstall-Package GraphExpression\n```\n\n# \u003ca name=\"index\" /\u003eIndex\n\n* [Complex graphs](https://github.com/juniorgasparotto/GraphExpression#impl-graph-complex)\n* [Circular graphs](https://github.com/juniorgasparotto/GraphExpression#impl-graph-circular)\n* [Searching](https://github.com/juniorgasparotto/GraphExpression#impl-search)\n  * [Unreferenced research](https://github.com/juniorgasparotto/GraphExpression#impl-search-without-ref)\n  * [Search with reference](https://github.com/juniorgasparotto/GraphExpression#impl-search-with-ref)\n  * [Types of searches](https://github.com/juniorgasparotto/GraphExpression#impl-search-kind)\n    * [`Ancestors`](https://github.com/juniorgasparotto/GraphExpression#impl-search-ancertors)\n    * [`Descendants`](https://github.com/juniorgasparotto/GraphExpression#impl-search-descentands)\n    * [`Children`](https://github.com/juniorgasparotto/GraphExpression#impl-search-children)\n    * [`Siblings`](https://github.com/juniorgasparotto/GraphExpression#impl-search-siblings)\n* [Customizing complex expressions](https://github.com/juniorgasparotto/GraphExpression#impl-factory-expression-complex)\n* [Creating circular entities with graph and mathematical expression](https://github.com/juniorgasparotto/GraphExpression#impl-factory-entity-circular)\n* [Creating complex entities with graph and mathematical expression](https://github.com/juniorgasparotto/GraphExpression#impl-factory-entity-complex)\n  * [Understanding `Entity` class](https://github.com/juniorgasparotto/GraphExpression#impl-factory-entity-complex-class-entity)\n  * [Complex entities in text form-primitive types](https://github.com/juniorgasparotto/GraphExpression#impl-factory-entity-complex-primitive)\n  * [Complex entities in text-form complex types](https://github.com/juniorgasparotto/GraphExpression#impl-factory-entity-complex-complex)\n  * [Complex entities in text form-Collections and arrays](https://github.com/juniorgasparotto/GraphExpression#impl-factory-entity-complex-collections)\n  * [Understanding `ComplexEntityFactory` class](https://github.com/juniorgasparotto/GraphExpression#impl-factory-entity-complex-class-complex-factory)\n  * [Discoverers of types](https://github.com/juniorgasparotto/GraphExpression#impl-factory-entity-complex-discovery-types)\n  * [Discoverers of members](https://github.com/juniorgasparotto/GraphExpression#impl-factory-entity-complex-discovery-members)\n  * [Value initializers](https://github.com/juniorgasparotto/GraphExpression#impl-factory-entity-complex-value-loaders)\n  * [Assignment of children](https://github.com/juniorgasparotto/GraphExpression#impl-factory-entity-complex-child-assign)\n* [Serialization](https://github.com/juniorgasparotto/GraphExpression#impl-serialization)\n  * [Circular serialization](https://github.com/juniorgasparotto/GraphExpression#impl-serialization-circular)\n  * [Complex Serialization](https://github.com/juniorgasparotto/GraphExpression#impl-serialization-complex)\n    * [Customizing the serialization of the items](https://github.com/juniorgasparotto/GraphExpression#impl-serialization-complex-itens-serialize)\n* [Deserialization](https://github.com/juniorgasparotto/GraphExpression#impl-deserialization)\n  * [Deserialization circular](https://github.com/juniorgasparotto/GraphExpression#impl-deserialization-circular)\n  * [Deserialization complex](https://github.com/juniorgasparotto/GraphExpression#impl-deserialization-complex)\n* [Information from the graph of an entity](https://github.com/juniorgasparotto/GraphExpression#impl-graph-info)\n* [Donations](https://github.com/juniorgasparotto/GraphExpression#donate)\n* [License](https://github.com/juniorgasparotto/GraphExpression#license)\n\n# \u003ca name=\"impl-graph-complex\" /\u003eComplex graphs\n\nWe call complex graphs those containing no type defined, that is, all items are defined as `object` .\n\nThis type of graph is presented by class:\n\n```csharp\nGraphExpression.Expression\u003cobject\u003e : List\u003cEntityItem\u003cobject\u003e\u003e\n```\n\nThis class inherits from `List\u003cEntityItem\u003cobject\u003e\u003e` , that is, it is also a collection `EntityItem\u003cobject\u003e` class. The class `EntityItem\u003cobject\u003e` represents an item in the list, this is the class that there are all the information of the entity in the graph.\n\nIn the following example we will convert an object of the `Class1` type for the `Expression\u003cobject\u003e` object and display all `EntityItem\u003cobject\u003e` of the structure `Class1` type. In last exit, we display how would this object in the form of expression of graph:\n\n```csharp\npublic void GraphComplex()\n{\n    // create a simple object\n    var model = new Class1\n    {\n        Class1_Prop1 = \"Value1\",\n        Class1_Prop2 = new Class2()\n        {\n            Class2_Field1 = 1000,\n            Class2_Prop2 = \"Value2\"\n        }\n    };\n\n    // transversal navigation\n    Expression\u003cobject\u003e expression = model.AsExpression();\n    foreach (EntityItem\u003cobject\u003e item in expression)\n    {\n        var ident = new string(' ', item.Level * 2);\n        var output = $\"{ident}[{item.Index}] =\u003e Item: {GetEntity(item)}, Parent: {GetEntity(item.Parent)}, Previous: {GetEntity(item.Previous)}, Next: {GetEntity(item.Next)}, Level: {item.Level}\";\n        System.Console.WriteLine(output);\n    }\n\n    // Serialize to expression\n    System.Console.WriteLine(expression.DefaultSerializer.Serialize());\n}\n\n// Get entity as String to example\nprivate string GetEntity(EntityItem\u003cobject\u003e item)\n{\n    if (item is PropertyEntity prop)\n        return $\"Property.{prop.Property.Name}\";\n\n    if (item is FieldEntity field)\n        return $\"Field.{field.Field.Name}\";\n\n    if (item is ComplexEntity root)\n        return root.Entity.GetType().Name;\n\n    return null;\n}\n\npublic class Class1\n{\n    public string Class1_Prop1 { get; set; }\n    public Class2 Class1_Prop2 { get; set; }\n}\n\npublic class Class2\n{\n    public int Class2_Prop1 = int.MaxValue;\n    public string Class2_Prop2 { get; set; }\n}\n```\n\n**1)** at the first exit, we can visualize all the type information `Class1` and also information from the graph: expression `Index` , `Parent` , `Next` , `Previous` and `Level` :\n\n```\n  [0] =\u003e Item: Class1, Parent: , Previous: , Next: Property.Class1_Prop1, Level: 1\n    [1] =\u003e Item: Property.Class1_Prop1, Parent: Class1, Previous: Class1, Next: Property.Class1_Prop2, Level: 2\n    [2] =\u003e Item: Property.Class1_Prop2, Parent: Class1, Previous: Property.Class1_Prop1, Next: Property.Class2_Prop2, Level: 2\n      [3] =\u003e Item: Property.Class2_Prop2, Parent: Property.Class1_Prop2, Previous: Property.Class1_Prop2, Next: Field.Class2_Field1, Level: 3\n      [4] =\u003e Item: Field.Class2_Field1, Parent: Property.Class1_Prop2, Previous: Property.Class2_Prop2, Next: , Level: 3\n```\n\n* The property `Level` is responsible for reporting on what level of the graph is each item, making it possible to create a identada output that represents the hierarchy of the `model` object.\n* The method `GetEntity` is just a helper that prints the item type and the name of the Member that can be a property or a field. We could also return the value of the Member, but to leave cleaner output, we eliminate this information.\n\n**2)** On second output, see how was the expression of this graph object:\n\n[Click here](https://github.com/juniorgasparotto/GraphExpression#impl-serialization-complex) to understand how the serialization of complex objects.\n\n```\n\"Class1.32854180\" + \"Class1_Prop1: Value1\" + (\"Class1_Prop2.36849274\" + \"Class2_Prop2: Value2\" + \"Class2_Field1: 1000\")\n```\n\nThe extension method `AsExpression` is responsible for creating the complex expression. This method will browse through all the nodes from the root to the last descendant. This method contains the following parameters:\n\n* `ComplexExpressionFactory factory = null`: This parameter must be used when you need to change or extend the default behavior of creating a complex graph. The topic [Customizing complex expressions](https://github.com/juniorgasparotto/GraphExpression#impl-factory-expression-complex) back all the information of how to extend the default behavior.\n* `bool deep = false`: When `true` the expression will be deep, that is, when possible, will repeat entities that have already been navigated. See the topic [Deep search](https://github.com/juniorgasparotto/GraphExpression/blob/master/doc/concept.md#search-deep) to understand the purpose of this functionality.\n\nThis method is available in all .NET objects, simply add the namespace reference: `using GraphExpression` .\n\n**Conclusion:**\n\nIn this topic we saw how simple it is to navigate complex objects, opening paths to research into and.\n\nSee also the topic [Creating complex entities with graph and mathematical expression](https://github.com/juniorgasparotto/GraphExpression#impl-factory-entity-complex), it will show another way to create complex objects.\n\n## Standard elements of a graph for complex types\n\nThe elements of a complex expression ( `Expression\u003cobject\u003e` ) can vary between the following types:\n\n* `ComplexEntity`: This type is the basis for all other types of a complex expression. It is also the root entity type, i.e. the first entity of the expression.\n* `PropertyEntity`: Determines that the item is a property.\n* `FieldEntity`: Determines that the item is a field.\n* `ArrayItemEntity`: Determines that the item is an item of a `array` , i.e., the parent class will be of type `Array` .\n* `CollectionItemEntity`: Determines that the item is an item in a collection, that is, the parent class will be of type `ICollection` .\n* `DynamicItemEntity`: Determines that the item is a dynamic property, i.e., the parent class will be of type `dynamic` .\n\nAll of these types inherit from `ComplexEntity` that for your time inherits from `EntityItem\u003cobject\u003e` , so in addition to its specific properties still have the item information in the expression.\n\nIt is still possible to extend to create a complex expression. To know more see the topic[Customizing complex expressions](https://github.com/juniorgasparotto/GraphExpression#impl-factory-expression-complex)\n\n# \u003ca name=\"impl-graph-circular\" /\u003eCircular graphs\n\nWe define the circular graphs as being those that contain a defined type, i.e. all items are set to the same `T` type.\n\nThis type of graph is presented by class:\n\n```csharp\nGraphExpression.Expression\u003cT\u003e : List\u003cEntityItem\u003cT\u003e\u003e\n```\n\nThis class inherits from `List\u003cEntityItem\u003cT\u003e\u003e` , that is, it is also a collection of class: `EntityItem\u003cT\u003e` .\n\nIn the following example we will convert the object to the `Expression\u003cCircularEntity\u003e` type and show you how was the converted structure:\n\n```csharp\npublic void GraphCircular()\n{\n    var A = new CircularEntity(\"A\");\n    var B = new CircularEntity(\"B\");\n    var C = new CircularEntity(\"C\");\n    var D = new CircularEntity(\"D\");\n\n    // populate A\n    A.Children.Add(B);\n    A.Children.Add(C);\n\n    // populate C\n    C.Children.Add(D);\n\n    // Create circular expression\n    Expression\u003cCircularEntity\u003e expression = A.AsExpression(e =\u003e e.Children, entityNameCallback: o =\u003e o.Name);\n\n    // print 'A'\n    foreach (EntityItem\u003cCircularEntity\u003e item in expression)\n    {\n        var ident = new string(' ', item.Level * 2);\n        var output = $\"{ident}[{item.Index}] =\u003e Item: {item.Entity.Name}, Parent: {item.Parent?.Entity.Name}, Previous: {item.Previous?.Entity.Name}, Next: {item.Next?.Entity.Name}, Level: {item.Level}\";\n        System.Console.WriteLine(output);\n    }\n\n    // Serialize to graph expression\n    System.Console.WriteLine(expression.DefaultSerializer.Serialize());\n}\n\npublic class CircularEntity\n{\n    public string Name { get; private set; }\n    public List\u003cCircularEntity\u003e Children { get; } = new List\u003cCircularEntity\u003e();\n    public CircularEntity(string identity) =\u003e this.Name = identity;\n}\n```\n\n**1)** at the first exit, we see the items `expression` object, representing the object hierarchy `A` :\n\n```\n[0] =\u003e Item: A, Parent: , Previous: , Next: B, Level: 1\n  [1] =\u003e Item: B, Parent: A, Previous: A, Next: C, Level: 2\n  [2] =\u003e Item: C, Parent: A, Previous: B, Next: D, Level: 2\n    [3] =\u003e Item: D, Parent: C, Previous: C, Next: , Level: 3\n```\n\n**2)** On second output, we can see the expression of the graph `A` object:\n\n[Click here](https://github.com/juniorgasparotto/GraphExpression#impl-serialization-circular) to understand how the serialization of circular objects.\n\n```\nA + B + (C + D)\n```\n\nThe extension method `AsExpression\u003cT\u003e` is responsible for creating the circular expression. This method will browse through all the nodes from the root to the last descendant. This method contains the following parameters:\n\n* `Func\u003cT, IEnumerable\u003cT\u003e\u003e childrenCallback`: This parameter determines which are the children of the entities. Is this parameter that will determine the continuity of the implementation. All entities of the graph will call this method until all are navigated. The execution will only be interrupted in case of cyclic relations.\n* `Func\u003cT, object\u003e entityNameCallback`: This parameter is responsible for determining what will be the name of the entity in the serialization or in debug mode. In our example, we use the property `Name` . If this parameter is not passed, the `ToString()` method will be used.\n* `bool deep = false`: When `true` the expression will be deep, that is, when possible, will repeat entities that have already been navigated.\n\nThis method is available in all .NET objects, simply add the namespace reference: `using GraphExpression` .\n\n**Conclusion:**\n\nIn this topic we saw how simple it is to navigate in circular objects, opening paths to research into and.\n\nSee also the topic [Creating circular entities with graph and mathematical expression](https://github.com/juniorgasparotto/GraphExpression#impl-factory-entity-circular), it will show another way to create circular objects without the use of the method `Add()` .\n\n# \u003ca name=\"impl-search\" /\u003eSearching\n\nThere are two types of searches in the concept of graph expression: **unreferenced Research** and **reference search**.\n\n_Attention: in this topic, we will use the model of complex graphs due to your increased complexity._\n\n**[Click here](https://github.com/juniorgasparotto/GraphExpression/blob/master/doc/concept.md#search) to better understand how search works in expression of graph**\n\n## \u003ca name=\"impl-search-without-ref\" /\u003eUnreferenced research\n\nThe \"unreferenced\" will be made into a collection of entities, i.e., each item in the collection will be tested. By repeating the same search in all items in the list, this kind of research can bring duplicates.\n\n[Click here](https://github.com/juniorgasparotto/GraphExpression/blob/master/doc/concept.md#search-without-references) to learn more about this type of research.\n\nWhereas the same models of the example `GraphComplex` , let's create a search to return all descendants of all entities that are a property and children of the class `Class2` .\n\n```csharp\npublic void Search1()\n{\n    // create a simple object\n    var model = new Class1\n    {\n        Class1_Prop1 = \"Value1\",\n        Class1_Prop2 = new Class2()\n        {\n            Class2_Prop2 = \"ValueChild\",\n            Class2_Field1 = 1000\n        }\n    };\n\n    // filter\n    Expression\u003cobject\u003e expression = model.AsExpression();\n    IEnumerable\u003cEntityItem\u003cobject\u003e\u003e result = expression.Descendants(e =\u003e e is PropertyEntity \u0026\u0026 e.Parent.Entity is Class2);\n    foreach (EntityItem\u003cobject\u003e item in result)\n        System.Console.WriteLine(GetEntity(item));\n}\n```\n\n_As expected, the result returned two lines:_\n\n```\nProperty.Class2_Prop2\nProperty.Class2_Prop2\n```\n\n* The first entity (root) had all his descendants tested by filter and following descendant had positive feedback: `Property.Class2_Prop2` .\n* The second `Property.Class1_Prop1` principal was also tested, but she has no descendants.\n* The third `Property.Class1_Prop2` entity had all of its descendants tested and also returned the item: `Property.Class2_Prop2` .\n* The fourth entity on, none returned positive.\n\nIf you want to eliminate repetitions in this type of search (with collections), use the `Linq` function:\n\n```csharp\nDistinct();\n```\n\n## \u003ca name=\"impl-search-with-ref\" /\u003eSearch with reference\n\nThe \"reference search\" will be made using a specific item, that is, first you need to locate the desired item and from it will be done the research you want.\n\n[Click here](https://github.com/juniorgasparotto/GraphExpression/blob/master/doc/concept.md#search-with-references) to learn more about this type of research.\n\nWhereas the same models of the example `GraphComplex` , let's create a search to return all descendants of the root item to be a property and children `Class2` class.\n\n```csharp\npublic void Search2()\n{\n    // create a simple object\n    var model = new Class1\n    {\n        Class1_Prop1 = \"Value1\",\n        Class1_Prop2 = new Class2()\n        {\n            Class2_Prop2 = \"ValueChild\",\n            Class2_Field1 = 1000\n        }\n    };\n\n    // filter\n    Expression\u003cobject\u003e expression = model.AsExpression();\n    EntityItem\u003cobject\u003e root = expression.First();\n    IEnumerable\u003cEntityItem\u003cobject\u003e\u003e result = root.Descendants(e =\u003e e is PropertyEntity \u0026\u0026 e.Parent.Entity is Class2);\n    foreach (EntityItem\u003cobject\u003e item in result)\n        System.Console.WriteLine(GetEntity(item));\n}\n```\n\nAs expected, the result returned one row:\n\n```\nProperty.Class2_Prop2\n```\n\n* Note that the only change was to use the root item as reference ( `First()` ) and it did eliminate duplicates without the need of using the `Distinct` method.\n* This was because only one item was tested (the root item). On \"research without reference\", all items were reviewed and the `Property.Class1_Prop2` item also returns the same result as the root item.\n* When possible, use this type of search, this will make the search faster.\n* The entity root is the best option for this.\n\n## \u003ca name=\"impl-search-kind\" /\u003eTypes of searches\n\nBy default, this project brings the following types of searches:\n\n* `Ancestors`: Returns all ancestors of a given item.\n* `AncestorsUntil`: Returns all ancestors of a given item until the specified filter returns positive.\n* `Descendants`: Returns all descendants of a given item.\n* `DescendantsUntil`: Returns all descendants of a given item until the specified filter returns positive.\n* `Children`: Returns the children of an item.\n* `Siblings`: Returns the siblings of an item.\n* `SiblingsUntil`: Returns the siblings of an item until the specified filter returns positive.\n\nAll these types of searches are available for any of the object types:\n\n* `GraphExpression.EntityItem\u003cT\u003e`: Search with reference\n* `IEnumerable\u003cGraphExpression.EntityItem\u003cT\u003e\u003e`: Search without reference\n\nYou can also create custom searches using C # Extensions methods.\n\n**Without references:**\n\n```csharp\npublic static IEnumerable\u003cEntityItem\u003cT\u003e\u003e Custom\u003cT\u003e(this IEnumerable\u003cEntityItem\u003cT\u003e\u003e references)\n```\n\n**With references:**\n\n```csharp\npublic static IEnumerable\u003cEntityItem\u003cT\u003e\u003e Custom\u003cT\u003e(this EntityItem\u003cT\u003e references)\n```\n\n### Delegates of the research\n\nAll research methods use the following delegates:\n\n```csharp\npublic delegate bool EntityItemFilterDelegate\u003cT\u003e(EntityItem\u003cT\u003e item);\npublic delegate bool EntityItemFilterDelegate2\u003cT\u003e(EntityItem\u003cT\u003e item, int depth);\n```\n\n* `EntityItem\u003cT\u003e item`: This parameter means the current item during the search.\n* `int depth`: Determines the depth of the current item in relation to your position.\n\nYou can use the classes `Func\u003cEntityItem\u003cT\u003e\u003e` and `Func\u003cEntityItem\u003cT\u003e, int\u003e` to simplify use.\n\n### \u003ca name=\"impl-search-ancertors\" /\u003e`Ancestors`\n\nThe search for ancestors is useful to find the father or the parents of an item. We have a few overloads that will be explained below:\n\n**1)** This is the default overload, if no parameter is passed, then no filter is applied and all ancestors will be returned.\n\n```csharp\nIEnumerable\u003cEntityItem\u003cT\u003e\u003e Ancestors(EntityItemFilterDelegate2\u003cT\u003e filter = null, EntityItemFilterDelegate2\u003cT\u003e stop = null, int? depthStart = null, int? depthEnd = null)\n```\n\n* `filter`: Does not return items when the filter return negative but continues searching until you reach the root item. The research uses the delegate `EntityItemFilterDelegate2` , that is, we have the depth information of the item to use in the search.\n* `stop`: Determines when the navigation must stop, otherwise the navigation should go to the root item.\n* `depthStart`: Determines the depth to the research begin\n* `depthEnd`: Determines the depth that the search should stop\n\nIn this example, we will return all the ancestors of the last item of expression, noting that the structure is the same as the example `GraphComplex` :\n\n```\n  [0] =\u003e Item: Class1, Parent: , Previous: , Next: Property.Class1_Prop1, Level: 1\n    [1] =\u003e Item: Property.Class1_Prop1, Parent: Class1, Previous: Class1, Next: Property.Class1_Prop2, Level: 2\n    [2] =\u003e Item: Property.Class1_Prop2, Parent: Class1, Previous: Property.Class1_Prop1, Next: Property.Class2_Prop2, Level: 2\n      [3] =\u003e Item: Property.Class2_Prop2, Parent: Property.Class1_Prop2, Previous: Property.Class1_Prop2, Next: Field.Class2_Field1, Level: 3\n      [4] =\u003e Item: Field.Class2_Field1, Parent: Property.Class1_Prop2, Previous: Property.Class2_Prop2, Next: , Level: 3\n```\n\n```csharp\npublic void Ancertor1()\n{\n    // create a simple object\n    var model = new Class1\n    {\n        Class1_Prop1 = \"Value1\",\n        Class1_Prop2 = new Class2()\n        {\n            Class2_Prop2 = \"ValueChild\",\n            Class2_Field1 = 1000\n        }\n    };\n\n    // transversal navigation\n    Expression\u003cobject\u003e expression = model.AsExpression();\n    EntityItem\u003cobject\u003e lastItem = expression.Last();\n    IEnumerable\u003cEntityItem\u003cobject\u003e\u003e result = lastItem.Ancestors();\n\n    foreach (EntityItem\u003cobject\u003e item in result)\n        System.Console.WriteLine(GetEntity(item));\n\n    System.Console.WriteLine(\"-\u003e Parent\");\n\n    // Get first ancertos (parent)\n    result = lastItem.Ancestors((item, depth) =\u003e depth == 1);\n\n    foreach (var item in result)\n        System.Console.WriteLine(GetEntity(item));\n}\n```\n\n_The first output displays all parents of the item reference._\n\n```\nProperty.Class1_Prop2\nClass1\n```\n\n* Return order will always be the nearest ancestor, that is, the first item in the return list will always be the father of the item reference.\n\n_The second output displays only the ancestor whose depth is equal to `1` , or is, in this case would be the parent item of the item reference:_\n\n```\nProperty.Class1_Prop2\n```\n\n**2)** the second overload has the same filters, however, uses the delegate `EntityItemFilterDelegate` that has only the `item` parameter leaving faster writing.\n\n```csharp\nIEnumerable\u003cEntityItem\u003cT\u003e\u003e Ancestors(EntityItemFilterDelegate\u003cT\u003e filter, EntityItemFilterDelegate\u003cT\u003e stop = null, int? depthStart = null, int? depthEnd = null)\n```\n\n**3)** the third overload filters only by the depth of beginning and end.\n\n```csharp\nIEnumerable\u003cEntityItem\u003cT\u003e\u003e Ancestors(int depthStart, int depthEnd)\n```\n\n**4)** the fourth overload only the final depth filters.\n\n```csharp\nIEnumerable\u003cEntityItem\u003cT\u003e\u003e Ancestors(int depthEnd)\n```\n\n**5)** this method has the same usefulness of standard overload, however he is a simplifier to retrieve all ancestors until any negative `stop` parameter return ancestor. Otherwise it returns all items until you reach the root. He uses the delegate `EntityItemFilterDelegate2` , that is, we have the depth information of the item to use in the search.\n\n```csharp\nIEnumerable\u003cEntityItem\u003cT\u003e\u003e AncestorsUntil(EntityItemFilterDelegate2\u003cT\u003e stop, EntityItemFilterDelegate2\u003cT\u003e filter = null)\n```\n\n**6)** the second method overload `AncestorsUntil` has the same filters, however, uses the delegate `EntityItemFilterDelegate` that has only the `item` parameter leaving faster writing.\n\n```csharp\nIEnumerable\u003cEntityItem\u003cT\u003e\u003e AncestorsUntil(EntityItemFilterDelegate\u003cT\u003e stop, EntityItemFilterDelegate\u003cT\u003e filter = null)\n```\n\n### \u003ca name=\"impl-search-descentands\" /\u003e`Descendants`\n\nThe descendants search is useful to find the children or all descendants of an item. We have a few overloads that will be explained below:\n\n**1)** This is the default overload, if no parameter is passed, then no filter is applied and all descendants will be returned.\n\n```csharp\nIEnumerable\u003cEntityItem\u003cT\u003e\u003e Descendants(EntityItemFilterDelegate2\u003cT\u003e filter = null, EntityItemFilterDelegate2\u003cT\u003e stop = null, int? depthStart = null, int? depthEnd = null)\n```\n\n* `filter`: Does not return items when the filter return negative but continues searching until you get to the last item. The research uses the delegate `EntityItemFilterDelegate2` , that is, we have the depth information of the item to use in the search.\n* `stop`: Determines when the navigation must stop, otherwise the navigation should go to the last item.\n* `depthStart`: Determines the depth to the research begin\n* `depthEnd`: Determines the depth that the search should stop\n\nIn this example, we will return all descendants of the root item whose initial and final depth is equal to `2` , we will use the same structure of the example `GraphComplex` :\n\n```\n  Class1                            // ***** ROOT *****\n    PropertyEntity.Class1_Prop1     // Deph = 1\n    PropertyEntity.Class1_Prop2     // Deph = 1\n      PropertyEntity.Class2_Prop2   // Deph = 2\n      FieldEntity.Class2_Field1     // Deph = 2\n```\n\n```csharp\npublic void Descendants1()\n{\n    // create a simple object\n    var model = new Class1\n    {\n        Class1_Prop1 = \"Value1\",\n        Class1_Prop2 = new Class2()\n        {\n            Class2_Prop2 = \"ValueChild\",\n            Class2_Field1 = 1000\n        }\n    };\n\n    // filter\n    Expression\u003cobject\u003e expression = model.AsExpression();\n    EntityItem\u003cobject\u003e root = expression.First();\n    IEnumerable\u003cEntityItem\u003cobject\u003e\u003e result = root.Descendants(2, 2);\n    foreach (EntityItem\u003cobject\u003e item in result)\n        System.Console.WriteLine(GetEntity(item));\n}\n```\n\n_The output will be:_\n\n```\nProperty.Class2_Prop2\nField.Class2_Field1\n```\n\n**2)** the second overload has the same filters, however, uses the delegate `EntityItemFilterDelegate` that has only the `item` parameter leaving faster writing.\n\n```csharp\nIEnumerable\u003cEntityItem\u003cT\u003e\u003e Descendants(EntityItemFilterDelegate\u003cT\u003e filter, EntityItemFilterDelegate\u003cT\u003e stop = null, int? depthStart = null, int? depthEnd = null)\n```\n\n**3)** the third overload filters only by the depth of beginning and end.\n\n```csharp\nIEnumerable\u003cEntityItem\u003cT\u003e\u003e Descendants(int depthStart, int depthEnd)\n```\n\n**4)** the fourth overload only the final depth filters.\n\n```csharp\nIEnumerable\u003cEntityItem\u003cT\u003e\u003e Descendants(int depthEnd)\n```\n\n**5)** this method has the same usefulness of standard overload, however he is a simplifier to retrieve all descendants until some descendant return negative in the parameter \"stop\". Otherwise it returns all items until you get to the last item. He uses the delegate `EntityItemFilterDelegate2` , that is, we have the depth information of the item to use in the search.\n\n```csharp\nIEnumerable\u003cEntityItem\u003cT\u003e\u003e DescendantsUntil(EntityItemFilterDelegate2\u003cT\u003e stop, EntityItemFilterDelegate2\u003cT\u003e filter = null)\n```\n\n**6)** the second method overload `DescendantsUntil` has the same filters, however, uses the delegate `EntityItemFilterDelegate` that has only the `item` parameter leaving faster writing.\n\n```csharp\nIEnumerable\u003cEntityItem\u003cT\u003e\u003e DescendantsUntil(EntityItemFilterDelegate\u003cT\u003e stop, EntityItemFilterDelegate\u003cT\u003e filter = null)\n```\n\n### \u003ca name=\"impl-search-children\" /\u003e`Children`\n\nTo return the children of an item just use the method:\n\n```csharp\nIEnumerable\u003cEntityItem\u003cT\u003e\u003e Children()\n```\n\nIn this example we return root item's children:\n\n```csharp\npublic void Children()\n{\n    // create a simple object\n    var model = new Class1\n    {\n        Class1_Prop1 = \"Value1\",\n        Class1_Prop2 = new Class2()\n        {\n            Class2_Prop2 = \"ValueChild\",\n            Class2_Field1 = 1000\n        }\n    };\n\n    // filter\n    Expression\u003cobject\u003e expression = model.AsExpression();\n    EntityItem\u003cobject\u003e root = expression.First();\n    IEnumerable\u003cEntityItem\u003cobject\u003e\u003e result = root.Children();\n    foreach (EntityItem\u003cobject\u003e item in result)\n        System.Console.WriteLine(GetEntity(item));\n}\n```\n\n_The output will display the two properties that are children of the root item:_\n\n```\nProperty.Class1_Prop1\nProperty.Class1_Prop2\n```\n\n* This method has no parameters, simply use the `Linq` functions if you need some filtering.\n* This method is a `Descendants(int depthStart, int depthEnd)` method alias, which will be passed the fixed values `Descendants(1, 1)` .\n\n### \u003ca name=\"impl-search-siblings\" /\u003e`Siblings`\n\nThis search finds the brothers of a given item. We have a few overloads that will be explained below:\n\n**1)** This is the default overload, if no parameter is passed, then no filter is applied and all descendants will be returned.\n\n```csharp\nIEnumerable\u003cEntityItem\u003cT\u003e\u003e Siblings(EntityItemFilterDelegate2\u003cT\u003e filter = null, EntityItemFilterDelegate2\u003cT\u003e stop = null, SiblingDirection direction = SiblingDirection.Start, int? positionStart = null, int? positionEnd = null)\n```\n\n* `filter`: Does not return items when the filter return negative but continues searching until the last brother or first (depends on the `direction` parameter). The research uses the delegate `EntityItemFilterDelegate2` , that is, we have the depth information of the item to use in the search.\n* `stop`: Determines when the navigation must stop, otherwise the navigation should go until the last brother or first (depends on the `direction` parameter).\n* `direction`: This parameter determines in which direction navigation should go:\n  * `Start`: Determines which navigation should start on the first brother positioned to the left of the reference item and go to the last brother to the right.\n  * `Next`: Determines which navigation should start next brother positioned to the right of the item and go to the last brother to the right.\n  * `Previous`: Determines which navigation should start next brother positioned to the left of the reference item and go to the first brother left.\n* `positionStart`: Determines the initial position that the search should start.\n  * When the direction is equal to `Start` , the position `1` will be the first sibling to the left of the reference item.\n  * When the direction is equal to `Next` , the position `1` will be the next sibling to the right of the item reference.\n  * When the direction is equal to `Previous` , the position `1` will be the next sibling to the left of the reference item.\n* `positionEnd`: Determines the end position that the search should stop.\n\nIn this example we will return the item whose brothers value is equal `C` in all directions.\n\n```csharp\npublic void Siblings1()\n{\n    // create a simple object\n    var model = new\n    {\n        A = \"A\",\n        B = \"B\",\n        C = \"C\",\n        D = \"D\",\n        E = \"E\",\n    };\n\n    // Get Siblings1 from C - Start direction\n    System.Console.WriteLine(\"-\u003e Start direction\");\n    Expression\u003cobject\u003e expression = model.AsExpression();\n    var C = expression.Where(f =\u003e f.Entity as string == \"C\");\n    IEnumerable\u003cEntityItem\u003cobject\u003e\u003e result = C.Siblings(direction: SiblingDirection.Start);\n    foreach (EntityItem\u003cobject\u003e item in result)\n        System.Console.WriteLine(item.ToString());\n\n    // Get Siblings1 from C - Next direction            \n    System.Console.WriteLine(\"-\u003e Next direction\");\n    result = C.Siblings(direction: SiblingDirection.Next);\n    foreach (EntityItem\u003cobject\u003e item in result)\n        System.Console.WriteLine(item.ToString());\n\n    // Get Siblings1 from C - Previous direction\n    System.Console.WriteLine(\"-\u003e Previous direction\");\n    result = C.Siblings(direction: SiblingDirection.Previous);\n    foreach (EntityItem\u003cobject\u003e item in result)\n        System.Console.WriteLine(item.ToString());\n}\n```\n\n_The first exit returns all the brothers of the `C` entity initiating the first sibling to the left until the last sibling to the right. It is important to highlight that the item itself is not returned, after all he's not brother himself._\n\n```\n-\u003e Start direction\nA: A\nB: B\nD: D\nE: E\n```\n\n_The second exit returns all the brothers of the `C` entity initiating the next sibling to the right till the last sibling to the right._\n\n```\n-\u003e Next direction\nD: D\nE: E\n```\n\n_The third exit returns all the brothers of the `C` entity initiating the previous sibling to the first brother left._\n\n```\n-\u003e Previous direction\nB: B\nA: A\n```\n\n**2)** the second overload has the same filters, however, uses the delegate `EntityItemFilterDelegate` that has only the `item` parameter leaving faster writing.\n\n```csharp\nIEnumerable\u003cEntityItem\u003cT\u003e\u003e Siblings(EntityItemFilterDelegate\u003cT\u003e filter, EntityItemFilterDelegate\u003cT\u003e stop = null, SiblingDirection direction = SiblingDirection.Start, int? positionStart = null, int? positionEnd = null)\n```\n\n**3)** the third overload filters only by the depth of beginning and end in the specified direction.\n\n```csharp\nIEnumerable\u003cEntityItem\u003cT\u003e\u003e Siblings(int positionStart, int positionEnd, SiblingDirection direction = SiblingDirection.Start)\n```\n\n**4)** the fourth overload only the final depth of filters specified direction.\n\n```csharp\nIEnumerable\u003cEntityItem\u003cT\u003e\u003e Siblings(int positionEnd, SiblingDirection direction = SiblingDirection.Start)\n```\n\n**5)** this method has the same usefulness of standard overload, however he is a simplifier to retrieve all the brothers until a brother return negative in the parameter \"stop\". Otherwise be returned all the brothers until the last or the first (depends on the `direction` parameter). He uses the delegate `EntityItemFilterDelegate2` , that is, we have the depth information of the item to use in the search.\n\n```csharp\nIEnumerable\u003cEntityItem\u003cT\u003e\u003e SiblingsUntil(EntityItemFilterDelegate2\u003cT\u003e stop, EntityItemFilterDelegate2\u003cT\u003e filter = null, SiblingDirection direction = SiblingDirection.Start)\n```\n\n**6)** the second method overload `SiblingsUntil` has the same filters, however, uses the delegate `EntityItemFilterDelegate` that has only the `item` parameter leaving faster writing.\n\n```csharp\nIEnumerable\u003cEntityItem\u003cT\u003e\u003e SiblingsUntil(EntityItemFilterDelegate\u003cT\u003e stop, EntityItemFilterDelegate\u003cT\u003e filter = null, SiblingDirection direction = SiblingDirection.Start)\n```\n\n# \u003ca name=\"impl-factory-expression-complex\" /\u003eCustomizing complex expressions\n\nThe method `object.AsExpression` is the fastest way to create a graph. When called without any parameters, it will create an instance of the object `Expression\u003cobject\u003e` that represents an expression of complex graph.\n\nThis method is located in the static class `GraphExpression.ComplexExpressionExtensions` and contains the following parameters:\n\n* `this object entityRoot`: The object that will be extended to accommodate the new method and also to be the root of the expression.\n* `ComplexExpressionFactory factory = null`: This parameter must be used when you need to change or extend the default behavior of creating a complex graph.\n* `bool deep = false`: When `true` the expression will be deep, that is, when possible, will repeat entities that have already been navigated.\n\nThe class `GraphExpression.ComplexExpressionFactory` is the class responsible for creating/customizing a complex expression. This class has some properties that increase the power of creation of the expression:\n\n* `List\u003cIEntityReader\u003e Readers`: With this list you can create or change the reading of entities for certain types of objects.\n* `List\u003cIMemberReader\u003e MemberReaders`: With this list you can create or change the readers of members.\n* `Func\u003cobject, IEnumerable\u003cPropertyInfo\u003e\u003e GetProperties`: Method that delegates to the user the option to determine which properties will be loaded. By default, will be used: `entity.GetType().GetProperties()` .\n* `Func\u003cobject, IEnumerable\u003cFieldInfo\u003e\u003e GetFields`: Method that delegates to the user the option to determine which fields are loaded. By default, will be used: `entity.GetType().GetFields()` .\n\nYou can use the instance of this class in the parameter `factory` of the method `object.AsExpression` or simply call the method `Build` that returns the instance of the `Expression\u003cobject\u003e` class, arriving at the same goal.\n\n```csharp\nExpression\u003cobject\u003e Build(object entityRoot, bool deep = false)\n```\n\n* `entityRoot`: Entity that will be the root of the expression.\n* `deep`: When `true` the expression will be profound.\n\nIn the example below, we will create a new reader of members ( `MethodReader` ) that have as objective to invoke the method `HelloWorld` of the class `Model` . We will create a new entity type complex ( `MethodEntity` ) to store the result of the method.\n\nNoting that the methods are not supported by default, only fields and properties are supported.\n\n```csharp\npublic void ComplexExpressionFactory()\n{\n    var factory = new ComplexExpressionFactory();\n    factory.MemberReaders.Add(new MethodReader());\n    var model = new Model();\n    var expression = model.AsExpression(factory);\n\n    foreach(ComplexEntity item in expression)\n    {\n        var output = GetEntity(item);\n        if (item is MethodEntity method)\n            output = $\"MethodEntity.{method.MethodInfo.Name}({method.Parameters[0]}, {method.Parameters[1]})\";\n        System.Console.WriteLine(output);\n    }\n}\n\npublic class MethodReader : IMemberReader\n{\n    public IEnumerable\u003cComplexEntity\u003e GetMembers(ComplexExpressionFactory factory, GraphExpression.Expression\u003cobject\u003e expression, object entity)\n    {\n        if (entity is Model)\n        {\n            var method = entity\n                .GetType()\n                .GetMethods().Where(f =\u003e f.Name == \"HelloWorld\")\n                .First();\n\n            var parameters = new object[] { \"value1\", \"value2\" };\n            var methodValue = method.Invoke(entity, parameters);\n            yield return new MethodEntity(expression, method, parameters, methodValue);\n        }\n    }\n}\n\nprivate class MethodEntity : ComplexEntity\n{\n    public MethodInfo MethodInfo { get; }\n    public object[] Parameters { get; }\n\n    public MethodEntity(Expression\u003cobject\u003e expression, MethodInfo methodInfo, object[] parameters, object value)\n        : base(expression)\n    {\n        this.MethodInfo = methodInfo;\n        this.Parameters = parameters;\n        this.Entity = value;\n    }\n}\n\nprivate class Model\n{\n    public string HelloWorld(string val1, string val2)\n    {\n        return $\"{val1}-{val2}\";\n    }\n}\n```\n\n_The output shows as was the expression with the new type of complex entity. The first item of the output is the root item and the second item is the new entity._\n\n```\nModel\nMethodEntity.HelloWorld(value1, value2)\n```\n\n## Readers of members\n\nThe readers of members \"inherit from the `IMemberReader` class. Its main purpose is to read the members of an instance and return to the expression.\n\n```csharp\npublic interface IMemberReader\n{\n    IEnumerable\u003cComplexEntity\u003e GetMembers(ComplexExpressionFactory factory, Expression\u003cobject\u003e expression, object entity);\n}\n```\n\nBy default, we have two readers of members:\n\n* `FieldReader`: This reader returns the fields of the instance using the`factory.GetFields`\n* `PropertyReader`: This reader returns the instance properties using the property`factory.GetProperties`\n\n_Attention: readers of members must be used by the readers of entities. If your reader doesn't do this job then your expression does not have members._\n\n## Readers of entities\n\nThe \"principal players\" are mainly responsible for the creation of complex expression and the property `Readers` will be used to find the best reader for each entity of the iteration.\n\nReaders of entities must inherit from `IEntityReader` interface and the method `CanRead` is responsible for determining if the entity may or may not be read by the reader. When the method `CanRead` returns `true` then the method `GetChildren` will be called and it is at this point that the items of the expression will be effectively created.\n\n```csharp\npublic interface IEntityReader\n{\n    bool CanRead(ComplexExpressionFactory factory, object entity);\n    IEnumerable\u003cComplexEntity\u003e GetChildren(ComplexExpressionFactory factory, Expression\u003cobject\u003e expression, object entity);\n}\n```\n\nThe order of the readers is of the utmost importance, since the last reader of the list will be used in the event of a tie, in other words, if three readers return `true` , the last on the list will be used.\n\nBy default, we have some readers of defined entities and all of them are already sorted on the property `Readers` to prevent reading errors.\n\n1. `DefaultReader`: This is the default class for all entities. Its function is to read the members of any type, with the exception of types that are in `System` and `Microsoft` . He is the first reader, i.e. If there is some other that returns `true` in the method `CanRead` , then this class is ignored.\n2. `CollectionReader`: This reader is responsible for reading objects that inherit from the `ICollection` type. He is the second and must always be above `ArrayReader` and `DictionaryReader` readers. This is necessary because the objects `Array` types and `IDictionary` also inherit from `ICollection` and these readers must have priority over this.\n3. `ArrayReader`: This reader is responsible for reading objects of type`Array`\n4. `DictionaryReader`: This reader is responsible for reading objects that inherit from the type`IDictionary`\n5. `DynamicReader`: This reader is responsible for reading objects that inherit from the `ExpandoObject` type. This reader must have priority over the reader `DictionaryReader` , so it is positioned below this reader.\n\nReaders of entities are solely responsible for reading the members, that is, if your \"principal player\" customized you want to keep the members of the entity, so don't forget to iterate over the property `MemberReaders` and do the due return.\n\nHere is an example of how to use the property `MemberReaders` within the readers of entities. This code belongs to the reader:`CollectionReader`\n\nNote that in addition to the reading of the list members are also created and returned. This is necessary because there may be business classes that have public properties and still inherit from `ICollection` .\n\n```csharp\npublic class CollectionReader : IEntityReader\n{\n    public bool CanRead(ComplexExpressionFactory factory, object entity)\n    {\n        return entity is System.Collections.ICollection;\n    }\n\n    public IEnumerable\u003cComplexEntity\u003e GetChildren(ComplexExpressionFactory factory, Expression\u003cobject\u003e expression, object entity)\n    {\n        var list = (System.Collections.ICollection)entity;\n        var enumerator = list.GetEnumerator();\n        var count = 0;\n        while (enumerator.MoveNext())\n            yield return new CollectionItemEntity(expression, count++, enumerator.Current);\n\n        // read members, it may happen to be an instance of the \n        // user that inherits from IList, so you need to read the members.\n        foreach (var memberReader in factory.MemberReaders)\n        {\n            var items = memberReader.GetMembers(factory, expression, entity);\n            foreach (var item in items)\n                yield return item;\n        }\n    }\n}\n```\n\n# \u003ca name=\"impl-factory-entity-circular\" /\u003eCreating circular entities with graph and mathematical expression\n\nOne of the advantages of `C#` language is that it allows you to override mathematical operators leaving the operation to the programmer. With this action delegated to the programmer it is possible to use the concept of graph expression to insert or remove an entity from the other.\n\nIf you have read the documentation on the expression of concept graph then you already know that the entity of the left of the operation is the parent entity and the entity of the right side of the operation is the daughter.\n\nWith that in mind, we will show a way to create **circular graphs** using only C # and mathematics.\n\nIn the sample code, we will overwrite `+` and operators `-` and delegate to them the following actions:\n\n* `+`: Add the \"right\" entity as being the daughter of \"the left\".\n* `-`: Remove the \"right-hand entity\" sons of \"entity list of the left\".\n\nTo the left of the operation entity is represented by the parameter `a` and the entity of the right side of the operation is represented by the parameter `b` .\n\n```csharp\npublic class CircularEntity\n{\n    public static CircularEntity operator +(CircularEntity a, CircularEntity b)\n    {\n        a.Children.Add(b);\n        return a;\n    }\n\n    public static CircularEntity operator -(CircularEntity a, CircularEntity b)\n    {\n        a.Children.Remove(b);\n        return a;\n    }\n\n    public string Name { get; private set; }\n    public List\u003cCircularEntity\u003e Children { get; } = new List\u003cCircularEntity\u003e();\n    public CircularEntity(string identity) =\u003e this.Name = identity;\n}\n```\n\nNote that the class `CircularEntity` can now be used in any mathematical expression:\n\n```csharp\npublic void GraphCircular()\n{\n    var A = new CircularEntity(\"A\");\n    var B = new CircularEntity(\"B\");\n    var C = new CircularEntity(\"C\");\n    var D = new CircularEntity(\"D\");\n\n    // ACTION: ADD\n    A = A + B + (C + D);\n}\n```\n\n_This code will create the graph of the entity `A` generating the following structure:_\n\n```\n[0] =\u003e A\n    [1] =\u003e B\n    [2] =\u003e C\n         [3] =\u003e D\n```\n\n_We now remove the entity `D` from `C` entity:_\n\n```csharp\npublic void GraphCircular()\n{\n    C = C - D;\n}\n```\n\n_The final structure of the entity `A` will be:_\n\n```\n[0] =\u003e A\n    [1] =\u003e B\n    [2] =\u003e C\n```\n\n_The final graph expression, after removal, would look like this:_\n\n```\nA + B + C\n```\n\n# \u003ca name=\"impl-factory-entity-complex\" /\u003eCreating complex entities with graph and mathematical expression\n\nCreate complex entities with graph expression is not a simple task as we have seen in circular graphs. You need a robust class structure and the use of reflection to compose the entities.\n\nLet's look at an example of how to create a complex class of type `CircularEntity` using only graph expression. The idea is to assign a value to the property `Name` .\n\n```csharp\npublic void EntityFactory()\n{\n    var root = new Entity(0) + new Entity(\"Name: Entity name ;)\");\n    var factory = new ComplexEntityFactory\u003cCircularEntity\u003e(root);\n\n    // Build entity\n    factory.Build();\n\n    var entity = factory.Value;\n    System.Console.WriteLine(entity.Name);\n}\n```\n\nThe output shows that the property `Name` has been filled:\n\n```\nEntity name ;)\n```\n\nNote that we're using mathematical expressions and assemble the entity `CircularEntity` type without using the command `new` .\n\nThe order of the expression is the same as we saw in the circular bodies, namely, the item on the left of the expression is the parent item of the item on the right of expression. Because it is a complex type, the item on the left is the instance and the item on the right is the Member.\n\nIn the language `C#` we have two types of members: **Properties** and **Fields** and both can be used in the expression independent of your visibility.\n\n## \u003ca name=\"impl-factory-entity-complex-class-entity\" /\u003eUnderstanding `Entity` class\n\nThis class represents an entity of the graph and the place where she might be. Each location is represented by a specific constructor and see it below:\n\n**1)** this constructor represents a complex type located at the root of the expression, the `complexEntityId` parameter is required and is used to assign an ID for the entity. This ID is important because you may want to use this instance to another location of the graph.\n\n```csharp\nEntity(int complexEntityId)\n```\n\n**2)** the second constructor creates an entity located in a member, that is, can be a property or a field. The `Name` parameter will set the name of the Member. The `complexEntityId` parameter will assign this member the entity which corresponds to that ID.\n\n```csharp\nEntity(string name, int complexEntityId)\n```\n\nIn the example below, we will see the use of the first two constructors where we create an object of type `MyClass` with ID equal to `0` and we will assign `Child` the entity property whose identification is also equal to `0` , that is, the root entity itself.\n\n```csharp\npublic void EntityFactory2()\n{\n    var root = new Entity(0) + new Entity(\"Child\", 0);\n    var factory = new ComplexEntityFactory\u003cMyClass\u003e(root);\n\n    // Build entity\n    factory.Build();\n\n    var entity = factory.Value;\n    System.Console.WriteLine(entity == entity.Child);\n}\n\nprivate class MyClass\n{\n    private int _intValue;\n    public MyClass Child { get; set; }\n    public int IntValue =\u003e _intValue;\n}\n```\n\nThe output shows that the entities are exactly the same:\n\n```\nTrue\n```\n\n**3)** the third constructor should be used when you need to assign a value that is not a reference, i.e. any primitive type. These values should be passed in text form to be assigned correctly.\n\n```csharp\nEntity(string name, string value)\n```\n\nIt is important to note that non-public members can also have values assigned. And in our next example we will demonstrate how to assign a value in the private field `_intValue` .\n\nNote also that the value is in the form of text, and this is important because the constructor that accepts an integer value is unique to assign references and not primitive values.\n\n```csharp\npublic void EntityFactory3()\n{\n    var root = new Entity(0) + new Entity(\"_intValue\", \"1000\");\n    var factory = new ComplexEntityFactory\u003cMyClass\u003e(root);\n\n    // Build entity\n    factory.Build();\n\n    var entity = factory.Value;\n    System.Console.WriteLine(typeof(MyClass).GetField(\"_intValue\", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(entity));\n}\n```\n\nThis output will produce the value below and it was necessary to obtain the value via reflection due to fields ' visibility `_intValue` :\n\n```\n1000\n```\n\n**4)** the last contains only the constructor parameter: `string raw` . The value of this parameter must be in the form of **complex entities in text form**.\n\n```csharp\nEntity(string raw)\n```\n\nIn the following example we will see the creation of an entity where we populate the private field `_intValue` using the **format of complex entities in text form**.\n\n```csharp\npublic void EntityFactory4()\n{\n    var root = new Entity(0) + new Entity(\"System.Int32._intValue: 1000\");\n    var factory = new ComplexEntityFactory\u003cMyClass\u003e(root);\n\n    // Build entity\n    factory.Build();\n\n    var entity = factory.Value;\n    System.Console.WriteLine(typeof(MyClass).GetField(\"_intValue\", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(entity));\n}\n```\n\nThis output will produce the value below and it was necessary to obtain the value via reflection due to fields ' visibility `_intValue` :\n\n```\n1000\n```\n\nThis format is divided into two: **primitive types** and **complex types** and see that in the next topics.\n\n**Class properties:**\n\n* `IEntityFactory Factory`: Property that contains the instance of the entities.\n* `Entity Parent`: Property that determines the parent entity in the expression.\n* `IReadOnlyCollection\u003cEntity\u003e Children`: Property that contains all the children.\n* `Entity this[int index]`: Property that returns a child by index.\n* `Entity this[string key]`: Property that returns a son by the name of the Member.\n* `List\u003cOperation\u003e Operations`: Property that contains all the operations for the execution in the factories of entities. This property is clean in all other entities, except for the root entity.\n* `string Raw`: Property that determines the text entity.\n* `Type Type`: Property that determines the type of the entity.\n* `MemberInfo MemberInfo`: Property that determines the Member.\n* `string Name`: Property that determines the name of the Member.\n* `object Value`: Property that determines the value, that is, the entity itself.\n* `string ValueRaw`: Property that determines the value in text form.\n* `bool IsPrimitive`: Property that indicates whether the value is primitive or not.\n* `string ComplexEntityId`: Property that indicates the ID of the entity.\n\n## \u003ca name=\"impl-factory-entity-complex-primitive\" /\u003eComplex entities in text form-primitive types\n\nFor primitive types, we have the following format:\n\n```\n[TypeName].[MemberName]: [Value]\n```\n\nThe square brackets indicate that the part is not mandatory, in the format above we see that the type is not required, however, when she is present, we should add a `.` .\n\nThe second part should not exist for the entity that is located at the root of the expression, after all if she is at the root she has no father.\n\nThe second entity in the second part is mandatory and indicates the name of the Member that can be a property or a field.\n\nThe next part is the `:` separator that divides the member name and your value. If the value of the Member is null, the tab will not be displayed.\n\n**Let's see some examples:**\n\n_Displays the type and the value of primitive entity that is located in the root. For being the root entity so there will be no member name:_\n\n```\nSystem.String: Value\n```\n\n_Displays the type, the value of the entity and primitive Member that is in the second position on:_\n\n```\nSystem.String.StrValue: Value\n```\n\n_Displays the type, Member, and an empty value of primitive entity that is in the second position on:_\n\n```\nSystem.String.StrValue: \n```\n\n_Displays the type and the Member when the value is null. Does not display the \"separator\", this is indicative that the value is null:_\n\n```\nSystem.String.StrValue\n```\n\n## \u003ca name=\"impl-factory-entity-complex-complex\" /\u003eComplex entities in text-form complex types\n\nFor complex types, we have the following format:\n\n```\n[TypeName].[MemberName].EntityID\n```\n\nThe square brackets indicate that the part is not mandatory, in the format above we see that the type is not required, however, when she is present, we should add a `.` .\n\nThe second part should not exist for the entity that is located at the root of the expression, after all if she is at the root she has no father.\n\nThe second entity in the second part is mandatory and indicates the name of the Member that can be a property or a field.\n\nThe next part is the ID of the entity in the graph. This ID must be an integer and it is she who ensures the possibility to use the same entity references in other parts of the graph.\n\n**Let's see some examples:**\n\n_Displays the type and ID of the complex entity that is located in the root. We'll use the ID equal to `0` . For being the root entity so there will be no member name:_\n\n```\nNamespace.MyClass.0\n```\n\n_Displays the type, Member, and the identification of the complex entity that is located in second position on. We'll use the ID equal to `1` :_\n\n```\nNamespace.MyClass.MyProperty.1\n```\n\n_Displays the type and the Member when the value is null. Displays no identification, because there is no entity. This is indicative that the value is null:_\n\n```\nNamespace.MyClass.MyProperty\n```\n\n## \u003ca name=\"impl-factory-entity-complex-collections\" /\u003eComplex entities in text form-Collections and arrays\n\nTo create items in a collection or array, the name of the Member must be a position within the brackets:`[{position}]: Value`\n\nIn the example below we will see how to create an array of integers using only graph expression. Note that instead of the member name, use the brackets as indicative of a collection item.\n\n```csharp\npublic void EntityFactory5()\n{\n    var root = new Entity(0) + new Entity(\"[0]\", \"10\") + new Entity(\"[1]: 11\");\n    var factory = new ComplexEntityFactory\u003cint[]\u003e(root);\n\n    // Build entity and get typed value\n    var entity = factory.Build().Value;\n    System.Console.WriteLine(entity[0]);\n    System.Console.WriteLine(entity[1]);\n}\n```\n\nThe output will be:\n\n```\n10\n11\n```\n\n## \u003ca name=\"impl-factory-entity-complex-class-complex-factory\" /\u003eUnderstanding `ComplexEntityFactory` class\n\nThis class is responsible for creating the graph of the complex entity based in the expression. Internally she re-executes the expression and generates each entity of the graph.\n\nThis class contains the following constructor:\n\n```csharp\nComplexEntityFactory(Type type, Entity root = null)\n```\n\n* `type`: This parameter determines the type of the root entity.\n* `root`: This parameter determines which is the root entity. It is not mandatory, because this class is also used in deserialization where the root entity is obtained.\n\nWe have some properties that will help in the creation and customization of the entities:\n\n* `IReadOnlyList\u003cEntity\u003e Entities`: Property that stores all the entities of the graph and without repeating them.\n* `bool IsTyped`: Property that indicates whether the creation has a defined type.\n* `IReadOnlyDictionary\u003cType, Type\u003e MapTypes`: Property that contains the maps for interfaces or abstract classes, or even to concrete classes if necessary.\n* `IReadOnlyList\u003cstring\u003e Errors`: Property that stores the errors.\n* `bool IgnoreErrors`: Property that indicates whether errors are ignored. Otherwise an exception will be sent.\n* `List\u003cITypeDiscovery\u003e TypeDiscovery`: Property that contains a list of discovery classes.\n* `List\u003cIValueLoader\u003e ValueLoader`: Property that contains a list of classes to initialize values.\n* `List\u003cIMemberInfoDiscovery\u003e MemberInfoDiscovery`: Property that contains a list of classes to find members.\n* `List\u003cISetChild\u003e SetChildAction`: Property that contains a list of classes that make the assignments of the daughters in the parent entities.\n* `Entity Root`: Property that indicates the root entity.\n* `Type RootType`: Property that indicates the type of the root entity.\n* `object Value`: Value of the root entity.\n\nFinally, we have some methods that are used when creating:\n\n* `ComplexEntityFactory Build()`: This method is responsible for generating the graph. This method should return the class itself to maintain fluency.\n* `void AddMapType\u003cTFrom, TTo\u003e()`: This method must be used before the method `Build` and it determines the mapping of types.\n* `void AddError(string err)`\n\nThere is also a variation of this class that allows you to work in a generic way and this facilitates the use of `Value` property which will already be with type set.\n\n```csharp\nComplexEntityFactory\u003cT\u003e()\n```\n\nIn the next example, we will see the creation of an entity that contains no properties with concrete types, being necessary the creation of a map of types:\n\n```csharp\npublic void EntityFactory6()\n{\n    var root = new Entity(0) \n        + (new Entity(\"A\", 1) + new Entity(\"MyProp\", \"10\"))\n        + (new Entity(\"B\", 2) + new Entity(\"MyProp\", \"20\"));\n\n    var factory = new ComplexEntityFactory\u003cClassWithAbstractAndInterface\u003e(root);\n    factory.AddMapType\u003cInterface, ImplementAbstractAndInterface\u003e();\n    factory.AddMapType\u003cAbstractClass, ImplementAbstractAndInterface\u003e();\n\n    // Build entity and get typed value\n    var entity = factory.Build().Value;\n    System.Console.WriteLine(entity.A.MyProp);\n    System.Console.WriteLine(entity.A.GetType().Name);\n    System.Console.WriteLine(entity.B.MyProp);\n    System.Console.WriteLine(entity.B.GetType().Name);\n}\n```\n\nThe output shows that the properties `A` and `B` were created with the `ImplementAbstractAndInterface` type and the properties `A.MyProp` and `B.MyProp` have also been populated:\n\n```\n10\nImplementAbstractAndInterface\n20\nImplementAbstractAndInterface\n```\n\n## \u003ca name=\"impl-factory-entity-complex-discovery-types\" /\u003eDiscoverers of types\n\nThe \"discoverers of types ' main objective is to find out the type of the entity. The property `TypeDiscovery` will be used to find the best option for each entity.\n\nThe discoverers of types must inherit from `ITypeDiscovery` interface and the method `CanDiscovery` is responsible for determining if the entity may or may not be discovered. When the method `CanDiscovery` returns `true` then the method `GetEntityType` is called and this is where the type of the entity is returned.\n\n```csharp\npublic interface ITypeDiscovery\n{\n    bool CanDiscovery(Entity item);\n    Type GetEntityType(Entity item);\n}\n```\n\nThe order of discovery is of the utmost importance, since the last of the list will be used in the event of a tie, in other words, if three return `true` , the last on the list will be used.\n\nBy default, we have some discoverers of types defined and all of them are already sorted on the property `TypeDiscovery` to prevent errors.\n\n1. `DictionaryItemTypeDiscovery`: This class is responsible for finding out the type of an item in the dictionary. The method `CanDiscovery` checks whether the parent type is a dictionary, if it is, then the method `GetEntityType` will be called by returning the `KeyValuePair\u003c,\u003e` type.\n2. `MemberInfoTypeDiscovery`: This class is responsible for finding out the type of the Member. The method `CanDiscovery` checks if the entity contains a member name, if it does, then the method `GetEntityType` will be called to get the type of the Member.\n3. `ListItemTypeDiscovery`: This class is responsible for finding out the type of an item in a list. The method `CanDiscovery` checks whether the father is a type `IList` , if it is, then the method `GetEntityType` will be invoked to get the type of the list.\n4. `ArrayItemTypeDiscovery`: This class is responsible for finding out the type of an item in the array. The method `CanDiscovery` checks whether the parent type is an array, if it is, then the method `GetEntityType` will be invoked to get the type of the array.\n\n## \u003ca name=\"impl-factory-entity-complex-discovery-members\" /\u003eDiscoverers of members\n\nThe \"discoverers of members\" aims to discover the entity member. The property `MemberInfoDiscovery` will be used to find the best option for members of each entity.\n\nThe discoverers of members must inherit from `IMemberInfoDiscovery` interface and the method `CanDiscovery` is responsible for determining if the entity may or may not have your Member discovered. When the method `CanDiscovery` returns `true` then the method `GetMemberInfo` is called to return the `MemberInfo` .\n\n```csharp\npublic interface IMemberInfoDiscovery\n{\n    bool CanDiscovery(Entity item);\n    MemberInfo GetMemberInfo(Entity item);\n}\n```\n\nBy default, we only have one class defined in: `MemberInfoDiscovery` .\n\n```csharp\nclass MemberInfoDiscovery : IMemberInfoDiscovery\n```\n\nIf you want to replace it, just add a new class in the property `MemberInfoDiscovery` .\n\nJust make sure that the method `CanDiscovery` has the following implementation:\n\n```csharp\npublic bool CanDiscovery(Entity item)\n{\n    return item.Factory.IsTyped\n            \u0026\u0026 item.Name != null\n            \u0026\u0026 !item.Name.StartsWith(Constants.INDEXER_START) // ignore [0] members\n            \u0026\u0026 item.Parent.Type != null;\n}\n```\n\nThis code ensures that:\n\n1. `item.Factory.IsTyped`: There is a type defined for the root entity. It is from her that we found all kinds of graph.\n2. `item.Name != null`: There is a name for the Member\n3. `!item.Name.StartsWith(Constants.INDEXER_START)`: The name of the Member cannot be a positional representation of collections, that is, cannot start with `[` .\n4. `item.Parent.Type != null`: There is a type for the parent entity. It is with this type and member name that we obtain the type of the Member.\n\n## \u003ca name=\"impl-factory-entity-complex-value-loaders\" /\u003eValue initializers\n\nThe \"values initializers\" aims to create the primitive and complex entities. The property `ValueLoader` will be used to find the best option for each entity. Understand the term \"value\" as being the entity that will be created.\n\nThe \"values initializers\" must inherit from `IValueLoader` interface and the method `CanLoad` is responsible for determining if the entity type may or may not be initialized. When the method `CanLoad` returns `true` then the method `GetValue` is called to get the value that will be the entity.\n\n```csharp\npublic interface IValueLoader\n{\n    bool CanLoad(Entity item);\n    object GetValue(Entity item);\n}\n```\n\nThe order of the \"initializer\" is of the utmost importance, since the last of the list will be used in the event of a tie, in other words, if three return `true` , the last on the list will be used.\n\nBy default, we have some \"initializers of values\" defined and all of them are already sorted on the property `ValueLoader` to prevent errors.\n\n1. `PrimitiveValueLoader`: Initializes the primitive types.\n2. `ComplexEntityValueLoader`: Initializes the complex types. If the type has a constructor that takes no parameters, then this constructor will be used, otherwise the instance will be created without calling the constructor, that is, using the `FormatterServices.GetUninitializedObject(typeof(T))` method. This initializer is only used when the property `ComplexEntityId` is populated, i.e. If the entity has ID is because she is complex.\n3. `ArrayValueLoader`: This initializer is used when the entity is an array. Independent of the number of dimensions.\n4. `ExpandoObjectValueLoader`: This initializer is used for anonymous types or `ExpandoObject` type.\n\n**Important:**\n\nThe `ExpandoObject` type will be used at all levels when the class `ComplexEntityFactory` does not have a defined type.\n\n## \u003ca name=\"impl-factory-entity-complex-child-assign\" /\u003eAssignment of children\n\nThe award is intended to add a child entity in your parent entity, i.e., assign a value in a parent instance member, or an item in a list for example. The property `SetChildAction` will be used to find the best option for each entity.\n\nA class that makes assignment of children must inherit from the `ISetChild` interface, and the method `CanSet` is responsible for determining whether the child item may or may not be attributed to the parent item. When the method `CanSet` returns `true` then the method `SetChild` will be called to do the assignment.\n\n```csharp\npublic interface ISetChild \n{\n    bool CanSet(Entity item, Entity child);\n    void SetChild(Entity item, Entity child);\n}\n```\n\nThe order is of extreme importance, once the last of the list will be used in the event of a tie, in other words, if three return `true` , the last on the list will be used.\n\nBy default, we have some classes of attribution set and all of them are already sorted on the property `SetChildAction` to prevent errors.\n\n1. `MemberInfoSetChild`: This class will be used when the child entity has a member set.\n2. `DictionarySetChild`: This class will be used when the parent entity is a dictionary and daughter have the member name started by the character `[` . This means that the child is an item and not a property of the parent entity.\n3. `ExpandoObjectSetChild`: This class is used when the parent entity is of type `ExpandoObject` .\n4. `ArraySetChild`: This class is used when the parent entity is of type `Array` and daughter have the member name started by the character `[` .\n5. `ListSetChild`: This class is used when the parent entity is of type `IList` and daughter have the member name started by the character `[` .\n\n# \u003ca name=\"impl-serialization\" /\u003eSerialization\n\nSerialization is the process of transformation of entity to text. We split the serialization into two kinds: **circular entity serialization** and **serialization of complex entities**.\n\nThat's interesting, because circular entities are simpler and require only a name to represent them, unlike complex entities that can contain several properties.\n\n## \u003ca name=\"impl-serialization-circular\" /\u003eCircular serialization\n\nSerialization of circular entities is made by `CircularEntityExpressionSerializer` class.\n\nThis class inherits from the abstract class `ExpressionSerializerBase\u003cT\u003e` which has the responsibility to write the mathematical basis of a graph. This is done by the method `Serialize()` . He is responsible for creating the parentheses, add \"+\" characters among other things.\n\nThe class `CircularEntityExpressionSerializer` overrides the method `SerializeItem` that is responsible for serializing each item of expression.\n\nThe constructor requires two parameters:\n\n```csharp\nCircularEntityExpressionSerializer(Expression\u003cT\u003e expression, Func\u003cT, object\u003e entityNameCallback)\n```\n\n1. `expression`: Indicates which will be a circular expression that should be serialized.\n2. `entityNameCallback`: Indicates which is the text used in each item of expression. If it is passed `null` then the method `ToString()` of each `EntityItem` will be used.\n\nIn the example below we will see a way to serialize a circular expression\n\n```csharp\npublic void SerializationCircular1()\n{\n    // create a simple object\n    var A = new CircularEntity(\"A\");\n    var B = new CircularEntity(\"B\");\n    var C = new CircularEntity(\"C\");\n    var D = new CircularEntity(\"D\");\n\n    A = A + B + (C + D);\n\n    var expression = A.AsExpression(c =\u003e c.Children);\n    var serialization = new CircularEntityExpressionSerializer\u003cCircularEntity\u003e(expression, f =\u003e f.Name);\n    var expressionAsString = serialization.Serialize();\n    System.Console.WriteLine(expressionAsString);\n}\n```\n\nThe output is a circular expression whose name of each item will be the property `Name` of the class `CircularEntity` :\n\n```\nA + B + (C + D)\n```\n\nSome properties of customizations can be used before the serialization. All these properties are in the base class, that is, they apply to complex expressions too.\n\n* `bool EncloseParenthesisInRoot`: This property determines if there is a root entity encompassing parentheses, the default is to not exist.\n* `bool ForceQuoteEvenWhenValidIdentified`: This property forces the use of quotation marks even when the name of the entity is a valid name. A valid name cannot contain spaces or special characters that the language `C#` does not support in variable names. Names that reference terms reserved the `C#` are also considered invalid, for example: `bool` , `while` and etc. If a name is invalid then the use of quotation marks will be used, if a name is valid then the use of quotation marks will depend on the value of this property.\n  * `true`: Forces the use of quotation marks even for valid names\n  * `false`: Displays the quotes only for invalid names. This is the default value of this property.\n* `IValueFormatter ValueFormatter`: This property indicates what will be the value formatter for each item of expression, by default we only have two, but is it possible to create a custom formatter using the interface `IValueFormatter` .\n  * `DefaultValueFormatter`: This formatter is used as the default for any primitive type.\n    * The types of \"date\" will have the following format:`yyyy-MM-ddTHH:mm:ss.fffzzz`\n    * For Boolean types the default will be`true|false`\n    * Other types will be converted to text using the culture: `CultureInfo.InvariantCulture` .\n  * `TruncateFormatter`: This formatter can be used when the name of the entity is too large and need to truncate it. This means that many big names will be reduced according to the specified size. This formatter can only be applied to types of texts ( `string` ).\n\nIn the following example we will force the use of parentheses in the root item, forcing the use of quotation marks for valid names and also truncate names that pass of 3 characters:\n\n```csharp\npublic void SerializationCircular2()\n{\n    // create a simple object\n    var A = new CircularEntity(\"A\");\n    var B = new CircularEntity(\"B\");\n    var C = new CircularEntity(\"C\");\n    var D = new CircularEntity(\"BigName\");\n\n    A = A + B + (C + D);\n\n    var expression = A.AsExpression(c =\u003e c.Children);\n    var serialization = new CircularEntityExpressionSerializer\u003cCircularEntity\u003e(expression, f =\u003e f.Name);\n    serialization.EncloseParenthesisInRoot = true;\n    serialization.ForceQuoteEvenWhenValidIdentified = true;\n    serialization.ValueFormatter = new TruncateFormatter(3);\n\n    var expressionAsString = serialization.Serialize();\n    System.Console.WriteLine(expressionAsString);\n}\n```\n\nThe output below shows how was our customization, note that the name `BigName` was truncated, all items now have quotation marks and there is a parentheses including the root item.\n\n```\n(\"A\" + \"B\" + (\"C\" + \"Big\"))\n```\n\nFinally, we highlight that when an expression is created using the method `AsExpression(c =\u003e c.Children)` , we will have on `DefaultSerialize` property a pre-configured instance of class: `CircularEntityExpressionSerializer\u003cT\u003e` .\n\nHowever, this property returns the type of interface: `ISerialize\u003cT\u003e` . Therefore, you must cast to the circular or serializer using the method below that will do the conversion for you:\n\n```csharp\nexpression.GetSerializer\u003cCircularEntityExpressionSerializer\u003cCircularEntity\u003e\u003e();\n```\n\n## \u003ca name=\"impl-serialization-complex\" /\u003eComplex Serialization\n\nSerialization of complex entities is made by the class `ComplexEntityExpressionSerializer` . This class must abide by the rules that we have seen in the topics [Complex entities in text form-primitive types](https://github.com/juniorgasparotto/GraphExpression#impl-factory-entity-complex-primitive), [Complex entities in text-form complex types](https://github.com/juniorgasparotto/GraphExpression#impl-factory-entity-complex-complex) and [Complex entities in text form-Collections and arrays](https://github.com/juniorgasparotto/GraphExpression#impl-factory-entity-complex-collections).\n\nThis class inherits from the abstract class `ExpressionSerializerBase\u003cobject\u003e` which has the responsibility to write the mathematical basis of a graph expression either circular or complex. This is done by the method `Serialize()` . He is responsible for creating the parentheses, adding the characters of sum and etc.\n\nThe class `ComplexEntityExpressionSerializer` overrides the method `SerializeItem` that is responsible for serializing each item of expression.\n\nThe constructor requires to be passed an instance of an expression.\n\n```csharp\nComplexEntityExpressionSerializer(Expression\u003cobject\u003e expression)\n```\n\n1. `expression`: Indicates which is the complex expression that should be serialized.\n\nIn the example below we will see a way to serialize a complex expression:\n\n```csharp\npublic void SerializationComplex1()\n{\n    // create a simple object\n    var model = new\n    {\n        A = \"A\",\n        B = \"B\",\n        C = \"C\",\n        D = \"D\",\n        E = \"E\",\n    };\n\n    var expression = model.AsExpression();\n    var serialization = new ComplexEntityExpressionSerializer(expression);\n    var expressionAsString = serialization.Serialize();\n    System.Console.WriteLine(expressionAsString);\n}\n```\n\nThe output is a complex expression containing all properties with their respective values of anonymous entity:\n\n```\n\"\u003c\u003ef__AnonymousType0`5.845912156\" + \"A: A\" + \"B: B\" + \"C: C\" + \"D: D\" + \"E: E\"\n```\n\nSome properties of customizations can be used before the serialization:\n\n* `bool EncloseParenthesisInRoot`: Has the same function of the circular expressions.\n* `bool ForceQuoteEvenWhenValidIdentified`: Has the same function of the circular expressions.\n* `IValueFormatter ValueFormatter`: Has the same function of the circular expressions.\n* `GetEntityIdCallback`: Property that returns the ID of an entity, by default, use the method `GetHashCode()` .\n* `ItemsSerialize`: Property that contains a list of the interface `IEntitySerialize` . This property is the main alternative to customize the serialization and see that in the next topics.\n* `ShowType`: Determines how will be the display of type in each item of expression\n  * `None`: Does not display the type for any item.\n  * `TypeNameOnlyInRoot`: Displays the name of the type (in short form) for the root item.\n  * `TypeName`: Displays the name of the type (in short form) for all items.\n  * `FullTypeName`: Displays the full name of the type for all items in the expression.\n\nIn the following example we will force the use of parentheses in the root item, force the display type in all items of the expression and also truncate values that pass of 3 characters:\n\n```csharp\npublic void SerializationComplex2()\n{\n    // create a simple object\n    var model = new\n    {\n        A = \"A\",\n        B = \"B\",\n        C = \"C\",\n        D = \"D\",\n        E = \"BIG VALUE\",\n    };\n\n    var expression = model.AsExpression();\n    var serialization = new ComplexEntityExpressionSerializer(expression);\n    serialization.EncloseParenthesisInRoot = true;\n    serialization.ValueFormatter = new TruncateFormatter(3);\n    serialization.ShowType = ShowTypeOptions.TypeName;\n    var expressionAsString = serialization.Serialize();\n    System.Console.WriteLine(expressionAsString);\n}\n```\n\nThe output below shows how was our customization, note that the value of the `E` property has been truncated and is there a parentheses including the root item. In addition, all items are displaying the name of the type in short form:\n\n```\n(\"\u003c\u003ef__AnonymousType0`5.-438126044\" + \"String.A: A\" + \"String.B: B\" + \"String.C: C\" + \"String.D: D\" + \"String.E: BIG\")\n```\n\nFinally, we highlight that when an expression is created using the method `AsExpression()` , we will have on `DefaultSerialize` property a pre-configured instance of class: `ComplexEntityExpressionSerializer\u003cT\u003e` .\n\n### \u003ca name=\"impl-serialization-complex-itens-serialize\" /\u003eCustomizing the serialization of the items\n\nThe serialization items are responsible for the serialization of the member name and obtaining the item type in the expression. The returned type will be used by the class `ValueFormatter` when it is primitive. For complex types will be the display of identification as we saw in the topic [Complex entities in text-form complex types](https://github.com/juniorgasparotto/GraphExpression#impl-factory-entity-complex-complex).\n\nThe property `ItemsSerialize` will be used to find the best serializer for each item of expression.\n\nThe serialization items must inherit from `IEntitySerialize` interface and the method `CanSerialize` is responsible for determining if the item of expression may or may not be serialized. When the method `CanSerialize` returns `true` then the method `GetSerializeInfo` is called to obtain the serialization information for the item.\n\n```csharp\npublic interface IEntitySerialize\n{\n    bool CanSerialize(ComplexEntityExpressionSerializer serializer, EntityItem\u003cobject\u003e item);\n    (Type Type, string ContainerName) GetSerializeInfo(ComplexEntityExpressionSerializer serializer, EntityItem\u003cobject\u003e item);\n}\n```\n\nThe order of serialization items is of the utmost importance, since the last of the list will be used in the event of a tie, in other words, if three return `true` , the last on the list will be used.\n\nBy default, we have some serializers are defined and all of them are already sorted on the property `ItemsSerialize` to prevent errors.\n\n1. `ObjectSerialize`: Is the default serialization class, if no other is found, this will be used. It returns the entity type and the value `null` for the property `ContainerName` .\n2. `PropertySerialize`: This class is used for items that derive from the properties. The type of the property and your name will be used.\n3. `FieldSerialize`: This class is used for items that are derived from the fields. The type of the field and your name will be used.\n4. `ArrayItemSerialize`: This class is used for items that derive from `array` . She returns in `ContainerName` the position property of the item in the form:`[{position1},{position2}]`\n5. `DynamicItemSerialize`: This class is used for items that derive from dynamic classes.\n6. `CollectionItemSerialize`: This class is used for items that derive from Collections. She returns in `ContainerName` the position property in the format:`[{position1},{position2}]`\n\nIn the following example we will see the creation of a new member named reader `MethodReader` that will be responsible for reading the method `HelloWorld` and create a new entity type in the expression called `MethodEntity` . Based on this new type of entity we create a serializer called `MethodSerialize` which will have the function to serialize the new type to the following format:\n\n```\nMethodName(parameters)\n```\n\n```csharp\npublic void SerializationComplex3()\n{\n    var factory = new ComplexExpressionFactory();\n    factory.MemberReaders.Add(new MethodReader());\n\n    var model = new Model();\n    var expression = model.AsExpression(factory);\n    var serialization = expression.GetSerializer\u003cComplexEntityExpressionSerializer\u003e();\n    serialization.ItemsSerialize.Add(new MethodSerialize());\n    System.Console.WriteLine(serialization.Serialize());\n}\n\nprivate class Model\n{\n    public string HelloWorld(string val1, string val2)\n    {\n        return $\"{val1}-{val2}\";\n    }\n}\n\npublic class MethodReader : IMemberReader\n{\n    public IEnumerable\u003cComplexEntity\u003e GetMembers(ComplexExpressionFactory factory, GraphExpression.Expression\u003cobject\u003e expression, object entity)\n    {\n        if (entity is Model)\n        {\n            var method = entity\n                .GetType()\n                .GetMethods().Where(f =\u003e f.Name == \"HelloWorld\")\n                .First();\n\n            var parameters = new object[] { \"value1\", \"value2\" };\n            var methodValue = method.Invoke(entity, parameters);\n            yield return new MethodEntity(expression, method, parameters, methodValue);\n        }\n    }\n}\n\npublic class MethodSerialize : IEntitySerialize\n{\n    public bool CanSerialize(ComplexEntityExpressionSerializer serializer, EntityItem\u003cobject\u003e item)\n    {\n        return item is MethodEntity;\n    }\n\n    public (Type Type, string ContainerName) GetSerializeInfo(ComplexEntityExpressionSerializer serializer, EntityItem\u003cobject\u003e item)\n    {\n        var cast = (MethodEntity)item;\n        return (\n            item.Entity?.GetType(),\n            $\"{cast.MethodInfo.Name}({string.Join(\",\", cast.Parameters)})\"\n        );\n    }\n}\n\nprivate class MethodEntity : ComplexEntity\n{\n    public MethodInfo MethodInfo { get; }\n    public object[] Parameters { get; }\n\n    public MethodEntity(Expression\u003cobject\u003e expression, MethodInfo methodInfo, object[] parameters, object value)\n        : base(expression)\n    {\n        this.MethodInfo = methodInfo;\n        this.Parameters = parameters;\n        this.Entity = value;\n    }\n}\n```\n\nThe output shows that the new methods serializer displayed the name of the method in the expected format and also the values of the parameters inside the parentheses.\n\n```\n\"Model.43942917\" + \"HelloWorld(value1,value2): value1-value2\"\n```\n\n# \u003ca name=\"impl-deserialization\" /\u003eDeserialization\n\nDeserialization is the process of transformation of a text to a specified entity. We split it up deserialization into two types: **deserialization circular entity** and **deserialization of complex entities**.\n\nThe deserialization process uses as a base the compiler `Roslyn` . This has pros and cons.\n\nThe good part is that we don't have to reimplement the reading of mathematical expressions, because with the Roslyn is possible convert `string` , which is a mathematical expression, in a `SystaxTree` and do the build for a mathematical expression.\n\nThe class `RoslynExpressionDeserializer\u003cT\u003e` is responsible for making the `string` conversion to a mathematical expression.\n\nThe inferred type `T` must contain an `+` operator overload.\n\nThe downside of this approach is that there is a slowness in this process in your first run. For now, we don't have a solution to this problem, but we are following the evolution of the compiler Roslyn.\n\n## \u003ca name=\"impl-deserialization-circular\" /\u003eDeserialization circular\n\nDeserialization of circular entities is made by the class `CircularEntityExpressionDeserializer\u003cT\u003e` . The method `Deserialize` is responsible for deserializing. There are a few variations of this method:\n\nThe inferred type `T` must contain an `+` operator overload, because that is the operator that the logic of the sum or subtraction will be contained.\n\n**1)** the first method requires only the expression in text form. Based on this expression and the inferred type in `CircularEntityExpressionDeserializer` class it is possible to make deserialization. There are two variants of this method, a synchronous and another asynchronously.\n\nThe inferred type must have (necessarily) a parameter in your constructor of type: `string` . This parameter is the name of the entity.\n\n```csharp\npublic T Deserialize(string expression);\npublic async Task\u003cT\u003e DeserializeAsync(string expression);\n```\n\nIn the following example we will see how simple deserialization of circular entities:\n\n```csharp\npublic void DeserializationCircular1()\n{\n    var expressionAsString = \"A + B + (C + D)\";\n\n    var serializer = new CircularEntityExpressionDeserializer\u003cCircularEntity\u003e();\n    var A = serializer.Deserialize(expressionAsString);\n\n    // A\n    System.Console.WriteLine(A.Name);\n\n    // B\n    System.Console.WriteLine(A.Children[0].Name);\n\n    // C\n    System.Console.WriteLine(A.Children[1].Name);\n\n    // C - children \n    System.Console.WriteLine(A.Children[1].Children[0].Name);\n}\n\npublic class CircularEntity\n{\n    public string Name { get; private set; }\n    public CircularEntity(string identity) \n    { \n        this.Name = identity;\n    }\n\n    ... continue\n}\n```\n\nThe output of this example shows that all levels have been created and populated with the name used in the expression. Note that the class `CircularEntity` contains a parameter `string` type. This is necessary so that these methods work:\n\n```\nA\nB\nC\nD\n```\n\n**2)** the second overload requires the expression and a method that is the \"circular entity factory\", that is, with this overload to your circular class does not need to be forced to have a constructor with a parameter, since the creation of the class will be made in this method. There are two variants of this method, a synchronous and another asynchronously.\n\n```csharp\npublic T Deserialize(string expression, Func\u003cstring, T\u003e createEntityCallback);\npublic async Task\u003cT\u003e DeserializeAsync(string expression, Func\u003cstring, T\u003e createEntityCallback);\n```\n\n**3)** the third overload of this method requires the expression and an instance of the class `CircularEntityFactory\u003cT\u003e` . This class allows custom functions are used in the expression in text form. There are two variants of this method, a synchronous and another asynchronously.\n\n```csharp\npublic T Deserialize(string expression, CircularEntityFactory\u003cT\u003e factory);\npublic async Task\u003cT\u003e DeserializeAsync(string expression, CircularEntityFactory\u003cT\u003e factory);\n```\n\nIn the following example we will show how to use custom functions in the expression. We will create a class `CircularEntityFactoryExtend` that inherits from the call `CircularEntityFactory\u003cCircularEntity\u003e` . In this class we will create the `NewEntity(string name)` method that will be used in the expression in text form.\n\n```csharp\npublic void DeserializationCircular2()\n{\n    var strExp = \"NewEntity('my entity name1') + NewEntity('my entity name2')\";\n    var factory = new CircularEntityFactoryExtend();\n    var serializer = new CircularEntityExpressionDeserializer\u003cCircularEntity\u003e();\n    var root = serializer.Deserialize(strExp, factory);\n    var entities = factory.Entities.Values.ToList();\n\n    System.Console.WriteLine(root.Name);\n    System.Console.WriteLine(root.Children[0].Name);\n}\n\npublic class CircularEntityFactoryExtend : CircularEntityFactory\u003cCircularEntity\u003e\n{\n    public CircularEntity NewEntity(string name)\n    {\n        return new CircularEntity(name);\n    }\n}\n```\n\nThe output is the name of the circular entities that have been created:\n\n```\nmy entity name1\nmy entity name2\n```\n\n## \u003ca name=\"impl-deserialization-complex\" /\u003eDeserialization complex\n\nDeserialization of complex entities is made by the class `ComplexEntityExpressionDeserializer` . The method `Deserialize` is responsible for deserializing. There are a few variations of this method:\n\n**1)** the first method requires only the expression in text form. Based on this expression and the inferred type in the method `Deserialize` it is possible to make deserialization. There are two variants of this method, a synchronous and another asynchronously.\n\n```csharp\npublic T Deserialize\u003cT\u003e(string expression);\npublic async Task\u003cT\u003e DeserializeAsync\u003cT\u003e(string expression);\n```\n\nIn the example below we will deserialize an expression to an array of integers. Note that the `int[]` type is being inferred in the method `Deserialize\u003cint[]\u003e` .\n\n```csharp\npublic void DeserializationComplex1()\n{\n    var expressionAsString = \"\\\"Int32[].1\\\" + \\\"[0]: 1\\\" + \\\"[1]: 2\\\" + \\\"[2]: 3\\\"\";\n    var deserializer = new ComplexEntityExpressionDeserializer();\n    var array = deserializer.Deserialize\u003cint[]\u003e(expressionAsString);\n    System.Console.WriteLine(array[0]);\n    System.Console.WriteLine(array[1]);\n    System.Console.WriteLine(array[2]);\n}\n```\n\n**2)** the second method has the same purpose of the first method, the only difference is that the guy won't be inferred in the method and the `type` parameter:\n\n```csharp\npublic object Deserialize(string expression, Type type = null);\npublic async Task\u003cobject\u003e DeserializeAsync(string expression, Type type = null);\n```\n\n**3)** the third method receives the parameter `factory` , this parameter should be used if you need some customization in the creation of complex entities. In short, this process is exactly the same as the process of the topic [Creating complex entities with graph and mathematical expression](https://github.com/juniorgasparotto/GraphExpression#impl-factory-entity-complex). Internally, the compiler will transform each item of expression in the class `Entity` and then follow the same steps that we've seen in this topic:\n\n```csharp\npublic T Deserialize\u003cT\u003e(string expression, ComplexEntityFactory factory);\npublic async Task\u003cT\u003e DeserializeAsync\u003cT\u003e(string expression, ComplexEntityFactory factory);\n```\n\n**4)** This last has the same overload overload function above, the only difference is that we don't have an inferred type, that is, the type will be defined in the class `ComplexEntityFactory` or if he has not, the result will be a class `ExpandObject` -type:\n\n```csharp\npublic object Deserialize(string expression, ComplexEntityFactory factory);\npublic async Task\u003cobject\u003e DeserializeAsync(string expression, ComplexEntityFactory factory);\n```\n\n# \u003ca name=\"impl-graph-info\" /\u003eInformation from the graph of an entity\n\nClasses: `Expression\u003cT\u003e` and `EntityItem\u003cT\u003e` bring some information of graph theory to help understand a little the relationship between the entities.\n\n**1)** `Expression\u003cT\u003e` : Contains the property `Graph` that isolates the General information of the graph, it contains the following properties and definitions:\n\n* `IReadOnlyList\u003cEdge\u003cT\u003e\u003e Edges`: This property contains all the edges of the graph.\n  * `class Edge\u003cT\u003e`: This class represents a connection between two entities (A and B), we have some properties and a method that help extract some information.\n    * `decimal Weight`: Determines the weight of the edge, if necessary, do the padding after the creation of the expression.\n    * `EntityItem\u003cT\u003e Source`: Determines the parent item of the edge\n    * `EntityItem\u003cT\u003e Target`: Determines the child item of the edge\n    * `IsLoop`: Determines if the `Source` equals `Target` , if yes, this edge is in looping.\n    * `bool IsAntiparallel(Edge\u003cT\u003e compare)`: Determines if two edges are antiparallel, meaning if an edge compared to the other has the same entities, however, in reverse order:\n      * `A -\u003e B`\n      * `B -\u003e A`\n* `IReadOnlyList\u003cVertex\u003cT\u003e\u003e Vertexes`: Contains the list of all entities of the graph\n  * `class Vertex\u003cT\u003e`: Represents a vertex, i.e. an entity\n    * `long Id`: This ID is generated automatically using the static class `VertexContainer` .\n    * `T Entity`: Represents the entity of the vertex.\n    * `int CountVisited`: Determines how many times the vertex was used in the graph.\n    * `IReadOnlyList\u003cEntityItem\u003cT\u003e\u003e Parents`: Lists all parents of a vertex in the graph.\n    * `IReadOnlyList\u003cEntityItem\u003cT\u003e\u003e Children`: Lists all the children of the entity.\n    * `int Indegrees`: Determines the indegree (number of parents)\n    * `int Outdegrees`: Determines the outdegree (number of children)\n    * `int Degrees`: Determines the degree of the vertex (sum of indegree with outdegree)\n    * `bool IsSink`: Checks if the vertex is a leaf, i.e. does not contain children.\n    * `bool IsSource`: Checks if the vertex is the root of the graph.\n    * `bool IsIsolated`: Checks if the vertex does not contain father and no children, that is, it is a root item.\n* `IReadOnlyList\u003cPath\u003cT\u003e\u003e Paths`: Contains a list of all the paths end of graph\n  * `class Path\u003cT\u003e`: Represents a path that starts at the root and goes up to the vertex.\n    * `IEnumerable\u003cEntityItem\u003cT\u003e\u003e Items`: Lists all the items in the path that begins at the root to the vertex.\n    * `string Identity`: This is the identification of the way, this ID uses the `Id` of each vertex and use the following pattern:\n      * Format:`[id-root].[id-parent].[id-instance]`\n      * Example:`[0].[1].[2]`\n    * `PathType PathType`: Determines the type of the path\n      * `Circuit`: Occurs when the root vertex is equal to the current vertex.\n      * `Circle`: Occurs when the parent vertex is equal to the current vertex.\n      * `Simple`: Is default type, i.e. when it is not and not circular circuit\n    * `bool ContainsPath(Path\u003cT\u003e pathTest)`: Checks whether a path exists within the path of the instance. Basically, this method makes a comparison at the property `Identity` of the two paths, i.e. If a path contain the ID of the other path is because this path is contained in another. Example:\n      * `Path 1`:`[0].[1].[2].[3]`\n      * `Path 2`:`[2].[3]`\n      * Using text comparison, we see that the second path is contained in the first path:\n        * `\"[0].[1].[2].[3]\".Constains(\"[2].[3]\") = true`\n\n**2)** `EntityItem\u003cT\u003e` : Contains the following properties:\n\n* `Vertex\u003cT\u003e Vertex`: Represents the apex of the item of expression.\n* `Edge\u003cT\u003e Edge`: Represents the edge of the item of expression.\n* `Path\u003cT\u003e Path`: Represents the path of the item in the item of expression.\n\nIn the example below we display the main information of the graph. We're not going to show all the information, since many are self explanatory:\n\n```csharp\npublic void GraphInfo()\n{\n    var A = new CircularEntity(\"A\");\n    var B = new CircularEntity(\"B\");\n    var C = new CircularEntity(\"C\");\n    var D = new CircularEntity(\"D\");\n\n    A = A + B + (C + D);\n    var expressionA = A.AsExpression(f =\u003e f.Children, e =\u003e e.Name);\n\n    foreach (Edge\u003cCircularEntity\u003e edge in expressionA.Graph.Edges)\n        System.Console.WriteLine(edge.ToString());\n\n    foreach (Path\u003cCircularEntity\u003e path in expressionA.Graph.Paths)\n        System.Console.WriteLine(path.ToString());\n\n    foreach (EntityItem\u003cCircularEntity\u003e item in expressionA)\n        System.Console.WriteLine($\"{item.ToString()} =\u003e {item.Path}\");\n}\n```\n\nThe first exit we can see all the edges of the graph, note that the first (root) contains no Dad:\n\n```\n , A\nA, B\nA, C\nC, D\n```\n\nThe second output, we see all the paths end of graph, i.e. from root to ends:\n\n```\n[A].[B]\n[A].[C].[D]\n```\n\nAt the third exit, we see all the paths of all items:\n\n```\nA =\u003e [A]\nB =\u003e [A].[B]\nC =\u003e [A].[C]\nD =\u003e [A].[C].[D]\n```\n\n## Removing duplicate graphs\n\nThe method `IEnumerable\u003cGraph\u003cT\u003e\u003e.RemoveCoexistents` aims to remove graphs that are contained within another graph.\n\nIn the example below we have graphs `A` and `C` . The `C` graph is contained in the graph `A` and we will use this method to remove the smaller graph, in case the `C` graph.\n\n```csharp\npublic void GraphRemoveCoexistents()\n{\n    var A = new CircularEntity(\"A\");\n    var B = new CircularEntity(\"B\");\n    var C = new CircularEntity(\"C\");\n    var D = new CircularEntity(\"D\");\n\n    A = A + B + (C + D);\n\n    var graphs = new List\u003cGraph\u003cCircularEntity\u003e\u003e\n    {\n        A.AsExpression(f=\u003ef.Children, e =\u003e e.Name).Graph,\n        C.AsExpression(f=\u003ef.Children, e =\u003e e.Name).Graph\n    };\n\n    System.Console.WriteLine($\"-\u003e A: HashCode: {graphs[0].GetHashCode()}\");\n    foreach (Path\u003cCircularEntity\u003e path in graphs[0].Paths)\n        System.Console.WriteLine(path.ToString());\n\n    System.Console.WriteLine($\"-\u003e B: HashCode: {graphs[1].GetHashCode()}\");\n    foreach (Path\u003cCircularEntity\u003e path in graphs[1].Paths)\n        System.Console.WriteLine(path.ToString());\n\n    var graphsNonDuplicates = graphs.RemoveCoexistents();\n    foreach(var graph in graphsNonDuplicates)\n    {\n        System.Console.WriteLine($\"-\u003e A: HashCode: {graph.GetHashCode()}\");\n        foreach (Path\u003cCircularEntity\u003e path in graph.Paths)\n            System.Console.WriteLine(path.ToString());\n    }\n}\n```\n\nThe first exit, we see the `A` graph:\n\n```\n-\u003e A: HashCode: 32854180\n[A].[B]\n[A].[C].[D]\n```\n\nThe second output, see the `B` graph:\n\n```\n-\u003e B: HashCode: 27252167\n[C].[D]\n\n```\n\nThe third output shows which graph were maintained after removal of coexistence. As the `A` graph contained the `C` graph, then only the `A` graph was maintained.\n\n```\n-\u003e HashCode not duplicates: 32854180\n```\n\nIn addition, we still have the method `IEnumerable\u003cPath\u003cT\u003e\u003e.RemoveCoexistents()` that has the same purpose, however, it removes the repeated paths in a collection of paths:\n\n```csharp\nIEnumerable\u003cPath\u003cT\u003e\u003e RemoveCoexistents\u003cT\u003e(this IEnumerable\u003cPath\u003cT\u003e\u003e source)\n```\n\n## Container of vertices\n\nThe class `VertexContainer\u003cT\u003e` contains a `static ConcurrentBag\u003cEntityId\u003e Vertexes` property that is responsible for storing all the vertices of the application.\n\nKeep a static property is not the best practice, but it's the only way to make all vertices in different `Expression\u003cobject\u003e` instances have the same ID. Without it you cannot use extension methods:\n\n```csharp\nIEnumerable\u003cGraph\u003cT\u003e\u003e RemoveCoexistents\u003cT\u003e(this IEnumerable\u003cGraph\u003cT\u003e\u003e source);\nstatic IEnumerable\u003cPath\u003cT\u003e\u003e RemoveCoexistents\u003cT\u003e(this IEnumerable\u003cPath\u003cT\u003e\u003e source);\n```\n\nI plan in the future to remove this static property and exchange it for an instance injected. This will reduce the power of the functionality, but leaves the instances under control.\n\n## Disabling the graph information\n\nThe property `GraphExpression.Expression\u003cT\u003e.EnableGraphInfo` determines whether the graph information collection is enabled. By default it is on, but performance issues, you can disable it.\n\nRecalling that by doing this, all the information of the graphs will be nil.\n\n# \u003ca name=\"donate\" /\u003eDonations\n\nGraphExpression is an open source project. Starting in 2017, many hours have been invested in the creation and evolution of this project.\n\nIf the GraphExpression was useful for you, or if you want to see it evolve increasingly, consider making a small donation (any amount). Help us also with suggestions and possible problems.\n\nAnyway, we thank you for have come up here;)\n\n**Bitcoin:**\n\n_19DmxWBNcaUGjm2PQAuMBD4Y8ZbrGyMLzK_\n\n![bitcoinkey](https://github.com/juniorgasparotto/GraphExpression/blob/master/doc/img/bitcoinkey.png)\n\n# \u003ca name=\"license\" /\u003eLicense\n\nThe MIT License (MIT)\n\nCopyright (c) 2018 Glauber Donizeti Gasparotto Junior\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associate","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjuniorgasparotto%2Fgraphexpression","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjuniorgasparotto%2Fgraphexpression","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjuniorgasparotto%2Fgraphexpression/lists"}