コード例 #1
0
ファイル: Component.cs プロジェクト: j-vallet/hbm-to-fnh
        public void Start(string prefix, MappedPropertyInfo item)
        {
            CodeFileBuilder componentBuilder = new CodeFileBuilder();

            componentBuilder.Indent(5);
            const string subPrefix = "y.";
            HbmComponent component = item.HbmObject <HbmComponent>();

            componentBuilder.AddLine("");

            var componentBodyBuilder = new ClassMapBody(componentBuilder);

            foreach (var componentPart in component.Items)
            {
                componentBodyBuilder.Add(subPrefix, new MappedPropertyInfo(componentPart, item.FileName));
            }
            _builder.StartMethod(prefix, string.Format("{0}<{1}>(x => x.{2}, y=>", FluentNHibernateNames.Component, item.ReturnType, item.Name));
            _builder.AddLine("{");
            _builder.AddLine(componentBuilder.ToString());
            _builder.AddLine("})");
            if (component.insert)
            {
                _builder.AddLine(string.Format(".{0}()", FluentNHibernateNames.Insert));
            }
            if (component.update)
            {
                _builder.AddLine(string.Format(".{0}()", FluentNHibernateNames.Update));
            }
        }
コード例 #2
0
 public ComponentMapper(HbmComponent component, System.Type componentType, IAccessorPropertyMapper accessorMapper, HbmMapping mapDoc)
     : base(componentType, mapDoc)
 {
     _component              = component;
     _component.@class       = componentType.GetShortClassName(mapDoc);
     _accessorPropertyMapper = accessorMapper;
 }
コード例 #3
0
 public ComponentMapper(HbmComponent component, Type componentType, MemberInfo declaringTypeMember, HbmMapping mapDoc)
     : base(componentType, mapDoc)
 {
     this.component         = component;
     component.@class       = componentType.GetShortClassName(mapDoc);
     accessorPropertyMapper = new AccessorPropertyMapper(declaringTypeMember.DeclaringType, declaringTypeMember.Name, x => component.access = x);
 }
コード例 #4
0
        public void WhenNoDefaultAssignComponentClassAssemblyQualifiedName()
        {
            var mapping = new HbmMapping();
            var hbm     = new HbmComponent();

            new ComponentMapper <Address>(mapping, hbm);
            hbm.Class.Should().Be.EqualTo(typeof(Address).AssemblyQualifiedName);
        }
コード例 #5
0
        public void CanSetComponentAccessor()
        {
            var mapdoc    = new HbmMapping();
            var component = new HbmComponent();
            var mapper    = new ComponentMapper(component, typeof(Name), ForClass <Person> .Property(p => p.Name), mapdoc);

            mapper.Access(Accessor.Field);
            component.access.Should().Contain("field");
        }
コード例 #6
0
        public void CanSetUpdate()
        {
            var mapdoc    = new HbmMapping();
            var component = new HbmComponent();
            var mapper    = new ComponentMapper(component, typeof(Name), ForClass <Person> .Property(p => p.Name), mapdoc);

            mapper.Update(false);
            component.update.Should().Be.False();
        }
コード例 #7
0
        public void CanSetParentAccessor()
        {
            var mapdoc    = new HbmMapping();
            var component = new HbmComponent();
            var mapper    = new ComponentMapper(component, typeof(Name), ConfOrm.ForClass <Person> .Property(p => p.Name), mapdoc);

            mapper.Parent(typeof(Address).GetProperty("Parent"), pm => pm.Access(Accessor.Field));
            component.Parent.access.Should().Contain("field");
        }
コード例 #8
0
        public void CanSetLazy()
        {
            var mapdoc    = new HbmMapping();
            var component = new HbmComponent();
            var mapper    = new ComponentMapper(component, typeof(Name), ConfOrm.ForClass <Person> .Property(p => p.Name), mapdoc);

            mapper.Lazy(true);
            component.lazy.Should().Be.True();
        }
コード例 #9
0
        public void CanSetOptimisticLock()
        {
            var mapdoc    = new HbmMapping();
            var component = new HbmComponent();
            var mapper    = new ComponentMapper(component, typeof(Name), ConfOrm.ForClass <Person> .Property(p => p.Name), mapdoc);

            mapper.OptimisticLock(false);
            component.optimisticlock.Should().Be.False();
        }
コード例 #10
0
        public void CanSetInsert()
        {
            var mapdoc    = new HbmMapping();
            var component = new HbmComponent();
            var mapper    = new ComponentMapper(component, typeof(Name), ConfOrm.ForClass <Person> .Property(p => p.Name), mapdoc);

            mapper.Insert(false);
            component.insert.Should().Be.False();
        }
コード例 #11
0
        public void Component(MemberInfo property, Action <IComponentMapper> mapping)
        {
            var hbm = new HbmComponent {
                name = property.Name
            };

            mapping(new ComponentMapper(hbm, property.GetPropertyOrFieldType(), new NoMemberPropertyMapper(), MapDoc));
            AddProperty(hbm);
        }
コード例 #12
0
        public void CanAddSimpleProperty()
        {
            var mapping = new HbmMapping();
            var hbm     = new HbmComponent();
            var map     = new ComponentMapper <Address>(mapping, hbm);

            map.Property(address => address.City);
            hbm.Items.Should().Have.Count.EqualTo(1);
            hbm.Items.First().Should().Be.OfType <HbmProperty>().And.ValueOf.Name.Should().Be.EqualTo("City");
        }
コード例 #13
0
        public void WhenDefaultNamespaceAndDefaultAssemblyAssignComponentClassName()
        {
            var mapping = new HbmMapping {
                assembly = typeof(Address).Assembly.GetName().Name, @namespace = typeof(Address).Namespace
            };
            var hbm = new HbmComponent();

            new ComponentMapper <Address>(mapping, hbm);
            hbm.Class.Should().Be.EqualTo("Address");
        }
コード例 #14
0
        public void CallingParentSetTheParentNode()
        {
            var mapdoc    = new HbmMapping();
            var component = new HbmComponent();
            var mapper    = new ComponentMapper(component, typeof(Name), ConfOrm.ForClass <Person> .Property(p => p.Name), mapdoc);

            mapper.Parent(typeof(Address).GetProperty("Parent"));
            component.Parent.Should().Not.Be.Null();
            component.Parent.name.Should().Be.EqualTo("Parent");
        }
コード例 #15
0
            public void Should_get_the_correct_value()
            {
                const string expected  = "System.String";
                HbmComponent component = new HbmComponent
                {
                    @class = expected + ", mscorlib"
                };
                string result = component.GetReturnType();

                result.ShouldBeEqualTo(expected);
            }
コード例 #16
0
            public void Should_get_the_correct_value()
            {
                const string expected  = "FirstName";
                HbmComponent component = new HbmComponent
                {
                    name = expected
                };
                string result = component.GetPropertyName();

                result.ShouldBeEqualTo(expected);
            }
コード例 #17
0
        public void WhenMapDocHasDefaultHasClassName()
        {
            var entityType = typeof(Person);
            var mapdoc     = new HbmMapping {
                assembly = entityType.Assembly.FullName, @namespace = entityType.Namespace
            };
            var component = new HbmComponent();

            new ComponentMapper(component, typeof(Name), ConfOrm.ForClass <Person> .Property(p => p.Name), mapdoc);
            component.Class.Should().Be.EqualTo(typeof(Name).Name);
        }
コード例 #18
0
        public void Component <TComponent>(Expression <Func <TEntity, TComponent> > property,
                                           Action <IComponentMapper <TComponent> > mapping) where TComponent : class
        {
            var memberInfo = TypeUtils.DecodeMemberAccessExpression(property);
            var hbm        = new HbmComponent {
                name = memberInfo.Name
            };

            mapping(new ComponentMapper <TComponent>(MapDoc, hbm));
            AddProperty(hbm);
        }
コード例 #19
0
        public virtual void Component(MemberInfo property, Action <IComponentMapper> mapping)
        {
            if (!IsMemberSupportedByMappedContainer(property))
            {
                throw new ArgumentOutOfRangeException("property", "Can't add a property of another graph");
            }
            var hbm = new HbmComponent {
                name = property.Name
            };

            mapping(new ComponentMapper(hbm, property.GetPropertyOrFieldType(), property, MapDoc));
            AddProperty(hbm);
        }
コード例 #20
0
 private void BindComponentProperty(HbmComponent componentMapping, Property property, Component model)
 {
     property.IsUpdateable = componentMapping.update;
     property.IsInsertable = componentMapping.insert;
     if (componentMapping.unique)
     {
         model.Owner.Table.CreateUniqueKey(model.ColumnIterator.OfType <Column>().ToList());
     }
     HbmTuplizer[] tuplizers = componentMapping.tuplizer;
     if (tuplizers != null)
     {
         Array.ForEach(tuplizers.Select(tuplizer => new
         {
             TuplizerClassName = FullQualifiedClassName(tuplizer.@class, mappings),
             Mode = tuplizer.entitymode.ToEntityMode()
         }).ToArray(),
                       x => model.AddTuplizer(x.Mode, x.TuplizerClassName));
     }
 }
コード例 #21
0
 private void BindComponentProperty(HbmComponent componentMapping, Property property, Component model)
 {
     property.IsUpdateable = componentMapping.update;
     property.IsInsertable = componentMapping.insert;
     if (componentMapping.unique)
     {
         model.Owner.Table.CreateUniqueKey(model.ColumnIterator.OfType <Column>().ToList());
     }
     HbmTuplizer[] tuplizers = componentMapping.tuplizer;
     if (tuplizers != null)
     {
         foreach (var tuplizer in tuplizers)
         {
             var mode = tuplizer.entitymode.ToEntityMode();
             var tuplizerClassName = FullQualifiedClassName(tuplizer.@class, mappings);
             model.AddTuplizer(mode, tuplizerClassName);
         }
     }
 }
コード例 #22
0
 public static string GetPropertyName(this HbmComponent item)
 {
     return(item.name);
 }
コード例 #23
0
 public ComponentMapper(HbmComponent component, System.Type componentType, MemberInfo declaringTypeMember, HbmMapping mapDoc)
     : this(component, componentType, new AccessorPropertyMapper(declaringTypeMember.DeclaringType, declaringTypeMember.Name, x => component.access = x), mapDoc)
 {
 }
コード例 #24
0
 public ComponentMapper(HbmMapping mapping, HbmComponent component) : base(mapping)
 {
     this.component   = component;
     component.@class = GetClassName();
 }
コード例 #25
0
 public static string GetReturnType(this HbmComponent item)
 {
     return(item.@class?.GetTypeName());
 }