Esempio n. 1
0
 private void WriteAttributeArgumentValue(CustomAttributeArgument argument)
 {
     if (argument.get_Value() as CustomAttributeArgument != null)
     {
         this.WriteAttributeArgumentValue((CustomAttributeArgument)argument.get_Value());
         return;
     }
     if (argument.get_Value() as CustomAttributeArgument[] != null)
     {
         this.WriteAttributeArgumentArray(argument);
         return;
     }
     if (argument.get_Type().get_IsDefinition())
     {
         stackVariable11 = argument.get_Type() as TypeDefinition;
     }
     else
     {
         stackVariable11 = argument.get_Type().Resolve();
     }
     V_0 = stackVariable11;
     if (V_0 == null || !V_0.get_IsEnum())
     {
         if (String.op_Inequality(argument.get_Type().get_Name(), "Type") || String.op_Inequality(argument.get_Type().get_Namespace(), "System"))
         {
             this.genericWriter.WriteLiteralInLanguageSyntax(argument.get_Value());
             return;
         }
         this.genericWriter.WriteKeyword(this.genericWriter.get_KeyWordWriter().get_TypeOf());
         this.genericWriter.WriteToken("(");
         this.genericWriter.WriteGenericReference(argument.get_Value() as TypeReference);
         this.genericWriter.WriteToken(")");
         return;
     }
     V_1 = EnumValueToFieldCombinationMatcher.GetEnumFieldDefinitionByValue(V_0.get_Fields(), argument.get_Value(), V_0.get_CustomAttributes());
     if (V_1.get_Count() == 0)
     {
         this.genericWriter.WriteLiteralInLanguageSyntax(argument.get_Value());
         return;
     }
     V_2 = 0;
     while (V_2 < V_1.get_Count())
     {
         this.genericWriter.WriteReferenceAndNamespaceIfInCollision(V_1.get_Item(V_2).get_DeclaringType());
         this.genericWriter.WriteToken(".");
         this.genericWriter.WriteEnumValueField(V_1.get_Item(V_2));
         if (V_2 + 1 < V_1.get_Count())
         {
             this.genericWriter.WriteSpace();
             this.genericWriter.WriteBitwiseOr();
             this.genericWriter.WriteSpace();
         }
         V_2 = V_2 + 1;
     }
     return;
 }
Esempio n. 2
0
        private void WriteAttributeArgumentValue(CustomAttributeArgument argument)
        {
            if (argument.Value is CustomAttributeArgument)
            {
                WriteAttributeArgumentValue((CustomAttributeArgument)argument.Value);
                return;
            }
            else if (argument.Value is CustomAttributeArgument[])
            {
                WriteAttributeArgumentArray(argument);
                return;
            }

            TypeDefinition argumentTypeDefinition = argument.Type.IsDefinition ? argument.Type as TypeDefinition : argument.Type.Resolve();

            if (argumentTypeDefinition != null && argumentTypeDefinition.IsEnum)
            {
                List <FieldDefinition> fields = EnumValueToFieldCombinationMatcher.GetEnumFieldDefinitionByValue(argumentTypeDefinition.Fields, argument.Value, 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
                {
                    genericWriter.WriteLiteralInLanguageSyntax(argument.Value);
                }
            }
            else
            {
                if (argument.Type.Name != "Type" || argument.Type.Namespace != "System")
                {
                    genericWriter.WriteLiteralInLanguageSyntax(argument.Value);
                }
                else
                {
                    genericWriter.WriteKeyword(genericWriter.KeyWordWriter.TypeOf);
                    genericWriter.WriteToken("(");
                    genericWriter.WriteGenericReference(argument.Value as TypeReference);
                    genericWriter.WriteToken(")");
                }
            }
        }
		private static ICollection<TypeReference> GetAttributeArgumentValueUsedTypes(CustomAttributeArgument argument)
		{
			if (argument.get_Value() as CustomAttributeArgument != null)
			{
				return AttributesUtilities.GetAttributeArgumentValueUsedTypes((CustomAttributeArgument)argument.get_Value());
			}
			if (argument.get_Value() as CustomAttributeArgument[] != null)
			{
				return AttributesUtilities.GetAttributeArgumentArrayUsedTypes(argument);
			}
			V_0 = new List<TypeReference>();
			if (argument.get_Type().get_IsDefinition())
			{
				stackVariable12 = argument.get_Type() as TypeDefinition;
			}
			else
			{
				stackVariable12 = argument.get_Type().Resolve();
			}
			V_1 = stackVariable12;
			if (V_1 == null || !V_1.get_IsEnum())
			{
				if (String.op_Equality(argument.get_Type().get_Name(), "Type") && String.op_Equality(argument.get_Type().get_Namespace(), "System"))
				{
					V_0.AddRange(Utilities.GetTypeReferenceTypesDepedningOn(argument.get_Value() as TypeReference));
				}
			}
			else
			{
				V_2 = EnumValueToFieldCombinationMatcher.GetEnumFieldDefinitionByValue(V_1.get_Fields(), argument.get_Value(), V_1.get_CustomAttributes());
				if (V_2.get_Count() != 0)
				{
					V_3 = 0;
					while (V_3 < V_2.get_Count())
					{
						V_0.AddRange(Utilities.GetTypeReferenceTypesDepedningOn(V_2.get_Item(V_3).get_DeclaringType()));
						V_3 = V_3 + 1;
					}
				}
			}
			return V_0;
		}
        private static ICollection <TypeReference> GetAttributeArgumentValueUsedTypes(CustomAttributeArgument argument)
        {
            if (argument.Value is CustomAttributeArgument)
            {
                return(GetAttributeArgumentValueUsedTypes((CustomAttributeArgument)argument.Value));
            }
            else if (argument.Value is CustomAttributeArgument[])
            {
                return(GetAttributeArgumentArrayUsedTypes(argument));
            }

            List <TypeReference> usedTypes = new List <TypeReference>();

            TypeDefinition argumentTypeDefinition = argument.Type.IsDefinition ? argument.Type as TypeDefinition : argument.Type.Resolve();

            if (argumentTypeDefinition != null && argumentTypeDefinition.IsEnum)
            {
                List <FieldDefinition> fields = EnumValueToFieldCombinationMatcher.GetEnumFieldDefinitionByValue(argumentTypeDefinition.Fields, argument.Value, argumentTypeDefinition.CustomAttributes);
                if (fields.Count != 0)
                {
                    for (int i = 0; i < fields.Count; i++)
                    {
                        usedTypes.AddRange(Utilities.GetTypeReferenceTypesDepedningOn(fields[i].DeclaringType));
                    }
                }
            }
            else
            {
                if (argument.Type.Name == "Type" && argument.Type.Namespace == "System")
                {
                    usedTypes.AddRange(Utilities.GetTypeReferenceTypesDepedningOn(argument.Value as TypeReference));
                }
            }

            return(usedTypes);
        }
Esempio n. 5
0
        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);
        }
Esempio n. 6
0
 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);
 }