Beispiel #1
0
            /// <summary>
            /// Creates a reference object which must be passed to the SwissQrCode instance
            /// </summary>
            /// <param name="referenceType">Type of the reference (QRR, SCOR or NON)</param>
            /// <param name="reference">Reference text</param>
            /// <param name="referenceTextType">Type of the reference text (QR-reference or Creditor Reference)</param>
            /// <param name="unstructuredMessage">Unstructured message</param>
            public Reference(ReferenceType referenceType, string reference = null, ReferenceTextType?referenceTextType = null, string unstructuredMessage = null)
            {
                this.referenceType     = referenceType;
                this.referenceTextType = referenceTextType;

                if (referenceType.Equals(ReferenceType.NON) && reference != null)
                {
                    throw new SwissQrCodeReferenceException("Reference is only allowed when referenceType not equals \"NON\"");
                }
                if (!referenceType.Equals(ReferenceType.NON) && reference != null && referenceTextType == null)
                {
                    throw new SwissQrCodeReferenceException("You have to set an ReferenceTextType when using the reference text.");
                }
                if (referenceTextType.Equals(ReferenceTextType.QrReference) && reference != null && (reference.Length > 27))
                {
                    throw new SwissQrCodeReferenceException("QR-references have to be shorter than 28 chars.");
                }
                if (referenceTextType.Equals(ReferenceTextType.QrReference) && reference != null && !Regex.IsMatch(reference, @"^[0-9]+$"))
                {
                    throw new SwissQrCodeReferenceException("QR-reference must exist out of digits only.");
                }
                if (referenceTextType.Equals(ReferenceTextType.QrReference) && reference != null && !ChecksumMod10(reference))
                {
                    throw new SwissQrCodeReferenceException("QR-references is invalid. Checksum error.");
                }
                if (referenceTextType.Equals(ReferenceTextType.CreditorReferenceIso11649) && reference != null && (reference.Length > 25))
                {
                    throw new SwissQrCodeReferenceException("Creditor references (ISO 11649) have to be shorter than 26 chars.");
                }

                this.reference = reference;

                if (unstructuredMessage != null && (unstructuredMessage.Length > 140))
                {
                    throw new SwissQrCodeReferenceException("The unstructured message must be shorter than 141 chars.");
                }
                this.unstructuredMessage = unstructuredMessage;
            }