람다 - 메서드 구문을 작성할 때 특성이있는 모든 클래스에 대해 각 클래스 이름과 해당 특성을 인쇄하는 함수를 원합니다.C# linq - lambda 식의 로컬 문자열 변수 만들기
var x1 = Assembly.GetExecutingAssembly()
.GetTypes()
.Select(type => type
.GetCustomAttributes(false)
.Select(attribute => type.Name + " - " + attribute.ToString())
.ToList())
.ToList();
x1.ForEach(type => type.ForEach(str => Console.WriteLine(str)));
출력 :
<ClassName> - <ProgramName>.<AttributeName>
<ClassName> - <ProgramName>.<AttributeName>
<>c__DisplayClass6 - System.Runtime.CompilerServices.CompilerGeneratedAttribute
I 로컬 람다 식 변수를 사용하기 때문에, 출력의 마지막 행이 있는지 이해한다.
마지막 행을 표시하지 않으려면 어떻게해야합니까? 유형이 그런 CompilerGeneratedAttribute
이있는 경우
if (type.IsDefined (typeof (CompilerGeneratedAttribute), false))를 확인하고 건너 뛸 수 있습니다. – riteshmeher
감사합니다! 그것은 작동합니다. –
당신을 도울 수있어서 기쁩니다! – riteshmeher