private XPCustomMemberInfo CreateMemberInfo(ITypesInfo typesInfo, IMemberInfo memberInfo, ProvidedAssociationAttribute providedAssociationAttribute, AssociationAttribute associationAttribute) {
            var typeToCreateOn = getTypeToCreateOn(memberInfo, associationAttribute);
            if (typeToCreateOn == null)
                throw new NotImplementedException();
            XPCustomMemberInfo xpCustomMemberInfo;
            if (!(memberInfo.IsList) || (memberInfo.IsList && providedAssociationAttribute.RelationType == RelationType.ManyToMany)) {
                xpCustomMemberInfo = typesInfo.CreateCollection(
                    typeToCreateOn,
                    memberInfo.Owner.Type,
                    associationAttribute.Name,
                    XpandModuleBase.Dictiorary,
                    providedAssociationAttribute.ProvidedPropertyName ?? memberInfo.Owner.Type.Name + "s", false);
            } else {
                xpCustomMemberInfo = typesInfo.CreateMember(
                    typeToCreateOn,
                    memberInfo.Owner.Type,
                    associationAttribute.Name,
                    XpandModuleBase.Dictiorary,
                    providedAssociationAttribute.ProvidedPropertyName ?? memberInfo.Owner.Type.Name, false);
            }

            if (!string.IsNullOrEmpty(providedAssociationAttribute.AssociationName) && memberInfo.FindAttribute<AssociationAttribute>() == null)
                memberInfo.AddAttribute(new AssociationAttribute(providedAssociationAttribute.AssociationName));

            typesInfo.RefreshInfo(typeToCreateOn);

            return xpCustomMemberInfo;
        }
Пример #2
0
        public void AN_Association_Collection_Can_Be_Created_To_Any_Persistent_Type()
        {
            ITypesInfo info           = XafTypesInfo.Instance;
            Type       typeToCreateOn = typeof(User);

            info.RegisterEntity(typeToCreateOn);
            Type typeOfCollection = typeof(Analysis);

            XPCustomMemberInfo collection = info.CreateCollection(typeToCreateOn, typeOfCollection, "association",
                                                                  XpoTypesInfoHelper.GetXpoTypeInfoSource().XPDictionary);

            AssociationAttribute attribute = assertMemberCreation(collection, typeOfCollection.Name + "s", typeToCreateOn);

            Assert.AreEqual(typeOfCollection.FullName, attribute.ElementTypeName);
        }
Пример #3
0
        private XPMemberInfo CreateMemberInfo(ITypesInfo typesInfo, XPMemberInfo memberInfo, ProvidedAssociationAttribute providedAssociationAttribute, AssociationAttribute associationAttribute)
        {
            var typeToCreateOn = GetTypeToCreateOn(memberInfo, associationAttribute);

            if (typeToCreateOn == null)
            {
                throw new NotImplementedException();
            }
            XPMemberInfo xpCustomMemberInfo;

            if (!(memberInfo.IsNonAssociationList) || (memberInfo.IsNonAssociationList && providedAssociationAttribute.RelationType == RelationType.ManyToMany))
            {
                xpCustomMemberInfo = typesInfo.CreateCollection(
                    typeToCreateOn,
                    memberInfo.Owner.ClassType,
                    associationAttribute.Name,
                    XpandModuleBase.Dictiorary,
                    providedAssociationAttribute.ProvidedPropertyName ?? memberInfo.Owner.ClassType.Name + "s", false);
            }
            else
            {
                xpCustomMemberInfo = typesInfo.CreateMember(
                    typeToCreateOn,
                    memberInfo.Owner.ClassType,
                    associationAttribute.Name,
                    XpandModuleBase.Dictiorary,
                    providedAssociationAttribute.ProvidedPropertyName ?? memberInfo.Owner.ClassType.Name, false);
            }

            if (!string.IsNullOrEmpty(providedAssociationAttribute.AssociationName) && !memberInfo.HasAttribute(typeof(AssociationAttribute)))
            {
                memberInfo.AddAttribute(new AssociationAttribute(providedAssociationAttribute.AssociationName));
            }

            typesInfo.RefreshInfo(typeToCreateOn);

            return(xpCustomMemberInfo);
        }