コード例 #1
0
        private bool TryApplyBehavior <TBehavior, TAccessor>(
            string key,
            PropertyDescriptor property,
            object behavior,
            ref XmlAccessor accessor,
            XmlAccessorFactory <TAccessor> factory
            )
            where TBehavior : class
            where TAccessor : XmlAccessor, IConfigurable <TBehavior>
        {
            var typedBehavior = behavior as TBehavior;

            if (typedBehavior == null)
            {
                return(false);
            }

            if (accessor == null)
            {
                accessor = CreateAccessor(key, property, factory);
            }

            var typedAccessor = accessor as TAccessor;

            if (typedAccessor == null)
            {
                throw Error.AttributeConflict(key);
            }

            typedAccessor.Configure(typedBehavior);
            return(true);
        }
コード例 #2
0
        private TAccessor CreateAccessor <TAccessor>(
            string key,
            PropertyDescriptor property,
            XmlAccessorFactory <TAccessor> factory
            ) where TAccessor : XmlAccessor
        {
            var xmlMeta  = GetXmlMetadata(property.Property.DeclaringType);
            var accessor = factory(key, property.PropertyType, xmlMeta.Context);

            if (xmlMeta.IsNullable.HasValue)
            {
                accessor.ConfigureNillable(xmlMeta.IsNullable.Value);
            }
            if (xmlMeta.IsReference.HasValue)
            {
                accessor.ConfigureReference(xmlMeta.IsReference.Value);
            }
            return(accessor);
        }