public T[] GetAttributes <T>(Type type, MemberInfo memberInfo, bool inherit) where T : Attribute { if (typeof(T) == typeof(ColumnAttribute)) { var attrs = _reader.GetAttributes <System.Data.Linq.Mapping.ColumnAttribute>(type, memberInfo, inherit); if (attrs.Length == 1) { var c = attrs[0]; var attr = new ColumnAttribute { Name = c.Name, DbType = c.DbType, CanBeNull = c.CanBeNull, Storage = c.Storage, SkipOnInsert = c.IsDbGenerated, SkipOnUpdate = c.IsDbGenerated }; return(new[] { (T)(Attribute)attr }); } } return(Array <T> .Empty); }
public void FieldAttribute() { var rd = new AttributeReader(); var attrs = rd.GetAttributes <ColumnAttribute>(MemberHelper.MemberOf <AttributeReaderTest>(a => a.Field1)); Assert.AreEqual(0, attrs.Length); }
public void FieldAttribute() { var rd = new AttributeReader(); var attrs = rd.GetAttributes<ColumnAttribute>(MemberHelper.MemberOf<AttributeReaderTest>(a => a.Field1)); Assert.AreEqual(0, attrs.Length); }
public void PropertyAttribute() { var rd = new AttributeReader(); var attrs = rd.GetAttributes <ColumnAttribute>(MemberHelper.MemberOf <AttributeReaderTest>(a => a.Property1)); Assert.NotNull(attrs); Assert.AreEqual(1, attrs.Length); Assert.AreEqual("TestName", attrs[0].Name); }
public void TypeAttribute() { var rd = new AttributeReader(); var attrs = rd.GetAttributes <TestFixtureAttribute>(typeof(AttributeReaderTest)); Assert.NotNull(attrs); Assert.AreEqual(1, attrs.Length); Assert.AreEqual(null, attrs[0].Description); }
public void PropertyAttribute() { var rd = new AttributeReader(); var attrs = rd.GetAttributes<ColumnAttribute>(MemberHelper.MemberOf<AttributeReaderTest>(a => a.Property1)); Assert.NotNull (attrs); Assert.AreEqual(1, attrs.Length); Assert.AreEqual("TestName", attrs[0].Name); }
public void TypeAttribute() { var rd = new AttributeReader(); var attrs = rd.GetAttributes<TestFixtureAttribute>(typeof(AttributeReaderTest)); Assert.NotNull (attrs); Assert.AreEqual(1, attrs.Length); Assert.AreEqual(null, attrs[0].Description); }
private IEnumerable <Tuple <Attributes.DimmensionX, MemberInfo> > GenerateAttributeList(Type type) { MemberInfo[] members = type.GetMembers(); // Get All necessary attributes and corresponding fields var attributeReader = new AttributeReader(); foreach (var member in members) { var attributesX = attributeReader.GetAttributes <Attributes.DimmensionX>(type, member); if (attributesX.Length > 0) { yield return(Tuple.Create(attributesX[0], member)); // add attribute itself and field name } } }