示例#1
0
        private MemberInfo GetMemberInfo(Type sourceType, Type projectedType, ProjectedMember projectedMember)
        {
            if (projectedMember == null)
            {
                return(null);
            }

            if (projectedMember is StringProjectedMember stringProjectedMember)
            {
                var memberInfo = projectedType
                                 .GetMembers(BindingFlags.Instance | BindingFlags.Public)
                                 .FirstOrDefault(x => x.Name == stringProjectedMember.MemberName);

                if (memberInfo == null)
                {
                    throw new InvalidOperationException($"Member {stringProjectedMember.MemberName} not found in type {sourceType.Name}");
                }

                if (memberInfo.MemberType != MemberTypes.Property && memberInfo.MemberType != MemberTypes.Field)
                {
                    throw new InvalidOperationException("The expession is not a field or property expression");
                }

                return(memberInfo);
            }
            else if (projectedMember is LambdaExpressionProjectedMember lambdaExpressionProjectedMember)
            {
                if (lambdaExpressionProjectedMember.PropertyExpression.Body is MemberExpression memberExpression &&
                    memberExpression.Expression.Type == sourceType)
                {
                    return(memberExpression.Member);
                }
                else
                {
                    throw new InvalidOperationException("The expession is not a valid member expression");
                }
            }
示例#2
0
 public MemberTargetConfiguration(ProjectedMember projectedMember)
 {
     ProjectedMember = projectedMember;
 }