/*CustomAttribute customAttribute; public CustomAttribute CustomAttribute { get { return customAttribute; } }*/ public DomCecilAttribute (CustomAttribute customAttribute) { //this.customAttribute = customAttribute; base.AttributeType = DomCecilMethod.GetReturnType (customAttribute.Constructor); base.Name = customAttribute.Constructor.DeclaringType.FullName; try { // This Resolve call is required to load enum parameter values. // Without this call, enum parameters are omited. customAttribute.Resolve (); } catch { // If the resolve operation fails, just continue. The enum parameters will // be omited, but there will be other parameters } foreach (object par in customAttribute.ConstructorParameters) AddPositionalArgument (new System.CodeDom.CodePrimitiveExpression (par)); foreach (System.Collections.DictionaryEntry entry in customAttribute.Properties) AddNamedArgument ((string)entry.Key, new System.CodeDom.CodePrimitiveExpression (entry.Value)); foreach (System.Collections.DictionaryEntry entry in customAttribute.Fields) AddNamedArgument ((string)entry.Key, new System.CodeDom.CodePrimitiveExpression (entry.Value)); }
private void WriteCustomAttribute(CustomAttribute custom) { custom.Resolve(); WriteDot(); WriteKeyword("custom"); WriteSpace(); WriteMethodReference(custom.Constructor, true); WriteSpace(); Write("="); WriteLine(); if (custom.HasConstructorArguments || custom.HasProperties || custom.HasFields) { WriteOpenBreckets(); WriteLine(); Indent(); if (custom.HasConstructorArguments) { WriteCustomAttributeConstructorArguments(custom.ConstructorArguments); } if (custom.HasProperties) { WriteCustomAttributeProperties(custom); } if (custom.HasFields) { WriteCustomAttributeFields(custom); } Outdent(); WriteEndBreckets(); } else { Byte[] blob = custom.GetBlob(); Write("("); WriteLine(); Indent(); WriteByteArray(blob); WriteLine(); Outdent(); Write(")"); WriteLine(); } }
void MarkCustomAttribute(CustomAttribute ca) { MarkMethod (ca.Constructor); if (!ca.Resolved) { ca = ca.Clone (); ca.Resolve (); } if (!ca.Resolved) return; MarkCustomAttributeParameters (ca); TypeReference constructor_type = ca.Constructor.DeclaringType; TypeDefinition type = constructor_type.Resolve (); if (type == null) throw new ResolutionException (constructor_type); MarkCustomAttributeProperties (ca, type); MarkCustomAttributeFields (ca, type); }
private static ICollection<TypeReference> GetCustomAttributeUsedTypes(CustomAttribute attribute) { List<TypeReference> usedTypes = new List<TypeReference>(); attribute.Resolve(); usedTypes.AddRange(Utilities.GetTypeReferenceTypesDepedningOn(attribute.AttributeType)); for (int argIndex = 0; argIndex < attribute.ConstructorArguments.Count; argIndex++) { usedTypes.AddRange(GetAttributeArgumentValueUsedTypes(attribute.ConstructorArguments[argIndex])); } if (attribute.HasConstructorArguments || attribute.HasFields || attribute.HasProperties) { if (attribute.HasProperties) { TypeDefinition attributeType = attribute.AttributeType.Resolve(); usedTypes.AddRange(GetAttributeNamedArgsUsedTypes(attributeType, attribute.Properties, false)); } if (attribute.HasFields) { TypeDefinition attributeType = attribute.AttributeType.Resolve(); usedTypes.AddRange(GetAttributeNamedArgsUsedTypes(attributeType, attribute.Fields, true)); } } return usedTypes; }
protected void WriteAttribute(CustomAttribute attribute, bool skipNewLine = false) { if (attributesNotToShow.Contains(attribute.AttributeType.FullName)) { return; } bool resolvingProblem = false; attribute.Resolve(); genericWriter.WriteToken(OpeningBracket); resolvingProblem = WriteAttributeSignature(attribute, resolvingProblem); genericWriter.WriteToken(ClosingBracket); if (resolvingProblem) { genericWriter.Write(" "); string comment = genericWriter.Language.CommentLines(ASSEMBLYNOTRESOLVEDERROR); genericWriter.Write(comment.Remove(comment.Length - 2)); } if (!skipNewLine) { genericWriter.WriteLine(); } }
private void WriteGlobalAttribute(CustomAttribute attribute, string keyword) { if (attributesNotToShow.Contains(attribute.AttributeType.FullName)) { return; } bool resolvingProblem = false; attribute.Resolve(); genericWriter.WriteToken(OpeningBracket); genericWriter.WriteKeyword(keyword); genericWriter.Write(":"); genericWriter.WriteSpace(); resolvingProblem = WriteAttributeSignature(attribute, resolvingProblem); genericWriter.WriteToken(ClosingBracket); if (resolvingProblem) { genericWriter.Write(" "); string comment = genericWriter.Language.CommentLines(ASSEMBLYNOTRESOLVEDERROR); genericWriter.Write(comment.Remove(comment.Length - 2)); } genericWriter.WriteLine(); }
public static bool[] GetDynamicPositioningFlags(CustomAttribute dynamicAttribute) { dynamicAttribute.Resolve(); if (!dynamicAttribute.IsResolved) { throw new Exception("Could not resolve DynamicAttribute"); } if (dynamicAttribute.ConstructorArguments.Count == 0) { return new bool[] { true }; } if (dynamicAttribute.ConstructorArguments[0].Type.FullName != "System.Boolean[]") { throw new Exception("Invalid argument type for DynamicAttribute"); } CustomAttributeArgument[] booleanArray = (CustomAttributeArgument[])dynamicAttribute.ConstructorArguments[0].Value; bool[] positioningFlags = new bool[booleanArray.Length]; for (int i = 0; i < booleanArray.Length; i++) { positioningFlags[i] = (bool)booleanArray[i].Value; } return positioningFlags; }