Ejemplo n.º 1
0
 private static AttributeValue GetAttributeValue(Type type, List <string> stringValues, List <AttributeValue> attributeValues)
 {
     if (stringValues.Count > 0)
     {
         if (StringTypes.Contains(type))
         {
             return(new AttributeValue {
                 SS = stringValues
             });
         }
         else if (AllNumberTypes.Contains(type))
         {
             return(new AttributeValue {
                 NS = stringValues
             });
         }
         else
         {
             throw new InvalidCastException("Type not supported: " + type.Name);
         }
     }
     else if (attributeValues.Count > 0)
     {
         return(new AttributeValue {
             L = attributeValues
         });
     }
     else
     {
         throw new InvalidCastException("Type not supported: " + type.Name);
     }
 }
Ejemplo n.º 2
0
        internal static AttributeValue ConvertToAttributeValue(Type type, IEnumerator value)
        {
            var stringValues    = new List <string>();
            var attributeValues = new List <AttributeValue>();

            if (value != null)
            {
                if (AllTypes.Contains(type))
                {
                    while (value.MoveNext())
                    {
                        stringValues.Add($"{value.Current}");
                    }
                }
                else if (type.IsClass)
                {
                    while (value.MoveNext())
                    {
                        attributeValues.Add(AttributeValueConverter.ConvertToAttributeValue[typeof(object)](value.Current));
                    }
                }
                else
                {
                    throw new InvalidCastException("Type not supported: " + type.Name);
                }

                if (stringValues.Count > 0)
                {
                    if (StringTypes.Contains(type))
                    {
                        return new AttributeValue
                               {
                                   SS = stringValues
                               }
                    }
                    ;
                    else if (AllNumberTypes.Contains(type))
                    {
                        return new AttributeValue
                               {
                                   NS = stringValues
                               }
                    }
                    ;
                }
                else if (attributeValues.Count > 0)
                {
                    return new AttributeValue
                           {
                               L = attributeValues
                           }
                }
                ;
            }

            return(new AttributeValue
            {
                NULL = true
            });
        }
    }
}