protected override InvocationResult PropertyMissing(string name) { var attribute = _element.Attribute(name); var childElement = _element.Element(name); var childElements = GetChildElements(name); var namespaceChildElement = GetNamespaceChildElement(name); var defaultNamespaceChildElement = GetDefaultNamespaceChildElement(name); var namespaceChildElements = GetNamespaceChildElements(name); var defaultNamespaceChildElements = GetDefaultChildElements(name); if (attribute != null) { var convertibleValue = new ConvertibleStringValue(attribute.Value, _valueConverter); return new SuccessfulInvocationResult(convertibleValue); } if (childElement != null) { return new SuccessfulInvocationResult(new DynamicXmlElement(childElement, _valueConverter, _namespaceRegistry)); } if (defaultNamespaceChildElement != null) { return new SuccessfulInvocationResult(new DynamicXmlElement(defaultNamespaceChildElement, _valueConverter, _namespaceRegistry)); } if (namespaceChildElement != null) { return new SuccessfulInvocationResult(new DynamicXmlElement(namespaceChildElement, _valueConverter, _namespaceRegistry)); } if (childElements.Any()) { return new SuccessfulInvocationResult(childElements); } if (defaultNamespaceChildElements.Any()) { return new SuccessfulInvocationResult(defaultNamespaceChildElements); } if (namespaceChildElements.Any()) { return new SuccessfulInvocationResult(namespaceChildElements); } throw new MissingValueException(name); }
protected override InvocationResult ConversionMissing(Type type, ConversionMode conversionMode) { var value = new ConvertibleStringValue(_element.Value, _valueConverter); if (value.CanConvertTo(type)) { return new SuccessfulInvocationResult(value.Convert(type)); } return new FailedInvocationResult(); }