Cilador.Fody.Core.ModuleWeaver.ExtractWeaveAttributesByTargetTypes C# (CSharp) Метод

ExtractWeaveAttributesByTargetTypes() приватный Метод

Looks at all types within the target assembly, and collects any that are annotated with weave attributes. Weave command attributes are removed from types as they are gathered.
private ExtractWeaveAttributesByTargetTypes ( ) : List>.Dictionary
Результат List>.Dictionary
        private Dictionary<TypeDefinition, List<CustomAttribute>> ExtractWeaveAttributesByTargetTypes()
        {
            Contract.Ensures(Contract.Result<Dictionary<TypeDefinition, List<CustomAttribute>>>().Keys.All(type => type != null));
            Contract.Ensures(!Contract.Result<Dictionary<TypeDefinition, List<CustomAttribute>>>().Values.Any(
                customAttributes => customAttributes == null || customAttributes.Any(customAttribute => customAttribute == null)));

            var weaveAttributeInterfaceType = this.ModuleDefinition.Import(typeof(IWeaveAttribute)).Resolve();

            var weaveAttributesByTargetTypes = new Dictionary<TypeDefinition, List<CustomAttribute>>();
            foreach (var type in this.ModuleDefinition.Types)
            {
                Contract.Assert(type != null);
                Contract.Assert(type.CustomAttributes != null);

                for (var i = type.CustomAttributes.Count - 1; i >= 0; i--)
                {
                    var attribute = type.CustomAttributes[i];
                    Contract.Assert(attribute != null);
                    var attributeTypeDefinition = attribute.AttributeType.Resolve();
                    Contract.Assert(attributeTypeDefinition != null);

                    foreach (var attributeInterfaceType in attributeTypeDefinition.Interfaces)
                    {
                        if (attributeInterfaceType.Resolve() == weaveAttributeInterfaceType)
                        {
                            List<CustomAttribute> weaveAttributesForType;
                            if (!weaveAttributesByTargetTypes.TryGetValue(type.Resolve(), out weaveAttributesForType))
                            {
                                weaveAttributesForType = new List<CustomAttribute>();
                                weaveAttributesByTargetTypes[type.Resolve()] = weaveAttributesForType;
                            }

                            weaveAttributesForType.Add(attribute);
                            type.CustomAttributes.RemoveAt(i);
                        }
                    }
                }
            }
            return weaveAttributesByTargetTypes;
        }