public static IPropertySymbol RemoveAttributeFromParameters( this IPropertySymbol property, INamedTypeSymbol attributeType) { if (attributeType == null) { return(property); } var someParameterHasAttribute = property.Parameters .Any(p => p.GetAttributes().Any(a => a.AttributeClass.Equals(attributeType))); 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)); }
// public static bool CompatibleSignatureToDelegate(this IMethodSymbol method, INamedTypeSymbol delegateType) // { // //Contract.ThrowIfFalse(delegateType.TypeKind == TypeKind.Delegate); // // var invoke = delegateType.DelegateInvokeMethod; // if (invoke == null) // { // // It's possible to get events with no invoke method from metadata. We will assume // // that no method can be an event handler for one. // return false; // } // // if (method.Parameters.Length != invoke.Parameters.Length) // { // return false; // } // // if (method.ReturnsVoid != invoke.ReturnsVoid) // { // return false; // } // // if (!method.ReturnType.InheritsFromOrEquals(invoke.ReturnType)) // { // return false; // } // // for (int i = 0; i < method.Parameters.Length; i++) // { // if (!invoke.Parameters[i].Type.InheritsFromOrEquals(method.Parameters[i].Type)) // { // return false; // } // } // // return true; // } // public static IMethodSymbol RenameTypeParameters(this IMethodSymbol method, IList <string> newNames) { if (method.TypeParameters.Select(t => t.Name).SequenceEqual(newNames)) { return(method); } var typeGenerator = new TypeGenerator(); var updatedTypeParameters = RenameTypeParameters( method.TypeParameters, newNames, typeGenerator); var mapping = new Dictionary <ITypeSymbol, ITypeSymbol>(); for (int i = 0; i < method.TypeParameters.Length; i++) { mapping.Add(method.TypeParameters[i], updatedTypeParameters[i]); } return(CodeGenerationSymbolFactory.CreateMethodSymbol( method.ContainingType, method.GetAttributes(), method.DeclaredAccessibility, method.GetSymbolModifiers(), method.ReturnType.SubstituteTypes(mapping, typeGenerator), method.ExplicitInterfaceImplementations.FirstOrDefault(), method.Name, updatedTypeParameters, method.Parameters.Select(p => CodeGenerationSymbolFactory.CreateParameterSymbol(p.GetAttributes(), p.RefKind, p.IsParams, p.Type.SubstituteTypes(mapping, typeGenerator), p.Name, p.IsOptional, p.HasExplicitDefaultValue, p.HasExplicitDefaultValue ? p.ExplicitDefaultValue : null)).ToList())); }
public static IParameterSymbol RenameParameter(this IParameterSymbol parameter, string parameterName) { return(parameter.Name == parameterName ? parameter : CodeGenerationSymbolFactory.CreateParameterSymbol( parameter.GetAttributes(), parameter.RefKind, parameter.IsParams, parameter.Type, parameterName, parameter.IsOptional, parameter.HasExplicitDefaultValue, parameter.HasExplicitDefaultValue ? parameter.ExplicitDefaultValue : null)); }
public static IMethodSymbol RemoveAttributeFromParametersAndReturnType( this IMethodSymbol method, INamedTypeSymbol attributeType, IList <SyntaxNode> statements = null, IList <SyntaxNode> handlesExpressions = null) { if (attributeType == null) { return(method); } var someParameterHasAttribute = method.Parameters .Any(m => m.GetAttributes().Any(a => a.AttributeClass.Equals(attributeType))); var returnTypeHasAttribute = method.GetReturnTypeAttributes() .Any(a => a.AttributeClass.Equals(attributeType)); if (!someParameterHasAttribute && !returnTypeHasAttribute) { 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().Where(a => !a.AttributeClass.Equals(attributeType)).ToList())); }