public void GetCustomAttribute(Type type, Type attributeType, bool expected) { var symbol = Compilation.GetTypeByMetadataName(type); symbol.ShouldNotBeNull(); var actual = SyntaxTools.GetCustomAttribute(symbol, attributeType.FullName !); if (expected) { actual.ShouldNotBeNull(); } else { actual.ShouldBeNull(); } }
private static IEnumerable <TestCaseData> GetFullNameCases() { var type = Compilation.GetTypeByMetadataName(typeof(FullNameCases)); type.ShouldNotBeNull(); foreach (var method in SyntaxTools.GetInstanceMethods(type)) { var attribute = SyntaxTools.GetCustomAttribute(method, typeof(DisplayNameAttribute).FullName !); var expected = (string)attribute !.ConstructorArguments[0].Value !; expected.ShouldNotBeNull(); yield return(new TestCaseData(method.ReturnType, expected) { TestName = "FullName." + method.Name }); } }
private static string GetDataContainerName(ITypeSymbol type) { var attribute = SyntaxTools.GetCustomAttribute(type, "System.Runtime.Serialization.DataContractAttribute"); string?attributeName = null; if (attribute != null) { for (var i = 0; i < attribute.NamedArguments.Length; i++) { var pair = attribute.NamedArguments[i]; if ("Name".Equals(pair.Key)) { attributeName = (string?)pair.Value.Value; break; } } } return(string.IsNullOrWhiteSpace(attributeName) ? type.Name : attributeName !); }
private static AttributeData?GetOperationContractAttribute(IMethodSymbol method) { return(SyntaxTools.GetCustomAttribute(method, "System.ServiceModel.OperationContractAttribute")); }
private static AttributeData?GetServiceContractAttribute(ITypeSymbol type) { return(SyntaxTools.GetCustomAttribute(type, "System.ServiceModel.ServiceContractAttribute")); }