Beispiel #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);
 }
Beispiel #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));
 }
Beispiel #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);
        }
Beispiel #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);
            }
        }
Beispiel #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);
        }
Beispiel #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);
        }
Beispiel #7
0
        public ForeignKeyAttribute(Type referenceTable)
        {
            var primaryKeyOfReferenceTable = Shared.AttributeExtension.PrimaryKeyAttributeValidate(referenceTable);

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

            ReferenceKeyProperty = primaryKeyOfReferenceTable;
        }