Replies: 9 comments
-
I read your site and i don't undrestand your usecase. You mention, for example:
I don't see why that would be. If these properties are incompatible (because they have different sized values), then your code should not compile. So i don't see why you need an additional connector here. |
Beta Was this translation helpful? Give feedback.
-
Please provide more information on:
Thank you :) |
Beta Was this translation helpful? Give feedback.
-
If this is something that can be implemented by a library, then is almost certainly should be implemented by a library, especially for such niche concerns as this. Not to mention that there are non library ways to achieve the same level of type safety. |
Beta Was this translation helpful? Give feedback.
-
Goals/Benefits:
Proposed syntax:
Syntax with attribute instructions:
|
Beta Was this translation helpful? Give feedback.
-
@mnbeer I think example usage is not enough, you should explain how would the proposed feature actually work. |
Beta Was this translation helpful? Give feedback.
-
@mnbeer I've read your repo notes and I think I understand the problem you are trying to solve. Please correct me if I am wrong:
I had a project were I have a surface API, some business logic and a backend DB. I might then have Further more, mapping layers becomes an exercise in repetition leading to hundreds or thousands of To combat this monotony, developers look to use mappers and more specifically convention based mappers This proposal seems to target a specific class of these errors where models fall our of sync with each This proposal provides a way to link the definition of a property in one type, to a property in another type. //C# today
public class Person
{
public int PersonId { get; set; }
public List<Address> Addresses { get; set; }
// other properties here
}
public class Address
{
public int AddressId { get; set; }
public int PersonId { get; set; }
public string AddressType { get; set; }
// other properties here
}
...
public class PersonViewModel
{
public int PersonId { get; set; } //conceptually the same as Person.PersonId
public Address HomeAddress { get; set; }
// other properties here
} Now if a dev changes Obviously, if the codebase uses hand written mappings, you will get a type error. But the idea is that This appears to be the Tangl concept @mnbeer is talking about. They further suggest that Attributes It sounds like this can be accomplished with attributes and analyzers, and apparently is with the |
Beta Was this translation helpful? Give feedback.
-
@AlgorithmsAreCool - Your general descriptions of the issues introduced by overlapping class definitions and the benefits of the tangl concept are spot on. Thanks, and if you don't mind, I may incorporate some of your language in my documentation. I don't know that tangls snugly align with terms like "inherit" and "reference" so I avoid the terms to avoid confusion (thus the new term). As you say, "native support in the language syntax for this concept ... would reduce friction of adoption." In addition - and I think this is very important - native support can be marvelously concise, readable, and self-explanatory compared to the attribute option of my project (and compared to the existing state of disconnected classes that litter projects now). |
Beta Was this translation helpful? Give feedback.
-
The idea here is follow the precedent of automatic properties where "the compiler creates a private, anonymous backing field..." (https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/auto-implemented-properties). In the following sample (minus attributes to make the sample cleaner), the developer codes these classes ...
... and the compiler transforms CustomerSummaryModel into
|
Beta Was this translation helpful? Give feedback.
-
As this is not a full syntactic and semantic proposal, I'm converting it to a discussion. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
A tangl is a formal relationship between two otherwise unconnected things (classes, members, etc.). It fills gaps not handled by interfaces and inheritance, ensuring that - for example - common properties in related models have the same implementation. Tangls help manage model pollution (https://github.com/mnbeer/Tangl/wiki/Model-Pollution#what-is-model-pollution) and prevent runtime type mismatch errors (https://github.com/mnbeer/Tangl/wiki/Preventing-Errors#how-does-a-tangl-prevent-errors).
Code might look something like this:
Tangls can be implemented with attributes using my library here: https://github.com/mnbeer/Tangl (https://www.nuget.org/packages/TanglAnalyzer/). But this can get pretty wordy.
Tangl definition and examples here: https://github.com/mnbeer/Tangl#what-is-a-tangl
Beta Was this translation helpful? Give feedback.
All reactions