Exemplo n.º 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);
        }
Exemplo n.º 2
0
 private bool TryApplyBehavior(
     string key,
     PropertyDescriptor property,
     object behavior,
     ref XmlAccessor accessor
     )
 {
     return(TryApplyBehavior <XmlElementAttribute, XmlElementBehaviorAccessor>(
                key,
                property,
                behavior,
                ref accessor,
                XmlElementBehaviorAccessor.Factory
                ) ||
            TryApplyBehavior <XmlArrayAttribute, XmlArrayBehaviorAccessor>(
                key,
                property,
                behavior,
                ref accessor,
                XmlArrayBehaviorAccessor.Factory
                ) ||
            TryApplyBehavior <XmlArrayItemAttribute, XmlArrayBehaviorAccessor>(
                key,
                property,
                behavior,
                ref accessor,
                XmlArrayBehaviorAccessor.Factory
                ) ||
            TryApplyBehavior <XmlAttributeAttribute, XmlAttributeBehaviorAccessor>(
                key,
                property,
                behavior,
                ref accessor,
                XmlAttributeBehaviorAccessor.Factory
                ) ||
            TryApplyBehavior <XPathAttribute, XPathBehaviorAccessor>(
                key,
                property,
                behavior,
                ref accessor,
                XPathBehaviorAccessor.Factory
                ) ||
            TryApplyBehavior <XPathVariableAttribute, XPathBehaviorAccessor>(
                key,
                property,
                behavior,
                ref accessor,
                XPathBehaviorAccessor.Factory
                ) ||
            TryApplyBehavior <XPathFunctionAttribute, XPathBehaviorAccessor>(
                key,
                property,
                behavior,
                ref accessor,
                XPathBehaviorAccessor.Factory
                ));
 }
        public void Configure(XPathAttribute attribute)
        {
            if (path != null)
            {
                throw Error.AttributeConflict(path.Path.Expression);
            }

            path = attribute.SetPath;

            if (path == attribute.GetPath)
            {
                return;
            }
            else if (Serializer.CanGetStub)
            {
                throw Error.SeparateGetterSetterOnComplexType(path.Path.Expression);
            }

            defaultAccessor = new DefaultAccessor(this, attribute.GetPath);
        }
Exemplo n.º 4
0
        private bool TryGetAccessor(
            string key,
            PropertyDescriptor property,
            bool requireVolatile,
            out XmlAccessor accessor
            )
        {
            accessor = property.HasAccessor()
              ? property.GetAccessor()
              : CreateAccessor(key, property);

            if (accessor.IsIgnored)
            {
                return(Try.Failure(out accessor));
            }
            if (requireVolatile && !accessor.IsVolatile)
            {
                return(Try.Failure(out accessor));
            }
            return(true);
        }
Exemplo n.º 5
0
		public static void SetAccessor(this PropertyDescriptor property, XmlAccessor accessor)
		{
		    property.ExtendedProperties[XmlAccessorKey] = accessor;
		}
 public override IXmlCollectionAccessor GetCollectionAccessor(Type itemType)
 {
     return(itemAccessor ?? (itemAccessor = new ItemAccessor(this)));
 }
Exemplo n.º 7
0
 public static void SetAccessor(this PropertyDescriptor property, XmlAccessor accessor)
 {
     property.ExtendedProperties[XmlAccessorKey] = accessor;
 }