private static void InitializeCodeActionWithNestedActionsDataTypeThreadUnsafe() { System.Reflection.TypeInfo codeActionTypeInfo = typeof(CodeAction).GetTypeInfo(); var _codeActionWithNestedActionsDataTypeInfo = codeActionTypeInfo.GetDeclaredNestedType(CodeActionWithNestedActionsTypeName); _codeActionWithNestedActionsType = _codeActionWithNestedActionsDataTypeInfo?.AsType(); if (_codeActionWithNestedActionsType == null) { return; } var codeActionWithNestedActionsConstructor = _codeActionWithNestedActionsDataTypeInfo.DeclaredConstructors.FirstOrDefault(); if (codeActionWithNestedActionsConstructor == null) { _codeActionWithNestedActionsType = null; return; } var parameters = codeActionWithNestedActionsConstructor.GetParameters(); switch (parameters?.Length) { case 3: _roslynOldApiUsed = true; return; case 4: _roslynOldApiUsed = false; InitializeCodeActionPriorityInstance(codeActionTypeInfo); return; default: _codeActionWithNestedActionsType = null; return; } }
private TypeInfo FindDeclaredNestedType(TypeInfo declaringTypeInfo, String name, bool ignoreCase) { TypeInfo nestedType = declaringTypeInfo.GetDeclaredNestedType(name); if (nestedType != null) return nestedType; if (!ignoreCase) return null; // // Desktop compat note: If there is more than one nested type that matches the name in a case-blind match, // we might not return the same one that the desktop returns. The actual selection method is influenced both by the type's // placement in the IL and the implementation details of the CLR's internal hashtables so it would be very // hard to replicate here. // // Desktop compat note #2: Case-insensitive lookups: If we don't find a match, we do *not* go back and search // other declaring types that might match the case-insensitive search and contain the nested type being sought. // Though this is somewhat unsatisfactory, the desktop CLR has the same limitation. // foreach (TypeInfo candidate in declaringTypeInfo.DeclaredNestedTypes) { String candidateName = candidate.Name; if (name.Equals(candidateName, StringComparison.OrdinalIgnoreCase)) return candidate; } return null; }