public virtual ArgumentComparer GetArgumentComparer(Type type, bool isInvocationTarget = false) { var comparerType = MatchingTypeFinder.TryFind(type, typeof(ArgumentComparerProvider)); if (comparerType != null) { return(CreateComparer(comparerType)); } if (isInvocationTarget) { return(ByRefArgumentComparer.Instance); } var equatableType = typeof(IEquatable <>).MakeGenericType(type); if (equatableType.IsAssignableFrom(type)) { var eacType = typeof(EquatableArgumentComparer <>).MakeGenericType(type); var eac = (EquatableArgumentComparer)CreateComparer(eacType); if (eac.IsAvailable) { return(eac); } } return(ArgumentComparer.Default); }
public void BasicMatchTest() { var scope = GetType(); var finder = new MatchingTypeFinder(scope.Assembly); finder.TryFind(typeof(object), null !).Should().BeNull(); finder.TryFind(typeof(int), scope).Should().Be(typeof(MatchForInt)); finder.TryFind(typeof(bool), scope).Should().Be(typeof(MatchForValueType)); finder.TryFind(typeof(MatchingTypeFinderTest), scope).Should().BeNull(); finder.TryFind(typeof(object), scope).Should().BeNull(); ((Action)(() => finder.TryFind(null !, scope))).Should().Throw <ArgumentNullException>(); }
public void GenericMatchTest() { var scope = GetType(); var finder = new MatchingTypeFinder(scope.Assembly); finder.TryFind(typeof(NoMatch <int>), scope).Should().BeNull(); finder.TryFind(typeof(Lazy <int>), scope).Should().Be(typeof(MatchForLazy <int>)); finder.TryFind(typeof(Lazy <bool>), scope).Should().Be(typeof(MatchForLazy <bool>)); finder.TryFind(typeof(Derived1), scope).Should().Be(typeof(MatchForG1 <int>)); finder.TryFind(typeof(Derived2), scope).Should().Be(typeof(MatchForG2 <int, string>)); finder.TryFind(typeof(Derived1D), scope).Should().Be(typeof(MatchForG1 <int>)); finder.TryFind(typeof(Derived2D), scope).Should().Be(typeof(MatchForG2 <int, string>)); }
/// <inheritdoc/> protected override void BuildRenderTree(RenderTreeBuilder builder) { if (Source == null) { WhenNull?.Invoke(builder); return; } var componentType = MatchingTypeFinder.TryFind(Source.GetType(), Scope); if (componentType == null) { if (WhenNoMatchFound == null) { throw Errors.NoMatchingComponentFound(Source.GetType(), Scope); } WhenNoMatchFound(Source)(builder); return; } var i = 0; builder.OpenComponent(i++, componentType); if (!string.IsNullOrEmpty(SourceParameterName)) { builder.AddAttribute(i++, SourceParameterName, Source); } if (Attributes != null) { foreach (var(key, value) in Attributes) { builder.AddAttribute(i++, key, value); } } builder.CloseComponent(); }