private static List <string> AnnotationParametersFromContext(VBAParser.AnnotationContext context) { var parameters = new List <string>(); var argList = context.annotationArgList(); if (argList != null) { parameters.AddRange(argList.annotationArg().Select(arg => arg.GetText())); } return(parameters); }
public IAnnotation Create(VBAParser.AnnotationContext context, QualifiedSelection qualifiedSelection) { string annotationName = context.annotationName().GetText(); List <string> parameters = new List <string>(); var argList = context.annotationArgList(); if (argList != null) { parameters.AddRange(argList.annotationArg().Select(arg => arg.GetText())); } Type annotationCLRType = null; if (_creators.TryGetValue(annotationName.ToUpperInvariant(), out annotationCLRType)) { return((IAnnotation)Activator.CreateInstance(annotationCLRType, qualifiedSelection, parameters)); } return(null); }
private string GetAttributeInstruction(VBAParser.AnnotationContext context, string attributeName, AnnotationType annotationType) { string attributeInstruction = string.Empty; if (annotationType.HasFlag(AnnotationType.ModuleAnnotation)) { switch (annotationType) { case AnnotationType.Exposed: attributeInstruction = $"Attribute {attributeName} = True\n"; break; case AnnotationType.PredeclaredId: attributeInstruction = $"Attribute {attributeName} = True\n"; break; } } else if (annotationType.HasFlag(AnnotationType.MemberAnnotation)) { switch (annotationType) { case AnnotationType.Description: var description = context.annotationArgList().annotationArg().FirstOrDefault()?.GetText() ?? string.Empty; description = description.StartsWith("\"") && description.EndsWith("\"") ? description : $"\"{description}\""; attributeInstruction = $"Attribute {attributeName} = \"{description}\"\n"; break; case AnnotationType.DefaultMember: attributeInstruction = $"Attribute {attributeName} = 0"; break; case AnnotationType.Enumerator: attributeInstruction = $"Attribute {attributeName} = -4"; break; } } return(attributeInstruction); }