Исходный код вики Сценарии

Редактировал(а) Alexandr Fokin 2026/03/17 19:05

Скрыть последних авторов
Alexandr Fokin 1.7 1 |(% style="width:174px" %)Поиск типа|(% style="width:1348px" %)(((
2 |Find Types in All Assemblies
Alexandr Fokin 1.4 3 [[https:~~/~~/stackoverflow.com/questions/4692340/find-types-in-all-assemblies>>https://stackoverflow.com/questions/4692340/find-types-in-all-assemblies]]
Alexandr Fokin 1.7 4 |{{code language="c#"}}var assemblyQualifiedName = type.AssemblyQualifiedName;
5 Type.GetType(assemblyQualifiedName, throwOnError: false){{/code}}
6 )))
Alexandr Fokin 1.5 7 |(% style="width:174px" %) |(% style="width:1348px" %)(((
Alexandr Fokin 1.2 8 Find a private field with Reflection?
Alexandr Fokin 1.1 9 [[https:~~/~~/stackoverflow.com/questions/95910/find-a-private-field-with-reflection>>https://stackoverflow.com/questions/95910/find-a-private-field-with-reflection]]
Alexandr Fokin 1.2 10
11 Using C# reflection to call a constructor
12 [[https:~~/~~/stackoverflow.com/questions/3255697/using-c-sharp-reflection-to-call-a-constructor>>https://stackoverflow.com/questions/3255697/using-c-sharp-reflection-to-call-a-constructor]]
Alexandr Fokin 1.3 13
14 Invoke method by MethodInfo
15 [[https:~~/~~/stackoverflow.com/questions/919826/invoke-method-by-methodinfo>>https://stackoverflow.com/questions/919826/invoke-method-by-methodinfo]]
Alexandr Fokin 1.2 16 )))
Alexandr Fokin 1.9 17 |(% style="width:174px" %)Получение основного типа для nullable структур.|(% style="width:1348px" %){{code language="c#"}}PropertyInfo prop;
Alexandr Fokin 1.5 18 var type = Nullable.GetUnderlyingType(prop.PropertyType)
19 ?? prop.PropertyType;{{/code}}
Alexandr Fokin 1.6 20 |(% style="width:174px" %)Формирование конкретного типа на основе Generic|(% style="width:1348px" %)(((
21 Type.MakeGenericType
22 [[https:~~/~~/learn.microsoft.com/ru-ru/dotnet/api/system.type.makegenerictype?view=net-7.0>>https://learn.microsoft.com/ru-ru/dotnet/api/system.type.makegenerictype?view=net-7.0]]
Alexandr Fokin 1.1 23
Alexandr Fokin 1.6 24 C# Type MakeGenericType
25 [[http:~~/~~/www.java2s.com/Tutorials/CSharp/System/Type/C_Type_MakeGenericType.htm>>http://www.java2s.com/Tutorials/CSharp/System/Type/C_Type_MakeGenericType.htm]]
26 )))
Alexandr Fokin 1.9 27 |(% style="width:174px" %)Ref и Out параметры метода.|(% style="width:1348px" %)(((
28 | |При передаче параметра с использованием out и ref, в качестве типа используется дополнительная обертка.
29 Критерий передачи {{code language="c#"}}parameter.ParameterType.IsByRef{{/code}}.
Alexandr Fokin 1.10 30 У обернутого типа значение IsValueType будет true даже для структур.
Alexandr Fokin 1.11 31 | |(((
32 What is the opposite of Type.MakeByRefType
Alexandr Fokin 1.9 33 [[https:~~/~~/stackoverflow.com/questions/607130/what-is-the-opposite-of-type-makebyreftype>>https://stackoverflow.com/questions/607130/what-is-the-opposite-of-type-makebyreftype]]
Alexandr Fokin 1.11 34
35 Type.IsByRef
36 [[https:~~/~~/learn.microsoft.com/ru-ru/dotnet/api/system.type.isbyref>>https://learn.microsoft.com/ru-ru/dotnet/api/system.type.isbyref]]
37 )))
Alexandr Fokin 1.9 38 | |{{code language="c#"}}// Получение типа обертки.
39 var refType = typeof(int).MakeByRefType()
Alexandr Fokin 1.6 40
Alexandr Fokin 1.9 41 // Разворачивание, получение основного типа.
42 // Также флаг refType.HasElementType.
43 refType.GetElementType();{{/code}}
44 )))
45
Alexandr Fokin 1.1 46