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;
		}
示例#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);
			}
		}
示例#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;
 }
示例#4
0
 private CollectionMemberInfoMetadata CreateCollectionPropertyInfoMetadata(MemberInfoMetadata memberInfoMetadata)
 {
     return(new CollectionMemberInfoMetadata(memberInfoMetadata));
 }
示例#5
0
 private ReferenceMemberInfoMetadata CreateReferencePropertyInfoMetadata(MemberInfoMetadata memberInfoMetadata)
 {
     return(new ReferenceMemberInfoMetadata(memberInfoMetadata));
 }
示例#6
0
 private PrimitiveMemberInfoMetadata CreatePrimitivePropertyInfoMetadata(MemberInfoMetadata memberInfoMetadata)
 {
     return(new PrimitiveMemberInfoMetadata(memberInfoMetadata));
 }
示例#7
0
 private bool CustomStrategy(IMemberStrategy memberStrategy, MemberInfoMetadata member)
 {
     return
         ((memberStrategy == null) || memberStrategy.HasToMap(member));
 }