public static IPersistentAssociatedMemberInfo GetAssociation(this IPersistentAssociatedMemberInfo persistentMemberInfo)
        {
            var associationName = persistentMemberInfo.TypeAttributes.OfType <IPersistentAssociationAttribute>().First().AssociationName;

            return(persistentMemberInfo.Owner.OwnMembers.OfType <IPersistentAssociatedMemberInfo>()
                   .Where(info => info != persistentMemberInfo && info.TypeAttributes.OfType <IPersistentAssociationAttribute>()
                          .Any(attribute => attribute.AssociationName == associationName)).First());
        }
예제 #2
0
        private AssemblyDefinition CreateAndCheckAssociation(IPersistentAssociatedMemberInfo memberInfo, Compiler compiler, bool autogenerateOtherPart = false)
        {
            memberInfo.CreateAssociation("association");
            var assemblyInfo = memberInfo.Owner.PersistentAssemblyInfo;
            var code         = assemblyInfo.GenerateCode();

            var compilerResult = compiler.Compile(code, assemblyInfo.Name);

            return(CheckAssociation(memberInfo, compilerResult.AssemblyDefinition));
        }
예제 #3
0
        private AssemblyDefinition CheckAssociation(IPersistentAssociatedMemberInfo memberInfo, AssemblyDefinition assemblyDefinition)
        {
            var propertyDefinitions =
                assemblyDefinition.MainModule.Types.SelectMany(definition => definition.Properties);
            var propertyDefinition = propertyDefinitions.First(definition => definition.Name == memberInfo.Name);
            var customAttribute    = propertyDefinition.CustomAttributes.FirstOrDefault(
                attribute => attribute.AttributeType.Name.Contains(typeof(AssociationAttribute).Name));

            customAttribute.Should().NotBeNull();
            customAttribute?.Properties.FirstOrDefault(argument => argument.Name == "assocation").Should().NotBeNull();
            return(assemblyDefinition);
        }
예제 #4
0
        public static IPersistentAssociationAttribute CreateAssociation(this IPersistentAssociatedMemberInfo associatedMemberInfo, string associationName, Type elementType = null)
        {
            var objectType           = XafTypesInfo.Instance.FindBussinessObjectType <IPersistentAssociationAttribute>();
            var associationAttribute = (IPersistentAssociationAttribute)Activator.CreateInstance(objectType, associatedMemberInfo.Session);

            associationAttribute.Owner = associatedMemberInfo;
            if (elementType != null)
            {
                associationAttribute.ElementTypeFullName = elementType.FullName;
            }
            associationAttribute.AssociationName = associationName;
            return(associationAttribute);
        }
 public static bool IsAssociation(this IPersistentAssociatedMemberInfo persistentMemberInfo)
 {
     return(persistentMemberInfo.Find <AssociationAttribute>() != null);
 }
 public static IPersistentCollectionMemberInfo GetAssociatedCollection(this IPersistentAssociatedMemberInfo persistentMemberInfo, string elementTypeFullName)
 {
     throw new NotImplementedException();
 }