Microsoft.Xades.XadesSignedXml.BuildDigestedReferences C# (CSharp) Method

BuildDigestedReferences() private method

Copy of System.Security.Cryptography.Xml.SignedXml.BuildDigestedReferences() which will add a "ds" namespace prefix to all XmlDsig nodes
private BuildDigestedReferences ( ) : void
return void
        private void BuildDigestedReferences()
        {
            ArrayList references = this.SignedInfo.References;

            //this.m_refProcessed = new bool[references.Count];
            Type SignedXml_Type = typeof(SignedXml);
            FieldInfo SignedXml_m_refProcessed = SignedXml_Type.GetField("m_refProcessed", BindingFlags.NonPublic | BindingFlags.Instance);
            SignedXml_m_refProcessed.SetValue(this, new bool[references.Count]);
            //

            //this.m_refLevelCache = new int[references.Count];
            FieldInfo SignedXml_m_refLevelCache = SignedXml_Type.GetField("m_refLevelCache", BindingFlags.NonPublic | BindingFlags.Instance);
            SignedXml_m_refLevelCache.SetValue(this, new int[references.Count]);
            //

            //ReferenceLevelSortOrder comparer = new ReferenceLevelSortOrder();
            Assembly System_Security_Assembly = Assembly.Load("System.Security, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a");
            Type ReferenceLevelSortOrder_Type = System_Security_Assembly.GetType("System.Security.Cryptography.Xml.SignedXml+ReferenceLevelSortOrder");
            ConstructorInfo ReferenceLevelSortOrder_Constructor = ReferenceLevelSortOrder_Type.GetConstructor(new Type[] { });
            Object comparer = ReferenceLevelSortOrder_Constructor.Invoke(null);
            //

            //comparer.References = references;
            PropertyInfo ReferenceLevelSortOrder_References = ReferenceLevelSortOrder_Type.GetProperty("References", BindingFlags.Public | BindingFlags.Instance);
            ReferenceLevelSortOrder_References.SetValue(comparer, references, null);
            //

            ArrayList list2 = new ArrayList();
            foreach (Reference reference in references)
            {
                list2.Add(reference);
            }

            list2.Sort((IComparer)comparer);

            //CanonicalXmlNodeList refList = new CanonicalXmlNodeList();
            Type CanonicalXmlNodeList_Type = System_Security_Assembly.GetType("System.Security.Cryptography.Xml.CanonicalXmlNodeList");
            ConstructorInfo CanonicalXmlNodeList_Constructor = CanonicalXmlNodeList_Type.GetConstructor(BindingFlags.NonPublic | BindingFlags.Instance, null, new Type[] { }, null);
            Object refList = CanonicalXmlNodeList_Constructor.Invoke(null);
            //

            //
            MethodInfo CanonicalXmlNodeList_Add = CanonicalXmlNodeList_Type.GetMethod("Add", BindingFlags.Public | BindingFlags.Instance);
            //

            foreach (DataObject obj2 in this.m_signature.ObjectList)
            {
                //refList.Add(obj2.GetXml());
                XmlElement xml = obj2.GetXml();
                SetPrefix("ds", xml); // <---
                CanonicalXmlNodeList_Add.Invoke(refList, new object[] { xml });
                //
            }

            //
            FieldInfo SignedXml_m_containingDocument = SignedXml_Type.GetField("m_containingDocument", BindingFlags.NonPublic | BindingFlags.Instance);
            Type Reference_Type = typeof(Reference);
            MethodInfo Reference_UpdateHashValue = Reference_Type.GetMethod("UpdateHashValue", BindingFlags.NonPublic | BindingFlags.Instance);
            //

            foreach (Reference reference2 in list2)
            {
                if (reference2.DigestMethod == null)
                {
                    reference2.DigestMethod = "http://www.w3.org/2000/09/xmldsig#sha1";
                }
                //reference2.UpdateHashValue(this.m_containingDocument, refList);
                object m_containingDocument = SignedXml_m_containingDocument.GetValue(this);
                Reference_UpdateHashValue.Invoke(reference2, new object[] { m_containingDocument, refList });
                //

                if (reference2.Id != null)
                {
                    //refList.Add(reference2.GetXml());
                    XmlElement xml = reference2.GetXml();
                    SetPrefix("ds", xml); // <---
                    CanonicalXmlNodeList_Add.Invoke(refList, new object[] { xml });
                    //
                }
            }
        }