public Injector To(string member, AccessModifier modifiers, bool recursive = false) { ChangeAccess(member, modifiers.HasFlag(AccessModifier.Public) && !modifiers.HasFlag(AccessModifier.Private), modifiers.HasFlag(AccessModifier.Virtual), modifiers.HasFlag(AccessModifier.Assignable), recursive); return(this); }
public static AccessModifier Parse(SyntaxTokenList list) { AccessModifier mod = AccessModifier.None; foreach (var item in list) { var raw = item.Text; if (raw == "public") { mod |= AccessModifier.Public; } else if (raw == "protected") { mod |= AccessModifier.Protected; } else if (raw == "private") { mod |= AccessModifier.Private; } else if (raw == "internal") { mod |= AccessModifier.Internal; } } if (mod.HasFlag(AccessModifier.Public)) { if (mod.HasFlag(AccessModifier.Private) || mod.HasFlag(AccessModifier.Protected)) { throw new SemanticViolationException("Invalid access modifier"); } } else if (mod.HasFlag(AccessModifier.Protected)) { if (mod.HasFlag(AccessModifier.Private)) { throw new SemanticViolationException("Invalid access modifier"); } } if (mod == AccessModifier.None) { mod = AccessModifier.Private; } return(mod); }
public static T ApplyModifiers <T>(this T syntaxNode, AccessModifier modifiers) where T : MemberDeclarationSyntax { List <SyntaxKind> syntaxKinds = new List <SyntaxKind>(); if (modifiers.HasFlag(AccessModifier.Abstract)) { syntaxKinds.Add(SyntaxKind.AbstractKeyword); } if (modifiers.HasFlag(AccessModifier.Internal)) { syntaxKinds.Add(SyntaxKind.InternalKeyword); } if (modifiers.HasFlag(AccessModifier.Private)) { syntaxKinds.Add(SyntaxKind.PrivateKeyword); } if (modifiers.HasFlag(AccessModifier.Protected)) { syntaxKinds.Add(SyntaxKind.ProtectedKeyword); } if (modifiers.HasFlag(AccessModifier.Public)) { syntaxKinds.Add(SyntaxKind.PublicKeyword); } if (modifiers.HasFlag(AccessModifier.Sealed)) { syntaxKinds.Add(SyntaxKind.SealedKeyword); } if (modifiers.HasFlag(AccessModifier.Partial)) { syntaxKinds.Add(SyntaxKind.PartialKeyword); } if (0 == syntaxKinds.Count) { return(syntaxNode); } return((T)syntaxNode.AddModifiers(syntaxKinds.Select(x => SyntaxFactory.Token(x)).ToArray())); }