private static IEnumerable <IResType> ResolveBaseClass(dnlib.DotNet.TypeDef source, Resolver resolver, out IResType?result) { // If the base type is not an object.. result = source.BaseType?.FullName.Equals("System.Object", StringComparison.InvariantCulture) == false // resolve the base type ? resolver.Resolve(source.BaseType.ToTypeSig(), source.ResolveTypeGenerics()) // otherwise return a null base type : null; return(result == null ? Enumerable.Empty <IResType>() : new[] { result }); }
private static IReadOnlyDictionary <string, (Variance variance, IReadOnlyCollection <IResType>)> ResolveGenericStructs(Resolver resolver, dnlib.DotNet.TypeDef source, dnlib.DotNet.TypeDef?parent) { IResType ResolveType(GenericParamConstraint x, IReadOnlyDictionary <string, string> generics) => resolver.Resolve(x.Constraint.ToTypeSig(), generics); (Variance, IReadOnlyCollection <IResType>) ResolveParameter(GenericParam parameter, IReadOnlyDictionary <string, string> generics) { // If the parameter has no generic constraints.. if (!parameter.HasGenericParamConstraints) { // return default return(Variance.NonVariant, Enumerable.Empty <IResType>().ToArray()); } // Otherwise return the list of constraints return(Variance.NonVariant, parameter.GenericParamConstraints.Select(x => ResolveType(x, generics)).ToReadOnlyCollection()); } return(source.GenericParameters // Exclude generic parameters from the parent .Except(parent?.GenericParameters ?? Enumerable.Empty <GenericParam>(), EqualityComparerEx <GenericParam> .Create(x => x.Name, x => x.Name)) // Materialize the result as a dictionary .ToDictionary(param => param.Name.String, param => ResolveParameter(param, source.ResolveTypeGenerics()))); }