public static ClassDeclarationSyntax WithViewsClass(this ClassDeclarationSyntax node, IEnumerable<View> viewFiles) { // create subclass called ViewsClass // create ViewNames get property returning static instance of _ViewNamesClass subclass // create subclass in ViewsClass called _ViewNamesClass // create string field per view const string viewNamesClass = "_ViewNamesClass"; var viewClassNode = CreateClass("ViewsClass", null, SyntaxKind.PublicKeyword) .WithAttributes(CreateGeneratedCodeAttribute(), CreateDebugNonUserCodeAttribute()) .WithField("s_ViewNames", viewNamesClass, SyntaxKind.StaticKeyword, SyntaxKind.ReadOnlyKeyword); var viewNamesClassNode = CreateClass(viewNamesClass, null, SyntaxKind.PublicKeyword); var controllerViews = viewFiles.Where(x => x.ControllerName.Equals(node.Identifier.ToString(), StringComparison.CurrentCultureIgnoreCase)) .ToImmutableArray(); var viewNameFields = controllerViews.Select( x => CreateStringFieldDeclaration(x.ViewName, x.ViewName, SyntaxKind.PublicKeyword, SyntaxKind.ReadOnlyKeyword)) .Cast<MemberDeclarationSyntax>() .ToArray(); viewNamesClassNode = viewNamesClassNode.AddMembers(viewNameFields); viewClassNode = viewClassNode.AddMembers(viewNamesClassNode); var viewFields = controllerViews.Select( x => CreateStringFieldDeclaration(x.ViewName, "~/" + x.RelativePath, SyntaxKind.PublicKeyword)) .Cast<MemberDeclarationSyntax>() .ToArray(); viewClassNode = viewClassNode.AddMembers(viewFields); return node.AddMembers(viewClassNode); }
public static NamespaceDeclarationSyntax AddStructs(this NamespaceDeclarationSyntax @this, params StructDeclarationSyntax[] @structsSyntax) { return @this.AddMembers(@structsSyntax); }
public static NamespaceDeclarationSyntax AddNamespaces(this NamespaceDeclarationSyntax @this, params NamespaceDeclarationSyntax[] @namespaceSyntax) { return @this.AddMembers(@namespaceSyntax); }
public static NamespaceDeclarationSyntax AddInterfaces(this NamespaceDeclarationSyntax @this, params InterfaceDeclarationSyntax[] @interfacesSyntax) { return @this.AddMembers(@interfacesSyntax); }
public static NamespaceDeclarationSyntax AddEnums(this NamespaceDeclarationSyntax @this, params EnumDeclarationSyntax[] @enumsSyntax) { return @this.AddMembers(@enumsSyntax); }
public static NamespaceDeclarationSyntax AddDelegates(this NamespaceDeclarationSyntax @this, params DelegateDeclarationSyntax[] @delegatesSyntax) { return @this.AddMembers(@delegatesSyntax); }
public static NamespaceDeclarationSyntax AddClasses(this NamespaceDeclarationSyntax @this, params ClassDeclarationSyntax[] @classesSyntax) { return @this.AddMembers(@classesSyntax); }
private static TypeDeclarationSyntax WithPropertyChangedEvent(this TypeDeclarationSyntax node, TypeDeclarationSyntax original, SemanticModel semanticModel, Workspace workspace) { var classSymbol = semanticModel.GetDeclaredSymbol(original); var interfaceSymbol = semanticModel.Compilation.GetTypeByMetadataName(InterfaceName); var propertyChangedEventSymbol = (IEventSymbol)interfaceSymbol.GetMembers("PropertyChanged").Single(); var propertyChangedEvent = classSymbol.FindImplementationForInterfaceMember(propertyChangedEventSymbol); // Does this class contain an implementation for the PropertyChanged event? If not, add it. if (propertyChangedEvent == null) { var propertyChangedEventDecl = GeneratePropertyChangedEvent(); node = node.AddMembers(propertyChangedEventDecl); } return node; }
public static EnumDeclarationSyntax AddConstants(this EnumDeclarationSyntax @this, params EnumMemberDeclarationSyntax[] @enumMemberSyntax) { return @this.AddMembers(@enumMemberSyntax); }
/// <summary> /// Returns the given class with a private parameterless constructor added. /// </summary> public static ClassDeclarationSyntax AddPrivateConstructor(this ClassDeclarationSyntax classDeclaration) { return classDeclaration.AddMembers( SyntaxEx.ConstructorDeclaration( new[] { SyntaxKind.PrivateKeyword }, classDeclaration.Identifier.ValueText)); }
public static ClassDeclarationSyntax WithStaticFieldsForFiles(this ClassDeclarationSyntax node, IEnumerable<StaticFile> staticFiles) { var staticNodes = staticFiles.Select( x => CreateStringFieldDeclaration(x.FileName, x.RelativePath.ToString(), SyntaxKind.PublicKeyword, SyntaxKind.StaticKeyword)) .Cast<MemberDeclarationSyntax>() .ToArray(); return node.AddMembers(staticNodes); }
public static ClassDeclarationSyntax WithControllerFields( this ClassDeclarationSyntax node, IEnumerable<ClassDeclarationSyntax> controllers) { // TODO field name should be overriddable via config, stripping off 'controller' by default // TODO add extension method to customise field initializer as this needs to be the one returned from GetR4MVCControllerClassName return node.AddMembers( controllers.Select( x => CreateFieldWithDefaultInitializer( x.Identifier.ToString().Replace("Controller", string.Empty), x.ToQualifiedName(), SyntaxKind.PublicKeyword, SyntaxKind.StaticKeyword)).Cast<MemberDeclarationSyntax>().ToArray()); }
public static NamespaceDeclarationSyntax WithDummyClass(this NamespaceDeclarationSyntax node) { const string dummyClassName = "Dummy"; var dummyClass = CreateClass(dummyClassName) .WithModifiers(SyntaxKind.PublicKeyword) .WithAttributes(CreateGeneratedCodeAttribute(), CreateDebugNonUserCodeAttribute()) .WithDefaultConstructor(false, SyntaxKind.PrivateKeyword) .WithField("Instance", dummyClassName, SyntaxKind.PublicKeyword, SyntaxKind.StaticKeyword); return node.AddMembers(dummyClass); }
public static Task<System.Boolean> AddMembersAsync(this Organization target,List<ReactiveRTM.SDOPackage.SDO> sdoList) { return Task.Factory.StartNew(()=>{ var ret = target.AddMembers(sdoList); return ret; }); }