GeoEco.Metadata.ClassMetadata.ValidatePropertyAssignment
- ClassMetadata.ValidatePropertyAssignment()
Validates a property’s value using the property’s
PropertyMetadata.This method is intended to be called from the setter method of a property to which a
PropertyMetadatahas been added. It calls theValidateValue()method of theTypeMetadataobtained fromPropertyMetadata.Typefor the property.ValidateValue()raises an exception if the specified value does not pass whatever checks are implemented by theTypeMetadata. For example:from GeoEco.Internationalization import _ import GeoEco.Metadata import GeoEco.Types class MyClass(object): def _GetMyProperty(self): return self._MyProperty def _SetMyProperty(self, value): self.__doc__.Obj.ValidatePropertyAssignment() self._MyProperty = value MyProperty = property(_GetMyProperty, _SetMyProperty, doc=GeoEco.Metadata.DynamicDocString()) GeoEco.Metadata.AddModuleMetadata(shortDescription=_('This is my example module.')) GeoEco.Metadata.AddClassMetadata(MyClass, shortDescription=_('This is my example class.')) GeoEco.Metadata.AddPropertyMetadata(MyClass.MyProperty, typeMetadata=GeoEco.Types.UnicodeStringTypeMetadata(), shortDescription=_('This is my example property.')) c = MyClass() c.MyProperty = 'Hello, world!' # This will succeed c.MyProperty = 1 # 1 is not a string; ValidatePropertyAssignment will raise TypeError