Partial objects #4853
Unanswered
ssougnez
asked this question in
Language Ideas
Partial objects
#4853
Replies: 1 comment 8 replies
-
IMO sounds like a good use case for an analyzer. |
Beta Was this translation helpful? Give feedback.
8 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hello,
first of all, sorry if this has already been proposed (I did a search and didn't find anything) or if it already exists in C#.
Use case
I'm using the NEST NuGet to interact with ElasticSearch. It exists a "Bulk" method used to update several documents in one go. The class used to represent a document in ES is the following:
As you can see, there are "a lot of" properties and I have some use cases where I only want to update one of them for several documents. For example, if I delete a process, I'll have to update the "Processes" properties of each impacted document. There are two solutions for this. Either I fetch all the document properties and I execute the bulk request with all the properties or I used an anonymous object to only update the process, something like :
And it works very well. However, the issue here is that, as I'm using an anonymous object, I can define whatever property names I want but it also includes typos. So I could have typed "Proceses" instead of "Processes" and the compiler wouldn't have complained about that. Or worse, maybe I have to renamed the "Document" class property "Processes" in "Procedures". In this case, I might miss the fact that I also have to change it in the anonymous object.
Proposal
Therefore, I thought that it would be pretty handy to be able to do something like this:
In this case, the fact that I'm using a partial "Document", the intellisense and the compiler would know the list of properties that I can define. However, at the end, it would generate an anonymous object with only these two properties because it simply created a "Document" object, all the properties that I didn't defined would be set to their default value and updated in Elastic Search, which I don't want.
Conclusion
In conclusion, I'd say that it could come pretty handy in specific situation to be able to define an anonymous objects that are a partial representation of an existing class.
Beta Was this translation helpful? Give feedback.
All reactions