Пример #1
0
 /// <summary>
 ///   Adds the sub class map.
 /// </summary>
 /// <param name = "subClassMap">The sub class map.</param>
 internal void AddSubClassMap(SubClassMap subClassMap)
 {
     _subClassMaps.Add(subClassMap);
     subClassMap.SuperClassMap = this;
 }
Пример #2
0
 /// <summary>
 ///   Adds the sub class map.
 /// </summary>
 /// <param name = "subClassMap">The sub class map.</param>
 internal void AddSubClassMap(SubClassMap subClassMap)
 {
     _subClassMaps.Add(subClassMap);
     subClassMap.SuperClassMap = this;
 }
Пример #3
0
        private SubClassMap CreateSubClassMap(Type classType, Func<Type, IClassMap> classMapFinder){
            //TODO: should probably do something different to find the base type
            //mabe a convention?
            var superClassMap = classMapFinder(classType.BaseType);
            if(superClassMap == null)
                throw new InvalidOperationException(string.Format("Unable to find super class map for subclass {0}", classType));

            var subClassMap = new SubClassMap(classType);
            ((ClassMapBase)superClassMap).AddSubClassMap(subClassMap);
            var discriminator = _profile.GetDiscriminator(classType);
            var parentDiscriminator = superClassMap.Discriminator;
            if(parentDiscriminator == null)
                subClassMap.Discriminator = discriminator;
            else
            {
                Array array;
                if(parentDiscriminator.GetType().IsArray)
                    array = Array.CreateInstance(typeof(object), ((Array)parentDiscriminator).Length + 1);
                else
                {
                    array = Array.CreateInstance(typeof(object), 2);
                    array.SetValue(parentDiscriminator, 0);
                }

                array.SetValue(discriminator, array.Length - 1);
                subClassMap.Discriminator = array;
            }

            foreach(var member in _profile.FindMembers(classType))
            {
                if(subClassMap.HasId && subClassMap.IdMap.MemberName == member.Name)
                    continue;

                if(subClassMap.HasExtendedProperties && subClassMap.ExtendedPropertiesMap.MemberName == member.Name)
                    continue;

                if(superClassMap.GetMemberMapFromMemberName(member.Name) != null)
                    continue; //don't want to remap a member

                subClassMap.AddMemberMap(CreateMemberMap(classType, member));
            }

            return subClassMap;
        }