public Evidence(Evidence evidence)
 {
     this.m_evidence = new Dictionary <Type, EvidenceTypeDescriptor>();
     if (evidence != null)
     {
         using (new EvidenceLockHolder(evidence, EvidenceLockHolder.LockType.Reader))
         {
             foreach (KeyValuePair <Type, EvidenceTypeDescriptor> pair in evidence.m_evidence)
             {
                 EvidenceTypeDescriptor descriptor = pair.Value;
                 if (descriptor != null)
                 {
                     descriptor = descriptor.Clone();
                 }
                 this.m_evidence[pair.Key] = descriptor;
             }
             this.m_target = evidence.m_target;
             this.m_locked = evidence.m_locked;
             this.m_deserializedTargetEvidence = evidence.m_deserializedTargetEvidence;
             if (evidence.Target != null)
             {
                 this.m_cloneOrigin = new WeakReference(evidence);
             }
         }
     }
     this.m_evidenceLock = new ReaderWriterLock();
 }
        private EvidenceTypeDescriptor GetEvidenceTypeDescriptor(Type evidenceType, bool addIfNotExist)
        {
            EvidenceTypeDescriptor descriptor = null;

            if (!this.m_evidence.TryGetValue(evidenceType, out descriptor) && !addIfNotExist)
            {
                return(null);
            }
            if (descriptor == null)
            {
                descriptor = new EvidenceTypeDescriptor();
                bool       flag       = false;
                LockCookie lockCookie = new LockCookie();
                try
                {
                    if (!this.IsWriterLockHeld)
                    {
                        lockCookie = this.UpgradeToWriterLock();
                        flag       = true;
                    }
                    this.m_evidence[evidenceType] = descriptor;
                }
                finally
                {
                    if (flag)
                    {
                        this.DowngradeFromWriterLock(ref lockCookie);
                    }
                }
            }
            return(descriptor);
        }
            private static Type[] GenerateEvidenceTypes(Evidence evidence, IEnumerable <Type> evidenceTypes, bool hostEvidence)
            {
                List <Type> list  = new List <Type>();
                List <Type> list2 = new List <Type>();
                List <Type> list3 = new List <Type>(ExpensiveEvidence.Count);

                foreach (Type type in evidenceTypes)
                {
                    EvidenceTypeDescriptor evidenceTypeDescriptor = evidence.GetEvidenceTypeDescriptor(type);
                    if ((hostEvidence && (evidenceTypeDescriptor.HostEvidence != null)) || (!hostEvidence && (evidenceTypeDescriptor.AssemblyEvidence != null)))
                    {
                        list.Add(type);
                    }
                    else if (ExpensiveEvidence.Contains(type))
                    {
                        list3.Add(type);
                    }
                    else
                    {
                        list2.Add(type);
                    }
                }
                Type[] array = new Type[(list.Count + list2.Count) + list3.Count];
                list.CopyTo(array, 0);
                list2.CopyTo(array, list.Count);
                list3.CopyTo(array, list.Count + list2.Count);
                return(array);
            }
        private EvidenceBase GetAssemblyEvidenceNoLock(Type type)
        {
            this.DeserializeTargetEvidence();
            EvidenceTypeDescriptor evidenceTypeDescriptor = this.GetEvidenceTypeDescriptor(type);

            if (evidenceTypeDescriptor != null)
            {
                return(evidenceTypeDescriptor.AssemblyEvidence);
            }
            return(null);
        }
Esempio n. 5
0
 // Token: 0x0600292C RID: 10540 RVA: 0x0009817C File Offset: 0x0009637C
 private EvidenceTypeDescriptor(EvidenceTypeDescriptor descriptor)
 {
     this.m_hostCanGenerate = descriptor.m_hostCanGenerate;
     if (descriptor.m_assemblyEvidence != null)
     {
         this.m_assemblyEvidence = descriptor.m_assemblyEvidence.Clone();
     }
     if (descriptor.m_hostEvidence != null)
     {
         this.m_hostEvidence = descriptor.m_hostEvidence.Clone();
     }
 }
 private EvidenceTypeDescriptor(EvidenceTypeDescriptor descriptor)
 {
     this.m_hostCanGenerate = descriptor.m_hostCanGenerate;
     if (descriptor.m_assemblyEvidence != null)
     {
         this.m_assemblyEvidence = descriptor.m_assemblyEvidence.Clone();
     }
     if (descriptor.m_hostEvidence != null)
     {
         this.m_hostEvidence = descriptor.m_hostEvidence.Clone();
     }
 }
 private bool WasStrongNameEvidenceUsed()
 {
     using (new EvidenceLockHolder(this, EvidenceLockHolder.LockType.Reader))
     {
         EvidenceTypeDescriptor evidenceTypeDescriptor = this.GetEvidenceTypeDescriptor(typeof(StrongName));
         if (evidenceTypeDescriptor != null)
         {
             IDelayEvaluatedEvidence hostEvidence = evidenceTypeDescriptor.HostEvidence as IDelayEvaluatedEvidence;
             return((hostEvidence != null) && hostEvidence.WasUsed);
         }
         return(false);
     }
 }
        private void AddHostEvidenceNoLock(EvidenceBase evidence, Type evidenceType, DuplicateEvidenceAction duplicateAction)
        {
            EvidenceTypeDescriptor evidenceTypeDescriptor = this.GetEvidenceTypeDescriptor(evidenceType, true);

            this.m_version++;
            if (evidenceTypeDescriptor.HostEvidence == null)
            {
                evidenceTypeDescriptor.HostEvidence = evidence;
            }
            else
            {
                evidenceTypeDescriptor.HostEvidence = HandleDuplicateEvidence(evidenceTypeDescriptor.HostEvidence, evidence, duplicateAction);
            }
        }
        private void AddAssemblyEvidenceNoLock(EvidenceBase evidence, Type evidenceType, DuplicateEvidenceAction duplicateAction)
        {
            this.DeserializeTargetEvidence();
            EvidenceTypeDescriptor evidenceTypeDescriptor = this.GetEvidenceTypeDescriptor(evidenceType, true);

            this.m_version++;
            if (evidenceTypeDescriptor.AssemblyEvidence == null)
            {
                evidenceTypeDescriptor.AssemblyEvidence = evidence;
            }
            else
            {
                evidenceTypeDescriptor.AssemblyEvidence = HandleDuplicateEvidence(evidenceTypeDescriptor.AssemblyEvidence, evidence, duplicateAction);
            }
        }
        /// <summary>
        ///     Make a deep copy of a type descriptor
        /// </summary>
        private EvidenceTypeDescriptor(EvidenceTypeDescriptor descriptor)
        {
            Contract.Assert(descriptor != null);

            m_hostCanGenerate = descriptor.m_hostCanGenerate;

            if (descriptor.m_assemblyEvidence != null)
            {
                m_assemblyEvidence = descriptor.m_assemblyEvidence.Clone() as EvidenceBase;
            }
            if (descriptor.m_hostEvidence != null)
            {
                m_hostEvidence = descriptor.m_hostEvidence.Clone() as EvidenceBase;
            }

#if _DEBUG
            m_evidenceType = descriptor.m_evidenceType;
#endif // _DEBUG
        }
Esempio n. 11
0
        /// <summary>
        ///     Make a deep copy of a type descriptor
        /// </summary>
        private EvidenceTypeDescriptor(EvidenceTypeDescriptor descriptor)
        {
            Contract.Assert(descriptor != null);

            m_hostCanGenerate = descriptor.m_hostCanGenerate;

            if (descriptor.m_assemblyEvidence != null)
            {
                m_assemblyEvidence = descriptor.m_assemblyEvidence.Clone() as EvidenceBase;
            }
            if (descriptor.m_hostEvidence != null)
            {
                m_hostEvidence = descriptor.m_hostEvidence.Clone() as EvidenceBase;
            }

#if _DEBUG
            m_evidenceType = descriptor.m_evidenceType;
#endif // _DEBUG
        }
 public void RemoveType(Type t)
 {
     if (t == null)
     {
         throw new ArgumentNullException("t");
     }
     using (new EvidenceLockHolder(this, EvidenceLockHolder.LockType.Writer))
     {
         EvidenceTypeDescriptor evidenceTypeDescriptor = this.GetEvidenceTypeDescriptor(t);
         if (evidenceTypeDescriptor != null)
         {
             this.m_version++;
             if (this.Locked && ((evidenceTypeDescriptor.HostEvidence != null) || evidenceTypeDescriptor.HostCanGenerate))
             {
                 new SecurityPermission(SecurityPermissionFlag.ControlEvidence).Demand();
             }
             this.m_evidence.Remove(t);
         }
     }
 }
        private EvidenceBase GetHostEvidenceNoLock(Type type)
        {
            EvidenceTypeDescriptor evidenceTypeDescriptor = this.GetEvidenceTypeDescriptor(type);

            if (evidenceTypeDescriptor != null)
            {
                if (evidenceTypeDescriptor.HostEvidence != null)
                {
                    return(evidenceTypeDescriptor.HostEvidence);
                }
                if ((this.m_target != null) && !evidenceTypeDescriptor.Generated)
                {
                    using (new EvidenceUpgradeLockHolder(this))
                    {
                        evidenceTypeDescriptor.Generated = true;
                        EvidenceBase base2 = this.GenerateHostEvidence(type, evidenceTypeDescriptor.HostCanGenerate);
                        if (base2 != null)
                        {
                            evidenceTypeDescriptor.HostEvidence = base2;
                            Evidence target = (this.m_cloneOrigin != null) ? (this.m_cloneOrigin.Target as Evidence) : null;
                            if (target == null)
                            {
                                return(base2);
                            }
                            using (new EvidenceLockHolder(target, EvidenceLockHolder.LockType.Writer))
                            {
                                EvidenceTypeDescriptor descriptor2 = target.GetEvidenceTypeDescriptor(type);
                                if ((descriptor2 != null) && (descriptor2.HostEvidence == null))
                                {
                                    descriptor2.HostEvidence = base2.Clone();
                                }
                            }
                        }
                        return(base2);
                    }
                }
            }
            return(null);
        }