dotnet-installer/src/Microsoft.DotNet.ProjectJsonMigration/transforms/ConditionalTransform.cs

30 lines
790 B
C#
Raw Normal View History

// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
2016-08-23 13:50:05 -07:00
namespace Microsoft.DotNet.ProjectJsonMigration.Transforms
{
internal abstract class ConditionalTransform<T, U> : ITransform<T, U>
{
private Func<T, bool> _condition;
public ConditionalTransform(Func<T,bool> condition)
{
_condition = condition;
}
public U Transform(T source)
{
if (_condition == null || _condition(source))
{
return ConditionallyTransform(source);
}
return default(U);
}
public abstract U ConditionallyTransform(T source);
}
}