2016-08-22 12:21:34 -07:00
|
|
|
// 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
|
2016-08-22 12:21:34 -07:00
|
|
|
{
|
2016-10-27 18:46:43 -07:00
|
|
|
internal abstract class ConditionalTransform<T, U> : ITransform<T, U>
|
2016-08-22 12:21:34 -07:00
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|