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 PropertyMetadata has been added. It calls the ValidateValue() method of the TypeMetadata obtained from PropertyMetadata.Type for the property. ValidateValue() raises an exception if the specified value does not pass whatever checks are implemented by the TypeMetadata. 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