private bool WriteSecurityAttribute(ModuleDefinition module, bool isAssemblyDeclaration, SecurityAttribute attribute, SecurityDeclaration securityDeclaration, out bool wroteArgument) { genericWriter.WriteToken(OpeningBracket); if (isAssemblyDeclaration) { genericWriter.WriteKeyword(genericWriter.KeyWordWriter.Assembly); genericWriter.Write(":"); genericWriter.WriteSpace(); } string attributeName = attribute.AttributeType.Name.EndsWith("Attribute") ? attribute.AttributeType.Name.Remove(attribute.AttributeType.Name.LastIndexOf("Attribute")) : attribute.AttributeType.Name; genericWriter.WriteNamespaceIfTypeInCollision(attribute.AttributeType); genericWriter.WriteReference(attributeName, attribute.AttributeType); genericWriter.WriteToken("("); TypeReference securityActionTypeReference = securityDeclaration.GetSecurityActionTypeReference(module); TypeDefinition argumentTypeDefinition = securityActionTypeReference.IsDefinition ? securityActionTypeReference as TypeDefinition : securityActionTypeReference.Resolve(); if (argumentTypeDefinition != null && argumentTypeDefinition.IsEnum) { List <FieldDefinition> fields = EnumValueToFieldCombinationMatcher.GetEnumFieldDefinitionByValue(argumentTypeDefinition.Fields, (int)securityDeclaration.Action, argumentTypeDefinition.CustomAttributes); if (fields.Count != 0) { for (int i = 0; i < fields.Count; i++) { genericWriter.WriteReferenceAndNamespaceIfInCollision(fields[i].DeclaringType); genericWriter.WriteToken("."); genericWriter.WriteEnumValueField(fields[i]); if (i + 1 < fields.Count) { genericWriter.WriteSpace(); genericWriter.WriteBitwiseOr(); genericWriter.WriteSpace(); } } } else { WriteSecurityAttributeAction(securityDeclaration.Action); } } wroteArgument = true; if (attribute.HasFields || attribute.HasProperties) { var attributeType = attribute.AttributeType.Resolve(); if (attribute.HasProperties) { wroteArgument = WriteAttributeNamedArgs(attributeType, attribute.Properties, false, wroteArgument); } if (attribute.HasFields) { WriteAttributeNamedArgs(attributeType, attribute.Fields, true, wroteArgument); } } genericWriter.WriteToken(")"); genericWriter.WriteToken(ClosingBracket); genericWriter.WriteLine(); return(wroteArgument); }
private bool WriteSecurityAttribute(ModuleDefinition module, bool isAssemblyDeclaration, SecurityAttribute attribute, SecurityDeclaration securityDeclaration, out bool wroteArgument, bool skipTheNewLine = false, bool isReturnValueAttribute = false) { this.genericWriter.WriteToken(this.get_OpeningBracket()); if (!isAssemblyDeclaration) { if (isReturnValueAttribute) { this.WriteReturnValueAttributeKeyword(); } } else { this.genericWriter.WriteKeyword(this.genericWriter.get_KeyWordWriter().get_Assembly()); this.genericWriter.Write(":"); this.genericWriter.WriteSpace(); } if (attribute.get_AttributeType().get_Name().EndsWith("Attribute")) { stackVariable19 = attribute.get_AttributeType().get_Name().Remove(attribute.get_AttributeType().get_Name().LastIndexOf("Attribute")); } else { stackVariable19 = attribute.get_AttributeType().get_Name(); } V_0 = stackVariable19; this.genericWriter.WriteNamespaceIfTypeInCollision(attribute.get_AttributeType()); this.genericWriter.WriteReference(V_0, attribute.get_AttributeType()); this.genericWriter.WriteToken("("); V_1 = securityDeclaration.GetSecurityActionTypeReference(module); if (V_1.get_IsDefinition()) { stackVariable38 = V_1 as TypeDefinition; } else { stackVariable38 = V_1.Resolve(); } V_2 = stackVariable38; if (V_2 != null && V_2.get_IsEnum()) { V_3 = EnumValueToFieldCombinationMatcher.GetEnumFieldDefinitionByValue(V_2.get_Fields(), (Int32)securityDeclaration.get_Action(), V_2.get_CustomAttributes()); if (V_3.get_Count() == 0) { this.WriteSecurityAttributeAction(securityDeclaration.get_Action()); } else { V_4 = 0; while (V_4 < V_3.get_Count()) { this.genericWriter.WriteReferenceAndNamespaceIfInCollision(V_3.get_Item(V_4).get_DeclaringType()); this.genericWriter.WriteToken("."); this.genericWriter.WriteEnumValueField(V_3.get_Item(V_4)); if (V_4 + 1 < V_3.get_Count()) { this.genericWriter.WriteSpace(); this.genericWriter.WriteBitwiseOr(); this.genericWriter.WriteSpace(); } V_4 = V_4 + 1; } } } wroteArgument = true; if (attribute.get_HasFields() || attribute.get_HasProperties()) { V_5 = attribute.get_AttributeType().Resolve(); if (attribute.get_HasProperties()) { wroteArgument = this.WriteAttributeNamedArgs(V_5, attribute.get_Properties(), false, wroteArgument); } if (attribute.get_HasFields()) { dummyVar0 = this.WriteAttributeNamedArgs(V_5, attribute.get_Fields(), true, wroteArgument); } } this.genericWriter.WriteToken(")"); this.genericWriter.WriteToken(this.get_ClosingBracket()); if (!skipTheNewLine) { this.genericWriter.WriteLine(); } return(wroteArgument); }