-
Notifications
You must be signed in to change notification settings - Fork 11
feat: Add property support to shapes and migrate ChangeRequest #491
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
5b4b5b1
7707778
65e31b3
d75e144
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -21,7 +21,7 @@ namespace OSLC4Net.Core.Attribute; | |||||||
| /// <summary> | ||||||||
| /// OSLC ValueType attribue | ||||||||
| /// </summary> | ||||||||
| [AttributeUsage(AttributeTargets.Method | AttributeTargets.Property) | ||||||||
| [AttributeUsage(AttributeTargets.Method | AttributeTargets.Property) | ||||||||
| ] | ||||||||
|
Comment on lines
+24
to
25
|
||||||||
| [AttributeUsage(AttributeTargets.Method | AttributeTargets.Property) | |
| ] | |
| [AttributeUsage(AttributeTargets.Method | AttributeTargets.Property)] |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -145,45 +145,71 @@ private static ResourceShape CreateResourceShape(string baseURI, | |||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| foreach (var propertyInfo in resourceType.GetProperties()) | ||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||
| var propertyDefinitionAttribute = propertyInfo.GetCustomAttribute<OslcPropertyDefinition>(); | ||||||||||||||||||||||||||||||||||
| if (propertyDefinitionAttribute != null) | ||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||
| var propertyDefinition = propertyDefinitionAttribute.value; | ||||||||||||||||||||||||||||||||||
| if (propertyDefinitions.Contains(propertyDefinition)) | ||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||
| // throw new OslcCoreDuplicatePropertyDefinitionException(resourceType, propertyDefinitionAttribute); | ||||||||||||||||||||||||||||||||||
| // Skip duplicates (e.g. from getter/setter pairs if we scan them too, though here we scan properties) | ||||||||||||||||||||||||||||||||||
| continue; | ||||||||||||||||||||||||||||||||||
|
Comment on lines
+156
to
+158
|
||||||||||||||||||||||||||||||||||
| // throw new OslcCoreDuplicatePropertyDefinitionException(resourceType, propertyDefinitionAttribute); | |
| // Skip duplicates (e.g. from getter/setter pairs if we scan them too, though here we scan properties) | |
| continue; | |
| throw new OslcCoreDuplicatePropertyDefinitionException(resourceType, propertyDefinitionAttribute); |
Copilot
AI
Dec 7, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The inline comment "lowercase first char for properties too? Usually yes for RDF properties" suggests uncertainty about the implementation. This logic transforms property names to camelCase, but the comment indicates this may not be the correct approach in all cases. This should be verified and the comment either removed or turned into proper documentation explaining when and why this transformation occurs.
Copilot
AI
Dec 7, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The property definition validation is commented out and replaced with a silent no-op. The original code threw OslcCoreInvalidPropertyDefinitionException when the property definition didn't end with the property name. This validation should be restored or at least logged, as it catches configuration errors in OSLC property definitions.
| // throw new OslcCoreInvalidPropertyDefinitionException(resourceType, member as MethodInfo, propertyDefinitionAttribute); | |
| // Relaxed check or throw proper exception | |
| throw new OslcCoreInvalidPropertyDefinitionException(resourceType, member as MethodInfo, propertyDefinitionAttribute); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
needs to be fixed properly
Copilot
AI
Dec 7, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The cast ((PropertyInfo)member).PropertyType on line 199 is unsafe. If member is a MethodInfo, this cast will throw an InvalidCastException. While the ternary operator checks if it's a MethodInfo first, the logic could be clearer and safer. Consider: var returnType = member switch { MethodInfo mi => mi.ReturnType, PropertyInfo pi => pi.PropertyType, _ => throw new ArgumentException("Unsupported member type") };
| var returnType = member is MethodInfo mi ? mi.ReturnType : ((PropertyInfo)member).PropertyType; | |
| var returnType = member switch | |
| { | |
| MethodInfo mi => mi.ReturnType, | |
| PropertyInfo pi => pi.PropertyType, | |
| _ => throw new ArgumentException("Unsupported member type", nameof(member)) | |
| }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
needs to be fixed properly
Copilot
AI
Dec 7, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Passing member as MethodInfo to GetComponentType on line 212 can result in a null reference if member is actually a PropertyInfo. This could cause issues in GetComponentType if it doesn't handle null gracefully. Consider updating GetComponentType to accept MemberInfo or handle both cases explicitly.
| var componentType = GetComponentType(resourceType, member as MethodInfo, returnType); | |
| Type componentType; | |
| if (member is MethodInfo methodInfo) | |
| { | |
| componentType = GetComponentType(resourceType, methodInfo, returnType); | |
| } | |
| else if (member is PropertyInfo propertyInfo) | |
| { | |
| // If GetComponentType can be overloaded to accept PropertyInfo, use that. | |
| // Otherwise, pass null for MethodInfo and rely on returnType. | |
| componentType = GetComponentType(resourceType, null, returnType); | |
| } | |
| else | |
| { | |
| throw new InvalidOperationException("Member is neither MethodInfo nor PropertyInfo."); | |
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
needs to be fixed properly
Copilot
AI
Dec 7, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similarly, member as MethodInfo on line 241 is passed to GetDefaultValueType, which may not handle null properly if the member is a PropertyInfo. This pattern is repeated and could lead to runtime errors.
| valueType = GetDefaultValueType(resourceType, member as MethodInfo, componentType); | |
| MethodInfo methodInfo = member as MethodInfo; | |
| if (methodInfo == null && member is PropertyInfo propertyInfo) | |
| { | |
| methodInfo = propertyInfo.GetGetMethod(); | |
| } | |
| valueType = GetDefaultValueType(resourceType, methodInfo, componentType); |
Copilot
AI
Dec 7, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Multiple validation methods are commented out in the CreateProperty method (ValidateUserSpecifiedOccurs, ValidateUserSpecifiedValueType, ValidateUserSpecifiedRepresentation). This removes important validation logic that was present in the original method-based approach. Either these validations should be re-enabled with proper overloads that accept MemberInfo, or there should be a clear justification for why this validation is no longer necessary.
| // ValidateUserSpecifiedRepresentation(resourceType, member, representation, componentType); | |
| ValidateUserSpecifiedRepresentation(resourceType, member, representation, componentType); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
needs to be fixed properly
This file was deleted.
This file was deleted.
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spelling: "attribue" should be "attribute"