2011-06-20 4 views

Odpowiedz

13

Sprawdź zajęcia dla atrybutu CompilerGenerated odróżnienia kompilatora generowane klas z drugiej

http://msdn.microsoft.com/en-us/library/system.runtime.compilerservices.compilergeneratedattribute.aspx

W reflektorze te Pokaż klasy mogą być postrzegane w ten sposób:

[CompilerGenerated] 
private sealed class <>c__DisplayClass1 
{..} 
+0

Uwaga: jeśli Wygeneruj kod samemu, użyj 'GenerateCodeAttribute' zamiast' CompilerGeneratedAttribute', jak [wytłumaczyć David Kean na tym blogu MSDN] (http://blogs.msdn.com/b/codeanalysis/archive/2007/04/27/correct-usage-of-the-compilergeneratedattribute-and-generatedcodeattribute.aspx). – Abel

7

Ta odpowiedź bardzo mi pomógł na zewnątrz! Oto kod Musiałem dodać do sprawdzenia Type dla CompilerGeneratedAttribute jak Valentin Kuzub wymienić:

using System.Runtime.CompilerServices; 

//... 

bool IsCompilerGenerated(Type t) 
{ 
    var attr = Attribute.GetCustomAttribute(t, typeof(CompilerGeneratedAttribute)); 
    return attr != null; 
} 
Powiązane problemy