コード例 #1
0
        /// <summary>
        /// Gets the loan field with the specified <paramref name="fieldId"/>.
        /// </summary>
        /// <param name="fieldId">The field id of the loan field to get. Borrower pair specified fields are supported, e.g. "4000#2".</param>
        /// <returns></returns>
        public LoanField this[string fieldId]
        {
            get
            {
                Preconditions.NotNullOrEmpty(fieldId, nameof(fieldId));

                FieldDescriptor descriptor;
                int?            borrowerPairIndex = null;
                ModelPath?      modelPath         = null;
                if (fieldId.Length > 2 && fieldId[fieldId.Length - 2] == '#')
                {
                    borrowerPairIndex = fieldId[fieldId.Length - 1] - '1';
                    if (borrowerPairIndex < 0 || borrowerPairIndex > 5)
                    {
                        throw new ArgumentException($"Could not find field '{fieldId}'");
                    }

                    var strippedFieldId = fieldId.Substring(0, fieldId.Length - 2);

                    descriptor = LoanFieldDescriptors.GetFieldDescriptor(strippedFieldId, _loan.Client?.Loans.FieldDescriptors.CustomFields, UndefinedCustomFieldHandling.Default);

                    if (!descriptor.IsBorrowerPairSpecific)
                    {
                        throw new ArgumentException($"Could not find field '{fieldId}'");
                    }

                    modelPath = LoanFieldDescriptors.CreateModelPath($"Loan.Applications[(ApplicationIndex == '{borrowerPairIndex}')]{descriptor.ModelPath.Substring(23)}");
                }
                else
                {
                    descriptor = LoanFieldDescriptors.GetFieldDescriptor(fieldId, _loan.Client?.Loans.FieldDescriptors.CustomFields, _loan.Client?.UndefinedCustomFieldHandling ?? UndefinedCustomFieldHandling.Default);
                }

                switch (descriptor.Type)
                {
                case LoanFieldType.Custom:
                    return(new CustomLoanField(descriptor, _loan));

                case LoanFieldType.Virtual:
                    return(new VirtualLoanField(descriptor, _loan));

                default:
                    return(new LoanField(descriptor, _loan, modelPath, borrowerPairIndex));
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Creates an instance descriptor with the specified <paramref name="instanceSpecifier"/>.
        /// </summary>
        /// <param name="instanceSpecifier">The instance specifier for an instance field descriptor.</param>
        /// <returns></returns>
        public FieldDescriptor GetInstanceDescriptor(string instanceSpecifier)
        {
            Preconditions.NotNullOrEmpty(instanceSpecifier, nameof(instanceSpecifier));

            if (!MultiInstance)
            {
                throw new InvalidOperationException("field must be multi-instance to retrieve an instance descriptor");
            }
            if (IsInstance)
            {
                throw new InvalidOperationException("cannot retrieve an instance descriptor of an instance descriptor");
            }

            var formatArg       = int.TryParse(instanceSpecifier, NumberStyles.None, null, out var i) ? (object)i : instanceSpecifier;
            var modelPathString = string.Format(ModelPath, formatArg);

            return(new FieldDescriptor(string.Format(FieldId, formatArg), LoanFieldDescriptors.CreateModelPath(modelPathString), modelPathString, string.Format(Description, formatArg), MultiInstance, instanceSpecifier, this));
        }