public static bool IsRequired(this MemberInfo memberInfo)
		{
			var memberMetadata = new MemberInfoMetadata(memberInfo);

			var isRequired =
				memberInfo
					.GetAttribute<RequiredAttribute>()
					.IsNotNull();

			if (memberMetadata.Type.IsNullable() && isRequired)
			{
				const string MessageFormat =
					"Member '{MemberName}' of type '{Type}' declared in '{DeclaringType}' cannot " +
					"have Required attribute because it is a nullable type.";

				var message =
					MessageFormat
					.NamedFormat(
						memberMetadata.Name,
						memberMetadata.Type.FriendlyShortName(),
						memberMetadata.DeclaringType.FullName);

				new ArgumentException(message)
					.Throw();
			}

			return
				isRequired;
		}
Ejemplo n.º 2
0
		public static void SetAccessor(MemberInfoMetadata member, IAccessorPropertyMapper m)
		{
			if (member.Accessor == Accessors.Field)
			{
				m.Access(AccessorHelper.Translate(member.Accessor));
			}

			if (member.MemberType == MemberTypes.Property)
			{
				m.Access(Accessor.Property);
			}
		}
Ejemplo n.º 3
0
 internal MappedType(
     Type sourceType,
     Type mappedType,
     KeyMemberInfoMetadata key,
     MemberInfoMetadata version,
     IEnumerable <PrimitiveMemberInfoMetadata> primitives,
     IEnumerable <ReferenceMemberInfoMetadata> references,
     IEnumerable <CollectionMemberInfoMetadata> collections)
 {
     Source      = sourceType;
     Mapped      = mappedType;
     Key         = key;
     Version     = version;
     Primitives  = primitives;
     References  = references;
     Collections = collections;
 }
Ejemplo n.º 4
0
 private CollectionMemberInfoMetadata CreateCollectionPropertyInfoMetadata(MemberInfoMetadata memberInfoMetadata)
 {
     return(new CollectionMemberInfoMetadata(memberInfoMetadata));
 }
Ejemplo n.º 5
0
 private ReferenceMemberInfoMetadata CreateReferencePropertyInfoMetadata(MemberInfoMetadata memberInfoMetadata)
 {
     return(new ReferenceMemberInfoMetadata(memberInfoMetadata));
 }
Ejemplo n.º 6
0
 private PrimitiveMemberInfoMetadata CreatePrimitivePropertyInfoMetadata(MemberInfoMetadata memberInfoMetadata)
 {
     return(new PrimitiveMemberInfoMetadata(memberInfoMetadata));
 }
Ejemplo n.º 7
0
 private bool CustomStrategy(IMemberStrategy memberStrategy, MemberInfoMetadata member)
 {
     return
         ((memberStrategy == null) || memberStrategy.HasToMap(member));
 }