Пример #1
0
        protected bool IsPropertyResolvable(Type type, IMap <String, IPropertyInfo> propertyMap, String memberName, IEntityMetaData metaData)
        {
            if (metaData != null && metaData.GetMemberByName(memberName) == null)
            {
                return(false);
            }
            if (propertyMap == null)
            {
                propertyMap = PropertyInfoProvider.GetPropertyMap(type);
            }
            if (propertyMap.ContainsKey(memberName))
            {
                return(true);
            }
            String[] memberPath = memberName.Split("\\.".ToCharArray());
            if (memberPath.Length == 0)
            {
                return(false);
            }
            IPropertyInfo propertyInfo = propertyMap.Get(memberPath[0]);

            if (propertyInfo == null)
            {
                return(false);
            }
            String remainingMemberName = memberName.Substring(memberPath[0].Length + 1);

            return(IsPropertyResolvable(propertyInfo.PropertyType, null, remainingMemberName, metaData));
        }
Пример #2
0
        protected void HandleMemberMappings(ValueObjectConfig config, IMap <String, IList <XElement> > configDetails, IEntityMetaData metaData)
        {
            Type entityType = config.EntityType;
            Type valueType  = config.ValueType;

            IMap <String, IPropertyInfo> entityPropertyMap = PropertyInfoProvider.GetPropertyMap(entityType);
            IMap <String, IPropertyInfo> valuePropertyMap  = PropertyInfoProvider.GetPropertyMap(valueType);

            for (int i = memberTagNames.Length; i-- > 0;)
            {
                String memberTagName = memberTagNames[i].LocalName;

                IList <XElement> memberTags = configDetails.Get(memberTagName);
                if (memberTags == null)
                {
                    continue;
                }

                for (int j = memberTags.Count; j-- > 0;)
                {
                    XElement element    = memberTags[j];
                    String   memberName = XmlConfigUtil.GetRequiredAttribute(element, XmlConstants.NAME);
                    if (config.IsIgnoredMember(memberName))
                    {
                        continue;
                    }
                    if (RuntimeValidationActive && !IsPropertyResolvable(valueType, valuePropertyMap, memberName, null))
                    {
                        throw new ArgumentException("Value type property '" + valueType.Name + "." + memberName + "' not found");
                    }

                    bool holdsListType = XmlConfigUtil.AttributeIsTrue(element, XmlConstants.LIST_TYPE);
                    if (holdsListType)
                    {
                        config.AddListTypeMember(memberName);
                    }

                    String entityMemberName = XmlConfigUtil.GetAttribute(element, XmlConstants.NAME_IN_ENTITY);
                    if (entityMemberName.Length == 0)
                    {
                        entityMemberName = memberName;
                    }
                    else
                    {
                        config.PutValueObjectMemberName(entityMemberName, memberName);
                    }
                    if (RuntimeValidationActive && !IsPropertyResolvable(entityType, entityPropertyMap, entityMemberName, metaData))
                    {
                        throw new ArgumentException("Entity type property '" + entityType.Name + "." + entityMemberName
                                                    + "' not found while configuring value type '" + valueType.Name + "'");
                    }
                }
            }
        }