コード例 #1
0
        private void SetProperty(object obj, PropertyInfo property, XmlRpcStructMemberAttribute memberAttribute, StructValue structValue)
        {
            var memberName = string.IsNullOrEmpty(memberAttribute.Name)
                ? property.Name
                : memberAttribute.Name;

            if (!structValue.Value.TryGetValue(memberName, out var xmlRpcValue))
            {
                if (memberAttribute.Required)
                {
                    throw new RequiredMemberMissingException(property, memberAttribute);
                }

                if (memberAttribute.DefaultValue != XmlRpcStructMemberAttribute.NoDefaultValue)
                {
                    property.SetValue(obj, memberAttribute.DefaultValue);
                }

                return;
            }

            var memberConverter = memberAttribute.GetConverter();

            var memberValue = memberConverter == null
                ? Convert(xmlRpcValue, memberAttribute.DataType ?? property.PropertyType)
                : memberConverter.ConvertFromValue(xmlRpcValue);

            property.SetValue(obj, memberValue);
        }
コード例 #2
0
        private void SetMemberValue(object obj, PropertyInfo property, XmlRpcStructMemberAttribute memberAttribute,
                                    StructValue xmlRpcStruct)
        {
            var memberName = string.IsNullOrEmpty(memberAttribute.Name)
                ? property.Name
                : memberAttribute.Name;

            var propertyValue = property.GetValue(obj);

            var memberConverter = memberAttribute.GetConverter();

            var value = memberConverter != null
                ? memberConverter.ConvertFromObject(propertyValue)
                : Convert(propertyValue);

            if (value == null)
            {
                return;
            }

            xmlRpcStruct.Value[memberName] = value;
        }
コード例 #3
0
 public RequiredMemberMissingException(PropertyInfo property, XmlRpcStructMemberAttribute memberAttribute) :
     base($"The required struct member '{memberAttribute.Name ?? property.Name}' is missing")
 {
     Property     = property;
     StructMember = memberAttribute;
 }