示例#1
0
        private static BindingMap CreateBingingMap(Type type)
        {
            var map = new BindingMap();

            var properties = type.GetProperties();

            foreach (var prop in properties)
            {
                var attr = (DeserializeAsAttribute)prop.GetCustomAttribute(
                    typeof(DeserializeAsAttribute));

                if (attr != null)
                {
                    if (string.IsNullOrEmpty(attr.Name))
                    {
                        var error = string.Format(
                            "Attribute DeserializeAs Name is empty for type '{0}', property {1}",
                            type.FullName,
                            prop.Name);

                        throw new InvalidOperationException(error);
                    }

                    map.Add(attr.Name.ToUpper(), prop);
                }
            }

            return(map);
        }