internal static bool TrySubstituteValue(object value, Resolver resolver, [NotNullWhen(true)] out ISubstitutedValue?substitutedValue) { if (value is Type[] types) { substitutedValue = new TypeArraySubstitution(ReflectionHelpers.TypesToTypeRefs(types, resolver), resolver); return(true); } substitutedValue = null; return(false); }
/// <summary> /// Gets the constructed type (non generic type definition) for a part. /// </summary> private static Reflection.TypeRef GetPartConstructedTypeRef(RuntimeComposition.RuntimePart part, IReadOnlyDictionary <string, object?> importMetadata) { Requires.NotNull(part, nameof(part)); Requires.NotNull(importMetadata, nameof(importMetadata)); if (part.TypeRef.IsGenericTypeDefinition) { var bareMetadata = LazyMetadataWrapper.TryUnwrap(importMetadata); object?typeArgsObject; if (bareMetadata.TryGetValue(CompositionConstants.GenericParametersMetadataName, out typeArgsObject) && typeArgsObject is object) { IEnumerable <TypeRef> typeArgs = typeArgsObject is LazyMetadataWrapper.TypeArraySubstitution ? ((LazyMetadataWrapper.TypeArraySubstitution)typeArgsObject).TypeRefArray : ReflectionHelpers.TypesToTypeRefs((Type[])typeArgsObject, part.TypeRef.Resolver); return(part.TypeRef.MakeGenericTypeRef(typeArgs.ToImmutableArray())); } } return(part.TypeRef); }