public ButlerProperty(string name, string id, string type) { TypeSyntax propertyType = SyntaxFactory.ParseTypeName(type); Info = SyntaxFactory.PropertyDeclaration(propertyType, name); _accessibility = ButlerAccessibility.Private; _definedAccessors = new HashSet <ButlerAccessorType> (); Name = name; Id = id; Dependencies = new List <ButlerClass> (); }
public void AddAccessor(ButlerAccessorType accessorType, ButlerAccessibility accessibility) { if (accessorType == ButlerAccessorType.Set && !_definedAccessors.Contains(ButlerAccessorType.Get)) { throw new Exception("Cannot define a set accessor without a get accessor."); } AccessorDeclarationSyntax accessor = SyntaxFactory.AccessorDeclaration(RoslynUtilities.FromAccessorType(accessorType)); accessor = accessor.WithSemicolonToken(SyntaxFactory.Token(SyntaxKind.SemicolonToken)); if (accessibility > _accessibility) { throw new Exception($"The accessibility modifier of the {accessorType.ToString ()} accessor must be more restrictive than the property"); } if (accessibility != _accessibility) { accessor = accessor.AddModifiers(SyntaxFactory.Token(RoslynUtilities.FromAccessibility(accessibility))); } Info = Info.AddAccessorListAccessors(accessor); _definedAccessors.Add(accessorType); }
public void SetAccessibility(ButlerAccessibility accessibility) { _accessibility = accessibility; Info = Info.AddModifiers(SyntaxFactory.Token(RoslynUtilities.FromAccessibility(accessibility))); }
public static SyntaxKind FromAccessibility(ButlerAccessibility accessibility) { return(_accessibilitiesMap[accessibility]); }