Exemple #1
0
 public PropertyTypeRegistration(PropertyInfo propInfo, RepositoryPropertyAttribute propTypeAttr)
 {
     // Use when a PropertyType attribute is on a code Property
     Name       = propTypeAttr.PropertyName != null ? propTypeAttr.PropertyName : DefaultName(propInfo);
     DataType   = (propTypeAttr.DataType != RepositoryDataType.NotDefined) ? propTypeAttr.DataType : DataTypeFromSystemType(propInfo.PropertyType);
     IsDeclared = true;
 }
		public PropertyTypeRegistration(PropertyInfo propInfo, RepositoryPropertyAttribute propTypeAttr)
		{
			//-- Use when a PropertyType attribute is on a code Property
			Name = propTypeAttr.PropertyName != null ? propTypeAttr.PropertyName : DefaultName(propInfo);
			DataType = (propTypeAttr.DataType != RepositoryDataType.NotDefined) ? propTypeAttr.DataType : DataTypeFromSystemType(propInfo.PropertyType);
			IsDeclared = true;
		}
        // ---------------------------------------------------------------------- Attribute parsing

        private static NodeTypeRegistration ParseAttributes(Type type)
        {
            NodeTypeRegistration    ntReg = null;
            ContentHandlerAttribute contentHandlerAttribute = null;

            foreach (object attrObject in type.GetCustomAttributes(false))
            {
                if ((contentHandlerAttribute = attrObject as ContentHandlerAttribute) != null)
                {
                    break;
                }
            }

            // Finish if there is not a ContentHandlerAttribute
            if (contentHandlerAttribute == null)
            {
                return(ntReg);
            }

            // Must inherit from Node.
            if (!IsInheritedFromNode(type))
            {
                throw new ContentRegistrationException(String.Format(CultureInfo.CurrentCulture,
                                                                     SR.Exceptions.Registration.Msg_NodeTypeMustBeInheritedFromNode_1,
                                                                     type.FullName));
            }

            // Property checks
            RepositoryPropertyAttribute     propertyAttribute                   = null;
            List <PropertyTypeRegistration> propertyTypeRegistrations           = new List <PropertyTypeRegistration>();
            Dictionary <string, RepositoryPropertyAttribute> propertyAttributes = new Dictionary <string, RepositoryPropertyAttribute>();

            List <PropertyInfo> props = new List <PropertyInfo>(type.GetProperties(_publicPropertyBindingFlags));

            props.AddRange(type.GetProperties(_nonPublicPropertyBindingFlags));

            foreach (PropertyInfo propInfo in props)
            {
                string propName = propInfo.Name;

                propertyAttribute = null;
                foreach (object attrObject in propInfo.GetCustomAttributes(false))
                {
                    if ((propertyAttribute = attrObject as RepositoryPropertyAttribute) != null)
                    {
                        break;
                    }
                }

                if (propertyAttribute == null)
                {
                    continue;
                }

                if (propertyAttributes.ContainsKey(propName))
                {
                    throw new RegistrationException(String.Format(CultureInfo.CurrentCulture,
                                                                  SR.Exceptions.Registration.Msg_PropertyTypeAttributesWithTheSameName_2,
                                                                  type.FullName, propInfo.Name));
                }
                propertyAttributes.Add(propName, propertyAttribute);

                // Override default name with passed name
                if (propertyAttribute.PropertyName != null)
                {
                    propName = propertyAttribute.PropertyName;
                }

                // Build PropertyTypeRegistration
                PropertyTypeRegistration propReg = new PropertyTypeRegistration(propInfo, propertyAttribute);
                propertyTypeRegistrations.Add(propReg);
            }

            // Build NodeTypeRegistration
            ntReg = new NodeTypeRegistration(type, null, propertyTypeRegistrations);

            return(ntReg);
        }