Сообщение Re: Type.Guid от 07.04.2015 6:21
Изменено 07.04.2015 6:24 Sinix
F>Куда он смотрит, при генерировании значения сабжа? Или кеширует где-то как-то однажды сгенерированные? Но тогда, все равно, кеш к чему-то привязываться должен...
http://ayende.com/blog/3095/system-type-guid-stability
В общем случае Type.GUID заточен под получение значения из GuidAttribute, поведение в случае, если тип не размечен GuidAttribute недокументировано.
Использовать можно, только если хочется походить по граблям типа таких.
Если хочется усложнить задачу, можно завязаться на текущую реализацию (подсмотреть можно в CoreCLR):
код | |
| |
А чтоб было совсем весело — не забываем про WinRT (цитата из того же кода):
//==========================================================================================
// Returns the GUID of this MethodTable.
// If metadata does not specify GUID for the type, GUID_NULL is returned (if bGenerateIfNotFound
// is FALSE) or a GUID is auto-generated on the fly from the name and members of the type
// (bGenerateIfNotFound is TRUE).
//
// Redirected WinRT types may have two GUIDs, the "classic" one which matches the return value
// of Type.Guid, and the new one which is the GUID of the WinRT type to which it is redirected.
// The bClassic parameter controls which one is returned from this method. Note that the parameter
// is ignored for genuine WinRT types, i.e. types loaded from .winmd files, those always return
// the new GUID.
//
Вы всё ещё хотите использовать Type.GUID?
F>Куда он смотрит, при генерировании значения сабжа? Или кеширует где-то как-то однажды сгенерированные? Но тогда, все равно, кеш к чему-то привязываться должен...
http://ayende.com/blog/3095/system-type-guid-stability
В общем случае Type.GUID заточен под получение значения из GuidAttribute, поведение в случае, если тип не размечен GuidAttribute недокументировано.
Использовать можно, только если хочется походить по граблям типа таких.
Если хочется усложнить задачу, можно завязаться на текущую реализацию (подсмотреть можно в CoreCLR):
код | |
| |
А чтоб было совсем весело — не забываем про WinRT (цитата из того же кода):
//==========================================================================================
// Returns the GUID of this MethodTable.
// If metadata does not specify GUID for the type, GUID_NULL is returned (if bGenerateIfNotFound
// is FALSE) or a GUID is auto-generated on the fly from the name and members of the type
// (bGenerateIfNotFound is TRUE).
//
// Redirected WinRT types may have two GUIDs, the "classic" one which matches the return value
// of Type.Guid, and the new one which is the GUID of the WinRT type to which it is redirected.
// The bClassic parameter controls which one is returned from this method. Note that the parameter
// is ignored for genuine WinRT types, i.e. types loaded from .winmd files, those always return
// the new GUID.
//
Вы всё ещё хотите использовать Type.GUID?
P.S. Ну и чтобы было понятно, почему код взят из methodtable.cpp — тынц на суровую правду жизни от Андрея Акиньшина (не проходим мимо, подписываемся на блог).