コード例 #1
0
        private ITypeMember Resolve(int index, Context context)
        {
            var row = _loader.Metadata.GetRow(TableId.MemberRef, index);

            string name    = row[Schema.MemberRef.Name].String;
            var    sigBlob = row[Schema.MemberRef.Signature].Blob;
            var    sig     = MetadataSignature.DecodeMember(sigBlob);

            SimpleIndex ownerIndex = row[Schema.MemberRef.Class].Value;
            var         owner      = ResolveOwner(ownerIndex, context);

            var member = FindMember(owner, name, sig, context);

            if (member == null)
            {
                //TODO: Report warning
#if DEBUG
                if (DebugHooks.BreakInvalidMemberReference)
                {
                    Debugger.Break();
                    FindMember(owner, name, sig, context);
                }
#endif
                throw new BadMetadataException(string.Format("Unable to resolve member ref {0}", ownerIndex));
            }

            return(member);
        }
コード例 #2
0
        /// <summary>
        /// Sign pdf document with metadata signature
        /// </summary>
        public static void Run()
        {
            Console.WriteLine("\n--------------------------------------------------------------------------------------------------------------------");
            Console.WriteLine("[Example Advanced Usage] # SignPdfWithStandardMetadata : Sign pdf document with metadata signature\n");

            // The path to the documents directory.
            string filePath = Constants.SAMPLE_PDF;
            string fileName = Path.GetFileName(filePath);

            string outputFilePath = Path.Combine(Constants.OutputPath, "SignPdfWithStandardMetadata", fileName);

            using (Signature signature = new Signature(filePath))
            {
                // setup options with text of signature
                MetadataSignOptions options = new MetadataSignOptions();

                // Using standard Pdf Metadata Signatures with new values
                MetadataSignature[] signatures = new MetadataSignature[]
                {
                    PdfMetadataSignatures.Author.Clone("Mr.Scherlock Holmes"),
                    PdfMetadataSignatures.CreateDate.Clone(DateTime.Now.AddDays(-1)),
                    PdfMetadataSignatures.MetadataDate.Clone(DateTime.Now.AddDays(-2)),
                    PdfMetadataSignatures.CreatorTool.Clone("GD.Signature-Test"),
                    PdfMetadataSignatures.ModifyDate.Clone(DateTime.Now.AddDays(-13)),
                    PdfMetadataSignatures.Producer.Clone("GroupDocs-Producer"),
                    PdfMetadataSignatures.Entry.Clone("Signature"),
                    PdfMetadataSignatures.Keywords.Clone("GroupDocs, Signature, Metadata, Creation Tool"),
                    PdfMetadataSignatures.Title.Clone("Metadata Example"),
                    PdfMetadataSignatures.Subject.Clone("Metadata Test Example"),
                    PdfMetadataSignatures.Description.Clone("Metadata Test example description"),
                    PdfMetadataSignatures.Creator.Clone("GroupDocs.Signature"),
                };
                options.Signatures.AddRange(signatures);

                // sign document to file
                SignResult signResult = signature.Sign(outputFilePath, options);
                Console.WriteLine($"\nSource document signed successfully with {signResult.Succeeded.Count} signature(s).\nFile saved at {outputFilePath}.");
            }
        }
コード例 #3
0
        private ITypeMember FindMember(IType type, string name, MetadataSignature sig, Context context)
        {
            if (type == null)
            {
                return(null);
            }

            //special multidimensional array methods
            if (type.IsArray)
            {
                switch (name)
                {
                case CLRNames.Constructor:
                    return(CreateArrayCtor(new Context(type, context.Method), (MethodSignature)sig));

                case CLRNames.Array.Getter:
                    return(GetArrayGetter(new Context(type, context.Method), (MethodSignature)sig));

                case CLRNames.Array.Address:
                    return(GetArrayAddress(new Context(type, context.Method), (MethodSignature)sig));

                case CLRNames.Array.Setter:
                    return(GetArraySetter(new Context(type, context.Method), (MethodSignature)sig));
                }
            }

            IType[]    types = null;
            MemberType kind;

            var typeContext = new Context(type, context != null && context.IsGeneric);

            switch (sig.Kind)
            {
            case SignatureKind.Field:
                kind = MemberType.Field;
                break;

            case SignatureKind.Method:
                return(FindMethod(type, name, (MethodSignature)sig, typeContext));

            case SignatureKind.Property:
                types = ResolveMethodSignature((MethodSignature)sig, typeContext, true);
                kind  = MemberType.Property;
                break;

            default:
                throw new BadSignatureException(string.Format("Invalid member signature {0}", sig));
            }

            while (type != null)
            {
                var member = FindMember(type, kind, name, types);
                if (member != null)
                {
                    return(member);
                }
                type = type.BaseType;
            }

            return(null);
        }