private IPropertyInformation EnsurePropertyDefinitionExisitsOnClassDefinition(
            ClassDefinition classDefinition,
            Type declaringType,
            string propertyName)
        {
            var propertyInfo =
                PropertyInfoAdapter.Create(declaringType.GetProperty(propertyName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance));
            var propertyReflector = new PropertyReflector(
                classDefinition,
                propertyInfo,
                new ReflectionBasedMemberInformationNameResolver(),
                PropertyMetadataProvider,
                DomainModelConstraintProviderStub);
            var propertyDefinition = propertyReflector.GetMetadata();

            if (!classDefinition.MyPropertyDefinitions.Contains(propertyDefinition.PropertyName))
            {
                var propertyDefinitions = new PropertyDefinitionCollection(classDefinition.MyPropertyDefinitions, false);
                propertyDefinitions.Add(propertyDefinition);
                PrivateInvoke.SetNonPublicField(classDefinition, "_propertyDefinitions", propertyDefinitions);
                var endPoints = new RelationEndPointDefinitionCollection(classDefinition.MyRelationEndPointDefinitions, false);
                endPoints.Add(MappingObjectFactory.CreateRelationEndPointDefinition(classDefinition, propertyInfo));
                PrivateInvoke.SetNonPublicField(classDefinition, "_relationEndPoints", endPoints);
            }

            return(propertyInfo);
        }
Пример #2
0
        public RelationDefinition[] GetRelationDefinitions(IDictionary <Type, ClassDefinition> classDefinitions)
        {
            ArgumentUtility.CheckNotNull("classDefinitions", classDefinitions);
            s_log.InfoFormat("Reflecting relation definitions of {0} class definitions...", classDefinitions.Count);

            using (StopwatchScope.CreateScope(s_log, LogLevel.Info, "Time needed to reflect relation definitions: {elapsed}."))
            {
                var relationDefinitions = MappingObjectFactory.CreateRelationDefinitionCollection(classDefinitions);
                return(relationDefinitions
                       .LogAndReturnValue(s_log, LogLevel.Info, result => string.Format("Generated {0} relation definitions.", result.Length)));
            }
        }
Пример #3
0
        public ClassDefinition[] GetClassDefinitions()
        {
            s_log.Info("Reflecting class definitions...");

            using (StopwatchScope.CreateScope(s_log, LogLevel.Info, "Time needed to reflect class definitions: {elapsed}."))
            {
                var types            = GetDomainObjectTypesSorted();
                var classDefinitions = MappingObjectFactory.CreateClassDefinitionCollection(types);

                return(classDefinitions
                       .LogAndReturnValue(s_log, LogLevel.Info, result => string.Format("Generated {0} class definitions.", result.Length)));
            }
        }
Пример #4
0
        public ClassDefinition GetMetadata(ClassDefinition baseClassDefinition)
        {
            var persistentMixinFinder = new PersistentMixinFinder(Type, baseClassDefinition == null);
            var classDefinition       = new ClassDefinition(
                _classIDProvider.GetClassID(Type), Type, IsAbstract(), baseClassDefinition, GetStorageGroupType(), persistentMixinFinder, _instanceCreator);

            var properties = MappingObjectFactory.CreatePropertyDefinitionCollection(classDefinition, GetPropertyInfos(classDefinition));

            classDefinition.SetPropertyDefinitions(properties);
            var endPoints = MappingObjectFactory.CreateRelationEndPointDefinitionCollection(classDefinition);

            classDefinition.SetRelationEndPointDefinitions(endPoints);

            return(classDefinition);
        }
        private RelationReflector CreateRelationReflectorForProperty(
            ClassDefinition classDefinition, Type declaringType, string propertyName)
        {
            var propertyInfo =
                PropertyInfoAdapter.Create(declaringType.GetProperty(propertyName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance));
            var propertyReflector = new PropertyReflector(
                classDefinition,
                propertyInfo,
                new ReflectionBasedMemberInformationNameResolver(),
                PropertyMetadataProvider,
                DomainModelConstraintProviderStub);
            var propertyDefinition = propertyReflector.GetMetadata();
            var properties         = new List <PropertyDefinition>();

            properties.Add(propertyDefinition);
            var propertyDefinitionsOfClass = (PropertyDefinitionCollection)PrivateInvoke.GetNonPublicField(classDefinition, "_propertyDefinitions");

            PrivateInvoke.SetNonPublicField(classDefinition, "_propertyDefinitions", null);
            if (propertyDefinitionsOfClass != null)
            {
                properties.AddRange(propertyDefinitionsOfClass);
            }
            classDefinition.SetPropertyDefinitions(new PropertyDefinitionCollection(properties, true));

            var endPoint  = MappingObjectFactory.CreateRelationEndPointDefinition(classDefinition, propertyInfo);
            var endPoints = new List <IRelationEndPointDefinition>();

            endPoints.Add(endPoint);
            var endPointDefinitionsOfClass = (RelationEndPointDefinitionCollection)PrivateInvoke.GetNonPublicField(classDefinition, "_relationEndPoints");

            PrivateInvoke.SetNonPublicField(classDefinition, "_relationEndPoints", null);
            if (endPointDefinitionsOfClass != null)
            {
                endPoints.AddRange(endPointDefinitionsOfClass);
            }
            classDefinition.SetRelationEndPointDefinitions(new RelationEndPointDefinitionCollection(endPoints, true));

            return(new RelationReflector(classDefinition, propertyInfo, new ReflectionBasedMemberInformationNameResolver(), PropertyMetadataProvider));
        }