static IUnresolvedMethod FunctionToIMethod(ProjectInformation pi, IUnresolvedTypeDefinition type, Function function, string[] contentLines) { var method = new DefaultUnresolvedMethod(type, function.Name); method.Region = new DomRegion((int)function.Line, 1, FindFunctionEnd(contentLines, (int)function.Line - 1) + 2, 1); Match match; bool abort = false; var parameters = new List <IUnresolvedParameter> (); foreach (string parameter in function.Parameters) { match = paramExpression.Match(parameter); if (null == match) { abort = true; break; } var typeRef = new DefaultUnresolvedTypeDefinition(string.Format("{0}{1}{2}", match.Groups["type"].Value, match.Groups["subtype"].Value, match.Groups["array"].Value)); var p = new DefaultUnresolvedParameter(typeRef, match.Groups["name"].Value); parameters.Add(p); } if (!abort) { parameters.ForEach(p => method.Parameters.Add(p)); } return(method); }
//TODO: handle generics public static IUnresolvedMethod CodeDomToMDDomMethod(CodeMemberMethod method) { var meth = new DefaultUnresolvedMethod(null, method.Name); meth.ReturnType = new DefaultUnresolvedTypeDefinition(method.ReturnType.BaseType); CodeDomModifiersToMDDom(meth, method.Attributes); foreach (CodeParameterDeclarationExpression dec in method.Parameters) { var paramType = new DefaultUnresolvedTypeDefinition(dec.Type.BaseType); var par = new DefaultUnresolvedParameter(paramType, dec.Name); if (dec.Direction == FieldDirection.Ref) { par.IsRef = true; } else if (dec.Direction == FieldDirection.Out) { par.IsOut = true; } meth.Parameters.Add(par); } return(meth); }
DefaultUnresolvedMethod ConvertAccessor(Accessor accessor, IUnresolvedMember p, string prefix) { if (accessor.IsNull) return null; var a = new DefaultUnresolvedMethod(currentTypeDefinition, prefix + p.Name); a.Accessibility = GetAccessibility(accessor.Modifiers) ?? p.Accessibility; a.Region = MakeRegion(accessor); if (p.EntityType == EntityType.Indexer) { foreach (var indexerParam in ((IUnresolvedProperty)p).Parameters) a.Parameters.Add(indexerParam); } DefaultUnresolvedParameter param = null; if (accessor.Role == PropertyDeclaration.GetterRole) { a.ReturnType = p.ReturnType; } else { param = new DefaultUnresolvedParameter(p.ReturnType, "value"); a.Parameters.Add(param); a.ReturnType = KnownTypeReference.Void; } foreach (AttributeSection section in accessor.Attributes) { if (section.AttributeTarget == "return") { ConvertAttributes(a.ReturnTypeAttributes, section); } else if (param != null && section.AttributeTarget == "param") { ConvertAttributes(param.Attributes, section); } else { ConvertAttributes(a.Attributes, section); } } return a; }
static void AddPlaceholders(Step action, IUnresolvedMethod method) { var parameters = new List <IUnresolvedParameter> (); int index = 0; foreach (var placeholder in action.Placeholders) { var typeRef = new DefaultUnresolvedTypeDefinition(placeholder.Name); var p = new DefaultUnresolvedParameter(typeRef, "p" + index); method.Parameters.Add(p); index++; } }
public override IUnresolvedEntity VisitEventDeclaration(EventDeclaration eventDeclaration, object data) { bool isSingleEvent = eventDeclaration.Variables.Count == 1; Modifiers modifiers = eventDeclaration.Modifiers; DefaultUnresolvedEvent ev = null; foreach (VariableInitializer vi in eventDeclaration.Variables) { ev = new DefaultUnresolvedEvent(currentTypeDefinition, vi.Name); ev.Region = isSingleEvent ? MakeRegion(eventDeclaration) : MakeRegion(vi); ev.BodyRegion = MakeRegion(vi); ApplyModifiers(ev, modifiers); ev.ReturnType = eventDeclaration.ReturnType.ToTypeReference(); var valueParameter = new DefaultUnresolvedParameter(ev.ReturnType, "value"); ev.AddAccessor = CreateDefaultEventAccessor(ev, "get_" + ev.Name, valueParameter); ev.RemoveAccessor = CreateDefaultEventAccessor(ev, "set_" + ev.Name, valueParameter); foreach (AttributeSection section in eventDeclaration.Attributes) { if (section.AttributeTarget == "method") { foreach (var attrNode in section.Attributes) { IUnresolvedAttribute attr = ConvertAttribute(attrNode); ev.AddAccessor.Attributes.Add(attr); ev.RemoveAccessor.Attributes.Add(attr); } } else if (section.AttributeTarget != "field") { ConvertAttributes(ev.Attributes, section); } } currentTypeDefinition.Members.Add(ev); if (interningProvider != null) { ev.ApplyInterningProvider(interningProvider); } } return isSingleEvent ? ev : null; }
void ConvertParameters(IList<IUnresolvedParameter> outputList, IEnumerable<ParameterDeclaration> parameters) { foreach (ParameterDeclaration pd in parameters) { DefaultUnresolvedParameter p = new DefaultUnresolvedParameter(pd.Type.ToTypeReference(), pd.Name); p.Region = MakeRegion(pd); ConvertAttributes(p.Attributes, pd.Attributes); switch (pd.ParameterModifier) { case ParameterModifier.Ref: p.IsRef = true; p.Type = new ByReferenceTypeReference(p.Type); break; case ParameterModifier.Out: p.IsOut = true; p.Type = new ByReferenceTypeReference(p.Type); break; case ParameterModifier.Params: p.IsParams = true; break; } if (!pd.DefaultExpression.IsNull) p.DefaultValue = ConvertConstantValue(p.Type, pd.DefaultExpression); outputList.Add(p); } }
static IUnresolvedParameter MakeParameter(ITypeReference type, string name) { DefaultUnresolvedParameter p = new DefaultUnresolvedParameter(type, name); p.Freeze(); return p; }