diff --git a/Src/Workspaces/Core/Shared/Extensions/ICompilationExtensions.cs b/Src/Workspaces/Core/Shared/Extensions/ICompilationExtensions.cs index 35836218db4862a5e92b47666d92a5aafd4ab7d8..d1dfcc3042b8736f44647b76375357bf0463654f 100644 --- a/Src/Workspaces/Core/Shared/Extensions/ICompilationExtensions.cs +++ b/Src/Workspaces/Core/Shared/Extensions/ICompilationExtensions.cs @@ -85,5 +85,10 @@ public static INamedTypeSymbol CoClassType(this Compilation compilation) { return compilation.GetTypeByMetadataName("System.Runtime.InteropServices.CoClassAttribute"); } + + public static INamedTypeSymbol ComAliasNameAttributeType(this Compilation compilation) + { + return compilation.GetTypeByMetadataName("System.Runtime.InteropServices.ComAliasNameAttribute"); + } } } \ No newline at end of file diff --git a/Src/Workspaces/Core/Shared/Extensions/IMethodSymbolExtensions.cs b/Src/Workspaces/Core/Shared/Extensions/IMethodSymbolExtensions.cs index 6f6d7b194526de2e0b6810c8b30ef805b3ee2690..1883c92bdbc8f62e686d08ee1cc3e7906e0a2bc7 100644 --- a/Src/Workspaces/Core/Shared/Extensions/IMethodSymbolExtensions.cs +++ b/Src/Workspaces/Core/Shared/Extensions/IMethodSymbolExtensions.cs @@ -168,6 +168,42 @@ public static IMethodSymbol RenameParameters(this IMethodSymbol method, IList statements = null, IList handlesExpressions = null) + { + if (attributeType == null) + { + return method; + } + + var someParameterHasAttribute = method.Parameters + .Where(m => m.GetAttributes().Where(a => a.AttributeClass.Equals(attributeType)).Any()) + .Any(); + if (!someParameterHasAttribute) + { + return method; + } + + return CodeGenerationSymbolFactory.CreateMethodSymbol( + method.ContainingType, + method.GetAttributes(), + method.DeclaredAccessibility, + method.GetSymbolModifiers(), + method.ReturnType, + method.ExplicitInterfaceImplementations.FirstOrDefault(), + method.Name, + method.TypeParameters, + method.Parameters.Select(p => + CodeGenerationSymbolFactory.CreateParameterSymbol( + p.GetAttributes().Where(a => !a.AttributeClass.Equals(attributeType)).ToList(), + p.RefKind, p.IsParams, p.Type, p.Name, p.IsOptional, + p.HasExplicitDefaultValue, p.HasExplicitDefaultValue ? p.ExplicitDefaultValue : null)).ToList(), + statements, + handlesExpressions, + method.GetReturnTypeAttributes()); + } + public static bool? IsMoreSpecificThan(this IMethodSymbol method1, IMethodSymbol method2) { var p1 = method1.Parameters; diff --git a/Src/Workspaces/Core/Shared/Extensions/IPropertySymbolExtensions.cs b/Src/Workspaces/Core/Shared/Extensions/IPropertySymbolExtensions.cs index 949358113998c3cf475c18aab9d622d8b0d696c1..ab54875862e69a758c5d0284d6a32caaaa6e2d63 100644 --- a/Src/Workspaces/Core/Shared/Extensions/IPropertySymbolExtensions.cs +++ b/Src/Workspaces/Core/Shared/Extensions/IPropertySymbolExtensions.cs @@ -33,5 +33,39 @@ public static IPropertySymbol RenameParameters(this IPropertySymbol property, IL property.SetMethod, property.IsIndexer); } + + public static IPropertySymbol RemoveAttributeFromParameters( + this IPropertySymbol property, INamedTypeSymbol attributeType) + { + if (attributeType == null) + { + return property; + } + + var someParameterHasAttribute = property.Parameters + .Where(p => p.GetAttributes().Where(a => a.AttributeClass.Equals(attributeType)).Any()) + .Any(); + if (!someParameterHasAttribute) + { + return property; + } + + return CodeGenerationSymbolFactory.CreatePropertySymbol( + property.ContainingType, + property.GetAttributes(), + property.DeclaredAccessibility, + property.GetSymbolModifiers(), + property.Type, + property.ExplicitInterfaceImplementations.FirstOrDefault(), + property.Name, + property.Parameters.Select(p => + CodeGenerationSymbolFactory.CreateParameterSymbol( + p.GetAttributes().Where(a => !a.AttributeClass.Equals(attributeType)).ToList(), + p.RefKind, p.IsParams, p.Type, p.Name, p.IsOptional, + p.HasExplicitDefaultValue, p.HasExplicitDefaultValue ? p.ExplicitDefaultValue : null)).ToList(), + property.GetMethod, + property.SetMethod, + property.IsIndexer); + } } } \ No newline at end of file