public static DomAttribute ReadAttribute(BinaryReader reader, INameDecoder nameTable) { DomAttribute attr = new DomAttribute(); attr.Name = ReadString(reader, nameTable); attr.Region = ReadRegion(reader, nameTable); attr.AttributeTarget = (AttributeTarget)reader.ReadInt32(); attr.AttributeType = ReadReturnType(reader, nameTable); // Named argument count uint num = ReadUInt(reader, 500); string[] names = new string[num]; for (int n = 0; n < num; n++) { names [n] = ReadString(reader, nameTable); } CodeExpression[] exps = ReadExpressionArray(reader, nameTable); int i; for (i = 0; i < num; i++) { attr.AddNamedArgument(names[i], exps [i]); } for (; i < exps.Length; i++) { attr.AddPositionalArgument(exps [i]); } return(attr); }
static void AddAttributes (AbstractMember member, IEnumerable<ICSharpCode.NRefactory.Ast.AttributeSection> attributes) { CodeDomVisitor domVisitor = new CodeDomVisitor (); foreach (ICSharpCode.NRefactory.Ast.AttributeSection attributeSection in attributes) { foreach (ICSharpCode.NRefactory.Ast.Attribute attribute in attributeSection.Attributes) { DomAttribute domAttribute = new DomAttribute (); domAttribute.Name = attribute.Name; domAttribute.Region = ConvertRegion (attribute.StartLocation, attribute.EndLocation); domAttribute.AttributeType = new DomReturnType (attribute.Name); member.Add (domAttribute); foreach (ICSharpCode.NRefactory.Ast.Expression exp in attribute.PositionalArguments) domAttribute.AddPositionalArgument ((CodeExpression)exp.AcceptVisitor (domVisitor, null)); foreach (ICSharpCode.NRefactory.Ast.NamedArgumentExpression nexp in attribute.NamedArguments) domAttribute.AddNamedArgument (nexp.Name, (CodeExpression)nexp.Expression.AcceptVisitor (domVisitor, null)); } } }
IEnumerable<IAttribute> ConvertAttributes (Attributes optAttributes, IMemberContext mc) { List<IAttribute> atts = new List<IAttribute> (); if (optAttributes == null || optAttributes.Attrs == null) return atts; ResolveContext ctx = new ResolveContext (mc); foreach (var section in optAttributes.Sections) { foreach (var attr in section) { DomAttribute domAttribute = new DomAttribute (); domAttribute.Name = ConvertQuoted (attr.Name); domAttribute.Region = ConvertRegion (attr.Location, attr.Location); domAttribute.AttributeType = ConvertReturnType (attr.TypeNameExpression); if (attr.PosArguments != null) { for (int i = 0; i < attr.PosArguments.Count; i++) { CodeExpression domExp; var exp = attr.PosArguments [i].Expr; if (exp is TypeOf) { TypeOf tof = (TypeOf)exp; IReturnType rt = ConvertReturnType (tof.TypeExpression); domExp = new CodeTypeOfExpression (rt.FullName); } else if (exp is Binary) { // Currently unsupported in the old dom (will be in the new dom) continue; } else if (exp is Constant) { try { var res = exp.Resolve (ctx); var val = res as Constant; if (val == null) continue; domExp = new CodePrimitiveExpression (val.GetValue ()); } catch { continue; } } else { try { domExp = ResolveMemberAccessExpression (exp); } catch { continue; } } if (domExp != null) domAttribute.AddPositionalArgument (domExp); } } if (attr.NamedArguments != null) { for (int i = 0; i < attr.NamedArguments.Count; i++) { var val = attr.NamedArguments [i].Expr as Constant; if (val == null) continue; domAttribute.AddNamedArgument (((NamedArgument)attr.NamedArguments [i]).Name, new CodePrimitiveExpression (val.GetValue ())); } } atts.Add (domAttribute); } } return atts; }
public void AddAttributes (MonoDevelop.Projects.Dom.AbstractMember member, Attributes optAttributes) { if (optAttributes == null || optAttributes.Attrs == null) return; foreach (var attr in optAttributes.Attrs) { DomAttribute domAttribute = new DomAttribute (); domAttribute.Name = attr.Name; domAttribute.Region = ConvertRegion (attr.Location, attr.Location); domAttribute.AttributeType = new DomReturnType (attr.Name); if (attr.PosArguments != null) { for (int i = 0; i < attr.PosArguments.Count; i++) { var val = attr.PosArguments[i].Expr as Constant; if (val == null) { continue; } domAttribute.AddPositionalArgument (new CodePrimitiveExpression (val.GetValue ())); } } if (attr.NamedArguments != null) { for (int i = 0; i < attr.NamedArguments.Count; i++) { var val = attr.NamedArguments[i].Expr as Constant; if (val == null) continue; domAttribute.AddNamedArgument (((NamedArgument)attr.NamedArguments[i]).Name, new CodePrimitiveExpression (val.GetValue ())); } } member.Add (domAttribute); } }
static void AddAttributes (AbstractMember member, IEnumerable<ICSharpCode.NRefactory.Ast.AttributeSection> attributes) { CodeDomVisitor domVisitor = new CodeDomVisitor (); foreach (ICSharpCode.NRefactory.Ast.AttributeSection attributeSection in attributes) { foreach (ICSharpCode.NRefactory.Ast.Attribute attribute in attributeSection.Attributes) { DomAttribute domAttribute = new DomAttribute (); domAttribute.Name = attribute.Name; domAttribute.Region = ConvertRegion (attribute.StartLocation, attribute.EndLocation); domAttribute.AttributeType = new DomReturnType (attribute.Name); member.Add (domAttribute); foreach (ICSharpCode.NRefactory.Ast.Expression exp in attribute.PositionalArguments) domAttribute.AddPositionalArgument ((CodeExpression)exp.AcceptVisitor (domVisitor, null)); foreach (ICSharpCode.NRefactory.Ast.NamedArgumentExpression nexp in attribute.NamedArguments) domAttribute.AddNamedArgument (nexp.Name, (CodeExpression)nexp.Expression.AcceptVisitor (domVisitor, null)); } } }
public static DomAttribute ReadAttribute (BinaryReader reader, INameDecoder nameTable, IDomObjectTable objectTable) { DomAttribute attr = new DomAttribute (); attr.Name = ReadString (reader, nameTable); attr.Region = ReadRegion (reader, nameTable); attr.AttributeTarget = (AttributeTarget)reader.ReadInt32 (); attr.AttributeType = ReadReturnType (reader, nameTable, objectTable); // Named argument count uint num = ReadUInt (reader, 500); string[] names = new string[num]; for (int n=0; n<num; n++) names [n] = ReadString (reader, nameTable); CodeExpression[] exps = ReadExpressionArray (reader, nameTable); int i; for (i=0; i<num; i++) attr.AddNamedArgument (names [i], exps [i]); for (; i<exps.Length; i++) attr.AddPositionalArgument (exps [i]); return attr; }