///
/// Copyright © 2003-2008 JetBrains s.r.o.
/// You may distribute under the terms of the GNU General Public License, as published by the Free Software Foundation, version 2 (see License.txt in the repository root folder).
///
using System;
using System.Collections;
using Microsoft.Build.Framework;
namespace JetBrains.Build.Common.Infra
{
///
/// Static helper methods, externalized from different tasks.
///
public static class TaskHelper
{
#region Operations
///
/// Gets a string value from the bag, throws on an error.
///
public static string GetStringValue(Hashtable bag, AttributeName attribute)
{
object oValue = bag[attribute];
if(oValue == null)
throw new InvalidOperationException(string.Format("The “{0}” task input parameter must be specified.", attribute));
if(oValue is ITaskItem)
return ((ITaskItem)oValue).ItemSpec;
if(oValue is string)
return (string)oValue;
throw new InvalidOperationException(string.Format("The “{0}” task input parameter must be a string.", attribute));
}
///
/// Gets a value from the bag, throws on an error.
///
public static T GetValue(Hashtable bag, AttributeName attribute)
{
object oValue = bag[attribute];
if(oValue == null)
throw new InvalidOperationException(string.Format("The “{0}” task input parameter must be specified.", attribute));
if(oValue is T)
return (T)oValue;
throw new InvalidOperationException(string.Format("The “{0}” task input parameter must be of type {1}.", attribute, typeof(T).FullName));
}
#endregion
}
}