private void AddFaaAttributeIfNeeded(Element element, List<ICustomAttribute> attributes, ITypeReference containingType) { if (element != null && element.IsFriendAccessAllowed)//typeHasFaaAttribute(attributes, containingType)) { List<INamedTypeDefinition> types = new List<INamedTypeDefinition>(this.host.FindAssembly(this.host.CoreAssemblySymbolicIdentity).GetAllTypes()); if (types == null || !types.Any()) return; //Couldn't find any type on the assembly IEnumerable<INamedTypeDefinition> faaAttributeType = types.Where(t => t.Name.Value == "FriendAccessAllowedAttribute"); if (!faaAttributeType.Any()) return; //Unable to find the FriendAccessAllowedAttribute var faaAttributeResult = faaAttributeType.FirstOrDefault(); if (!Util.HasAttribute(attributes, faaAttributeResult)) { Microsoft.Cci.MethodReference faaCtor = new Microsoft.Cci.MethodReference(this.host, faaAttributeResult, CallingConvention.HasThis, this.host.PlatformType.SystemVoid, this.host.NameTable.Ctor, 0); CustomAttribute faaAttribute = new CustomAttribute(); faaAttribute.Constructor = faaCtor; attributes.Add(Rewrite(faaAttribute)); } } }
private void MutateType(INamedTypeDefinition iTypeDef, Element element) { NamedTypeDefinition typeDef = iTypeDef as NamedTypeDefinition; if (typeDef == null) throw new Exception("Invalid namedType definition."); if (_applyAnnotations) { SecurityTransparencyStatus currentStatus = GetMarkedSecurityAnnotation(typeDef.Attributes, typeDef); if (element.SecurityTransparencyStatus != SecurityTransparencyStatus.Undefined && element.SecurityTransparencyStatus != SecurityTransparencyStatus.Transparent && currentStatus != element.SecurityTransparencyStatus) { RemoveSecurityTransparencyAttributes(typeDef.Attributes, typeDef); AddSecurityTransparencyAttribute(typeDef.Attributes, element.SecurityTransparencyStatus, typeDef); } } AddFaaAttributeIfNeeded(element, typeDef.Attributes, typeDef); if (_changeVisibility && element.ShouldMakeInternal) { MakeInternal(typeDef); } }
private void MutateMember(TypeDefinitionMember member, Element element) { // Set transparency attributes. if (_applyAnnotations) { SecurityTransparencyStatus currentStatus = GetMarkedSecurityAnnotation(member.Attributes, member.ContainingTypeDefinition); if (element.SecurityTransparencyStatus != SecurityTransparencyStatus.Undefined && currentStatus != element.SecurityTransparencyStatus) { RemoveSecurityTransparencyAttributes(member.Attributes, member.ContainingTypeDefinition); AddSecurityTransparencyAttribute(member.Attributes, element.SecurityTransparencyStatus, member.ContainingTypeDefinition); } } // Add FriendAccessAllowed attribute. if (!(member is PropertyDefinition)) // FAA isn't needed on properties; it's only needed on getters and setters { List<ICustomAttribute> attributes = member.Attributes; AddFaaAttributeIfNeeded(element, attributes, member.ContainingTypeDefinition); } // Make internal if needed. if (_changeVisibility && element.ShouldMakeInternal && !Util.IsInternal(member.ResolvedTypeDefinitionMember.Visibility)) { // Make the member internal MakeInternal(member); // Interface method implementations don't need Explicit Interface Method Implementations (EIMI's) if the implementing // method is public and has the same signature as the interface method. Since we're making the method internal, // we need to add the EIMI's. CreateExplicitInterfaceImplementations(member); } }