Create valid property identifiers when generating OData client#333
Conversation
280d032 to
108d251
Compare
SomeTroglodyte
left a comment
There was a problem hiding this comment.
Simple - this can't be any worse than the current master.
|
@microsoft-github-policy-service agree |
|
When using the ODataConnectedService extension in Visual Studio 2022 to generate C# classes from an unpatched Dynamics 365 10.0.29 OData ($metadata) url, @gregwinterstein 's fix has generated code that compiles correctly. Note: by unpatched I mean that our Dynamics 365 has no hotfix for LCS 753226, nor it can be applied - if you have 10.0.30 or 10.0.31 you can apply it, while 10.0.32+ is supposed to incorporate the fix. |
I'd like to test with non-dynamics sources but am too lazy to compile from source - care to share a build? |
108d251 to
0d3e015
Compare
bfcc9b4 to
8a64678
Compare
|
Took me a while, but I have just now built @gregwinterstein 's "all-fixes" branch from source and I can confirm it generates a working connected service where the current public version fails miserably. A source feed with dashes in field names no longer lets the compiler stumble over all the invalid subtractions... Sample excerpt /// <summary>
/// There are no comments for Property _SMC_K in the schema.
/// </summary>
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "#VersionNumber#")]
[global::Microsoft.OData.Client.OriginalNameAttribute("_SMC-K")]
public virtual string _SMC_K
{
get
{
return this.__SMC_K;
}
set
{
this.On_SMC_KChanging(value);
this.__SMC_K = value;
this.On_SMC_KChanged();
this.OnPropertyChanged("_SMC-K");
}
}
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "#VersionNumber#")]
private string __SMC_K;
partial void On_SMC_KChanging(string value);
partial void On_SMC_KChanged();👍 👍 👍 |
SomeTroglodyte
left a comment
There was a problem hiding this comment.
Tested and found working perfectly
|
My team really needs these changes. Can we please get them reviewed soon? Please and thank you! @ElizabethOkerio @KenitoInc @habbes @gathogojr |
8a64678 to
6512781
Compare
|
@gathogojr you had some thoughts around this issue. Could you check this PR? |
| { | ||
| string propertyType; | ||
| string propertyName = this.context.EnableNamingAlias ? Customization.CustomizeNaming(property.Name) : property.Name; | ||
| string propertyName = IdentifierMappings.ContainsKey(property.Name) ? |
There was a problem hiding this comment.
Use Dictionary<TKey,TValue>.TryGetValue(TKey, TValue) method instead of ContainsKey method + Dictionary<TKey,TValue>.Item[TKey] property. TryGetValue should be more efficient and cleaner
|
Thank you @gregwinterstein for your contribution. However, it might also not be a breaking change since the proxy classes that are generated in such a scenario do not compile meaning the affected customers are likely to be manually editing the proxy classes to mitigate the issue. |
I confirm: Regenerating is the most frequent use for me. Without this PR, each run requires 1-2 minutes of manual edits afterwards, per feed. This saves time especially then regenerating. |
@gathogojr, it has occurred to me that this pull request may cause some breaking changes because of the way valid identifiers are generated vs the way they were generated previously. I don't have a good solution for that. My main issue is that I am unable to generate proxies that compile for either Dynamics F&O or Dynamics CRM (this doesn't entirely resolve all of the CRM issues due to inconsistent casing in the CRM metadata). This change generates proxies that compile for Dynmaics F&O and gets a lot closer for Dynamics CRM. If backward compatibility is an issue, I'm open to suggestions. |
a869504 to
83cb640
Compare
Co-authored-by: Clément Habinshuti <haby_habbes@live.com>
Co-authored-by: Clément Habinshuti <haby_habbes@live.com>
Co-authored-by: Clément Habinshuti <haby_habbes@live.com>
Co-authored-by: Clément Habinshuti <haby_habbes@live.com>
Co-authored-by: Clément Habinshuti <haby_habbes@live.com>
…ild" This reverts commit 27cc60b.
83c6c69 to
590a8f5
Compare
|
Thank you @gregwinterstein for your contribution |
|
Edit: This is already available through VS marketplace in 1.1.0: I just got thrown off because that is not mirrored here on the releases page. |
Modify the code generator to generate valid identifiers
This change resolves the following issues: