示例#1
0
 private void SetSimpleProperty(object bean, InternalPropertyInfo info, object value)
 {
     if (info.GetWriteMethod() == null)
     {
         throw new ArgumentException("Property '" + info.name + "' of bean " + bean.GetType().Name +
                                     " does not have setter method");
     }
     InvokeWriteMethod(info.GetWriteMethod(), bean, info.GetName(), value);
 }
示例#2
0
 private object GetSimpleProperty(object bean, InternalPropertyInfo info)
 {
     if (info.GetReadMethod() == null)
     {
         throw new ArgumentException("Property '" + info.name + "' of bean " + bean.GetType().Name +
                                     " does not have getter method");
     }
     return(InvokeReadMethod(info.GetReadMethod(), bean));
 }
示例#3
0
        public InternalPropertyInfo GetPropertyInfoRequired(object bean, string name)
        {
            InternalPropertyInfo result = GetPropertyInfo(bean, name);

            if (result == null)
            {
                throw new ArgumentException(
                          "Bean " + bean.GetType().Name + " does not have property '" + name + "'");
            }
            return(result);
        }
示例#4
0
        /**
         * Write value to bean's property
         * @param bean
         * @param name
         * @param value
         * @return
         */
        public bool SetSimpleProperty(object bean, string name, object value)
        {
            InternalPropertyInfo pi = GetPropertyInfo(bean, name);

            if (pi != null)
            {
                SetSimpleProperty(bean, pi, value);
                return(true);
            }
            else
            {
                return(false);
            }
        }
示例#5
0
        internal static InternalPropertyInfo PrimaryKeyAttributeValidate(this IEnumerable <PropertyInfo> properties, Type type)
        {
            var primaryKeyProperty = properties.Where(IsSQLPrimaryKeyAttribute);

            if (primaryKeyProperty == null)
            {
                throw new Exception($"Can't find attribute [{typeof(PrimaryKeyAttribute).FullName}] in {type.FullName}.");
            }
            if (primaryKeyProperty.Count() != 1)
            {
                throw new Exception($"The attribute [{typeof(PrimaryKeyAttribute).FullName}] must specific only once per class. (error in {type.FullName} class)");
            }
            var property = new InternalPropertyInfo(primaryKeyProperty.First());

            return(property);
        }
示例#6
0
        public InternalPropertyInfo[] GetPropertiesInfoForBean(Type beanClass)
        {
            if (beanClass == null)
            {
                throw new ArgumentException("Bean class is required and can not be null");
            }

            InternalPropertyInfo[] infos = null;
            if (properties.ContainsKey(beanClass))
            {
                infos = properties[beanClass];
            }
            if (infos != null)
            {
                return(infos);
            }

            MemberInfo[] descriptors;
            try
            {
                descriptors = GetDescriptors(beanClass);
                //descriptors =  Introspector.getBeanInfo(beanClass).getPropertyDescriptors();
                if (!descriptors.Any())
                {
                    descriptors = EMPTY_PROPERTY_DESCRIPTOR;
                }
            }
            catch (Exception)
            {
                descriptors = EMPTY_PROPERTY_DESCRIPTOR;
            }
            infos = new InternalPropertyInfo[descriptors.Length];
            for (int i = 0; i < descriptors.Length; i++)
            {
                infos[i] = CreatePropertyInfo(beanClass, descriptors[i]);
            }
            properties.Add(beanClass, infos);
            return(infos);
        }
示例#7
0
        public ForeignKeyAttribute(Type referenceTable)
        {
            var primaryKeyOfReferenceTable = Shared.AttributeExtension.PrimaryKeyAttributeValidate(referenceTable);

            ReferenceKeyProperty = primaryKeyOfReferenceTable;
        }
示例#8
0
        public ForeignKeyAttribute(Type referenceTable)
        {
            var primaryKeyOfReferenceTable = AttributeValidator.PrimaryKeyAttributeValidate(referenceTable);

            ReferenceKeyProperty = primaryKeyOfReferenceTable;
        }