Skip to content

Commit

Permalink
Speed up ValidateProperty (#453)
Browse files Browse the repository at this point in the history
* Check metaMember.IsComplex before casting to ComplexObject
* Only do validation if property requires validation (don't check whole object)
  • Loading branch information
Daniel-Svensson authored Oct 31, 2023
1 parent 89119c4 commit d6fe496
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/OpenRiaServices.Client/Framework/Entity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1298,13 +1298,12 @@ protected void ValidateProperty(string propertyName, object value)
throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resource.Property_Is_ReadOnly, propertyName));
}

ComplexObject complexObject = value as ComplexObject;
if (complexObject != null && complexObject.IsAttached)
if (metaMember.IsComplex && value is ComplexObject complexObject && complexObject.IsAttached)
{
throw new InvalidOperationException(Resource.ComplexType_InstancesCannotBeShared);
}

if (this.MetaType.RequiresValidation)
if (metaMember.RequiresValidation)
{
ValidationContext validationContext = this.CreateValidationContext();
validationContext.MemberName = propertyName;
Expand Down

0 comments on commit d6fe496

Please sign in to comment.