static void AddAttributes(IProjectContent pc, IList<IAttribute> list, CustomAttributeCollection attributes) { foreach (CustomAttribute att in attributes) { DefaultAttribute a = new DefaultAttribute(CreateType(pc, null, att.Constructor.DeclaringType)); // Currently Cecil returns string instead of TypeReference for typeof() arguments to attributes var parameters = att.Constructor.Parameters; for (int i = 0; i < Math.Min(parameters.Count, att.ConstructorParameters.Count); i++) { object o = att.ConstructorParameters[i]; if (parameters[i].ParameterType.FullName == "System.Type" && o is string) { try { a.PositionalArguments.Add(ReflectionReturnType.Parse(pc, (string)o)); } catch (ReflectionTypeNameSyntaxError ex) { LoggingService.Warn("parsing '" + o + "'", ex); a.PositionalArguments.Add(o); } } else { a.PositionalArguments.Add(o); } } foreach (DictionaryEntry entry in att.Properties) { a.NamedArguments.Add(entry.Key.ToString(), entry.Value); } list.Add(a); } }
static void AddAttributes(IProjectContent pc, IEntity member, IList <IAttribute> list, ICustomAttributeProvider attributeProvider) { if (!attributeProvider.HasCustomAttributes) { return; } foreach (CustomAttribute att in attributeProvider.CustomAttributes) { DefaultAttribute a = new DefaultAttribute(CreateType(pc, member, att.Constructor.DeclaringType)); // Currently Cecil returns string instead of TypeReference for typeof() arguments to attributes try { foreach (var argument in att.ConstructorArguments) { a.PositionalArguments.Add(GetValue(pc, member, argument)); } foreach (CustomAttributeNamedArgument entry in att.Properties) { // some obfuscated assemblies may contain duplicate named arguments; we'll have to ignore those if (!a.NamedArguments.ContainsKey(entry.Name)) { a.NamedArguments.Add(entry.Name, GetValue(pc, member, entry.Argument)); } } } catch (InvalidOperationException) { // Workaround for Cecil bug. (some types cannot be resolved) } list.Add(a); } }
static void AddAttributes(IProjectContent pc, IList <IAttribute> list, CustomAttributeCollection attributes) { foreach (CustomAttribute att in attributes) { DefaultAttribute a = new DefaultAttribute(CreateType(pc, null, att.Constructor.DeclaringType)); // Currently Cecil returns string instead of TypeReference for typeof() arguments to attributes var parameters = att.Constructor.Parameters; for (int i = 0; i < Math.Min(parameters.Count, att.ConstructorParameters.Count); i++) { object o = att.ConstructorParameters[i]; if (parameters[i].ParameterType.FullName == "System.Type" && o is string) { try { a.PositionalArguments.Add(ReflectionReturnType.Parse(pc, (string)o)); } catch (ReflectionTypeNameSyntaxError ex) { LoggingService.Warn("parsing '" + o + "'", ex); a.PositionalArguments.Add(o); } } else { a.PositionalArguments.Add(o); } } foreach (DictionaryEntry entry in att.Properties) { a.NamedArguments.Add(entry.Key.ToString(), entry.Value); } list.Add(a); } }
static void AddAttributes(IProjectContent pc, IList<IAttribute> list, CustomAttributeCollection attributes) { foreach (CustomAttribute att in attributes) { DefaultAttribute a = new DefaultAttribute(att.Constructor.DeclaringType.FullName); // TODO: add only attributes marked "important", and include attribute arguments list.Add(a); } }
static void AddAttributes(IProjectContent pc, IList <IAttribute> list, CustomAttributeCollection attributes) { foreach (CustomAttribute att in attributes) { DefaultAttribute a = new DefaultAttribute(att.Constructor.DeclaringType.FullName); // TODO: add only attributes marked "important", and include attribute arguments list.Add(a); } }
static void AddAttributes(IProjectContent pc, IList<IAttribute> list, CustomAttributeCollection attributes) { foreach (CustomAttribute att in attributes) { DefaultAttribute a = new DefaultAttribute(CreateType(pc, null, att.Constructor.DeclaringType)); foreach (object o in att.ConstructorParameters) { a.PositionalArguments.Add(o); } foreach (DictionaryEntry entry in att.Properties) { a.NamedArguments.Add(entry.Key.ToString(), entry.Value); } list.Add(a); } }
static void AddAttributes(IProjectContent pc, IList <IAttribute> list, CustomAttributeCollection attributes) { foreach (CustomAttribute att in attributes) { DefaultAttribute a = new DefaultAttribute(CreateType(pc, null, att.Constructor.DeclaringType)); foreach (object o in att.ConstructorParameters) { a.PositionalArguments.Add(o); } foreach (DictionaryEntry entry in att.Properties) { a.NamedArguments.Add(entry.Key.ToString(), entry.Value); } list.Add(a); } }
void ReadAttributes(IList <IAttribute> attributes, int count) { for (int i = 0; i < count; i++) { IReturnType type = ReadType(); DefaultAttribute attr = new DefaultAttribute(type, (AttributeTarget)reader.ReadByte()); int posArgCount = reader.ReadByte(); for (int j = 0; j < posArgCount; j++) { attr.PositionalArguments.Add(ReadAttributeArgument()); } int namedArgCount = reader.ReadByte(); for (int j = 0; j < namedArgCount; j++) { attr.NamedArguments.Add(ReadString(), ReadAttributeArgument()); } attributes.Add(attr); } }
static void AddAttributes(IProjectContent pc, IEntity member, IList<IAttribute> list, ICustomAttributeProvider attributeProvider) { if (!attributeProvider.HasCustomAttributes) return; foreach (CustomAttribute att in attributeProvider.CustomAttributes) { DefaultAttribute a = new DefaultAttribute(CreateType(pc, member, att.Constructor.DeclaringType)); // Currently Cecil returns string instead of TypeReference for typeof() arguments to attributes try { foreach (var argument in att.ConstructorArguments) { a.PositionalArguments.Add(GetValue(pc, member, argument)); } foreach (CustomAttributeNamedArgument entry in att.Properties) { a.NamedArguments.Add(entry.Name, GetValue(pc, member, entry.Argument)); } } catch (InvalidOperationException) { // Workaround for Cecil bug. (some types cannot be resolved) } list.Add(a); } }
void ReadAttributes(IList<IAttribute> attributes, int count) { for (int i = 0; i < count; i++) { IReturnType type = ReadType(); DefaultAttribute attr = new DefaultAttribute(type, (AttributeTarget)reader.ReadByte()); int posArgCount = reader.ReadByte(); for (int j = 0; j < posArgCount; j++) { attr.PositionalArguments.Add(ReadAttributeArgument()); } int namedArgCount = reader.ReadByte(); for (int j = 0; j < namedArgCount; j++) { attr.NamedArguments.Add(ReadString(), ReadAttributeArgument()); } attributes.Add(attr); } }
List<IAttribute> VisitAttributes(IList<NRefactoryAST.AttributeSection> attributes, ClassFinder context) { // TODO Expressions??? List<IAttribute> result = new List<IAttribute>(); foreach (NRefactoryAST.AttributeSection section in attributes) { AttributeTarget target = AttributeTarget.None; if (section.AttributeTarget != null && section.AttributeTarget != "") { switch (section.AttributeTarget.ToUpperInvariant()) { case "ASSEMBLY": target = AttributeTarget.Assembly; break; case "FIELD": target = AttributeTarget.Field; break; case "EVENT": target = AttributeTarget.Event; break; case "METHOD": target = AttributeTarget.Method; break; case "MODULE": target = AttributeTarget.Module; break; case "PARAM": target = AttributeTarget.Param; break; case "PROPERTY": target = AttributeTarget.Property; break; case "RETURN": target = AttributeTarget.Return; break; case "TYPE": target = AttributeTarget.Type; break; default: target = AttributeTarget.None; break; } } foreach (NRefactoryAST.Attribute attribute in section.Attributes) { List<object> positionalArguments = new List<object>(); foreach (NRefactoryAST.Expression positionalArgument in attribute.PositionalArguments) { positionalArguments.Add(ConvertAttributeArgument(positionalArgument)); } Dictionary<string, object> namedArguments = new Dictionary<string, object>(); foreach (NRefactoryAST.NamedArgumentExpression namedArgumentExpression in attribute.NamedArguments) { namedArguments.Add(namedArgumentExpression.Name, ConvertAttributeArgument(namedArgumentExpression.Expression)); } var defaultAttribue = new DefaultAttribute(new AttributeReturnType(context, attribute.Name), target, positionalArguments, namedArguments); defaultAttribue.CompilationUnit = cu; defaultAttribue.Region = GetRegion(attribute.StartLocation, attribute.EndLocation); result.Add(defaultAttribue); } } return result; }