本文整理汇总了C#中List.IsNullOrEmpty方法的典型用法代码示例。如果您正苦于以下问题:C# List.IsNullOrEmpty方法的具体用法?C# List.IsNullOrEmpty怎么用?C# List.IsNullOrEmpty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类List
的用法示例。
在下文中一共展示了List.IsNullOrEmpty方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetListings
public static List<ClassifiedsListing> GetListings(Item item, ListingProperties props,
OrderType orderType)
{
VersatileIO.Info("Searching bp.tf classifieds for {0}...", props.ToString(item));
List<ClassifiedsListing> all = ClassifiedsScraper.GetClassifieds(item, props);
List<ClassifiedsListing> res = new List<ClassifiedsListing>();
foreach (ClassifiedsListing c in all)
{
if (c.ItemInstance.Item.IsSkin())
{
continue;
}
if (c.OrderType == orderType)
{
res.Add(c);
}
}
if (res.IsNullOrEmpty())
{
VersatileIO.Warning("No classifieds found for {0}.", props.ToString(item));
return res.EmptyIfNull().ToList();
}
VersatileIO.Info("{0} listings found.", res.Count);
return res;
}
示例2: GroupSearchResults
private async Task GroupSearchResults(List<SearchHint> items)
{
if (items.IsNullOrEmpty())
{
return;
}
await TaskEx.Run(() =>
{
var emptyGroups = new List<Group<SearchHint>>();
var types = items.Select(x => x.Type).Distinct().ToList();
types.ForEach(type => emptyGroups.Add(new Group<SearchHint>(type, new List<SearchHint>())));
var groupedItems = (from t in items
group t by t.Type
into grp
orderby grp.Key
select new Group<SearchHint>(grp.Key, grp)).ToList();
Deployment.Current.Dispatcher.BeginInvoke(() =>
{
SearchResults = (from g in groupedItems.Union(emptyGroups)
#if WP8
where g.Count > 0
#else
where g.HasItems
#endif
orderby g.Title
select g).ToList();
});
});
}
示例3: AllotPower
/// <summary>
/// 给某个角色分配权限
/// </summary>
/// <param name="roleNum"></param>
/// <param name="resItems"></param>
/// <returns></returns>
public int AllotPower(string roleNum, List<string> resItems)
{
using (TransactionScope ts = new TransactionScope())
{
int line = 0;
if (!resItems.IsNullOrEmpty())
{
SysRelationEntity entity = new SysRelationEntity();
entity.Where(a => a.RoleNum == roleNum);
line = this.SysRelation.Delete(entity);
SysResourceProvider provider = new SysResourceProvider();
List<SysRelationEntity> list = new List<SysRelationEntity>();
foreach (string resNum in resItems)
{
SysResourceEntity resource = provider.GetResource(resNum);
short ResType = resource != null ? resource.ResType : (short)EResourceType.Page;
entity = new SysRelationEntity() { RoleNum = roleNum, ResNum = resNum, ResType = ResType };
entity.IncludeAll();
list.Add(entity);
}
line += this.SysRelation.Add(list);
}
ts.Complete();
if (line > 0)
{
CacheHelper.Remove(string.Format(CacheKey.JOOSHOW_ROLEPOWER_CACHE, roleNum));
CacheHelper.Remove(CacheKey.JOOSHOW_ALLOTPOWER_CACHE);
}
return line;
}
}
示例4: Create
/// <summary>
/// 创建报表文件格式
/// </summary>
/// <param name="entity"></param>
/// <param name="list"></param>
/// <returns></returns>
public int Create(ReportsEntity entity,List<ReportParamsEntity> list)
{
if (!entity.ReportNum.IsEmpty())
{
return Update(entity,list);
}
int line = 0;
using (TransactionScope ts = new TransactionScope())
{
entity.ReportNum = entity.ReportNum.IsEmpty() ? SequenceProvider.GetSequence(typeof(ReportsEntity)) : entity.ReportNum;
entity.IncludeAll();
line += this.Reports.Add(entity);
if (!list.IsNullOrEmpty())
{
foreach (ReportParamsEntity item in list)
{
item.ParamNum = item.ParamNum.IsEmpty() ? SequenceProvider.GetSequence(typeof(ReportParamsEntity)) : item.ParamNum;
item.ReportNum = entity.ReportNum;
item.IncludeAll();
}
this.ReportParams.Add(list);
}
ts.Complete();
}
return line;
}
示例5: ReturnsTrueWhenValueIsHasZeroElements
public void ReturnsTrueWhenValueIsHasZeroElements()
{
var emptyString = new List<string>();
var emptyInt = new List<int>();
emptyString.IsNullOrEmpty().Should().BeTrue();
emptyInt.IsNullOrEmpty().Should().BeTrue();
}
示例6: WhenHasElements_ShouldReturnFalse
public void WhenHasElements_ShouldReturnFalse()
{
var enumerable = new List<object>();
enumerable.Add(new { });
var actual = enumerable.IsNullOrEmpty();
Assert.False(actual);
}
示例7: ReturnsFalseWhenValueHasElements
public void ReturnsFalseWhenValueHasElements()
{
var enumerableString = new List<string> { "a", "b" };
var enumerableInt = new List<int> { 1, 2 };
enumerableString.IsNullOrEmpty().Should().BeFalse();
enumerableInt.IsNullOrEmpty().Should().BeFalse();
}
示例8: Remove
public void Remove(List<TagEntity> tags)
{
if (tags.IsNullOrEmpty())
{
return;
}
tags.Iter(x => _tags.Remove(x.EntityId));
_tagRepository.Remove(tags);
}
示例9: CurrentBindDynamicRow
public static void CurrentBindDynamicRow(
this DbDataReader reader,
List<DynamicColumn> columns,
ref DynamicRow row)
{
if(null == reader) { return; }
if(columns.IsNullOrEmpty()) { return; }
var dbValues = new object[columns.Count];
reader.GetValues(dbValues);
var flatValues = new List<Any>();
var values = new List<Any>();
var hashCodes = new List<Any>();
var dbNulls = new List<string>();
var columnIndex = -1;
foreach(var column in columns) {
columnIndex++;
var value = dbValues[columnIndex];
if(DBNull.Value == value) {
dbNulls.Add(column.BaseColumnName);
value = null;
}
flatValues.SafeAdd(column.ColumnName, value);
flatValues.SafeAdd(column.BaseColumnName, value);
values.Add(column.BaseColumnName, value);
if(null != value) {
int hashCode = value.GetHashCode();
hashCodes.Add(
column.BaseColumnName, hashCode
);
}
}
row.__ReturnAny = true;
row.__DatabaseFirst = true;
row.__DynamicColumns = columns;
row.__FlatValues = flatValues;
row.__DynamicValues = values;
row.__DynamicOriginalValues = values;
row.__OriginalHashCodes = hashCodes;
row.__DynamicDbNulls = dbNulls;
row.__OriginalHashCode = row.GetHashCode();
if(dbNulls.Any()) {
foreach(var dbNull in dbNulls) {
hashCodes.Add(
dbNull,
row.__OriginalHashCode
);
}
}
row.__OriginalHashCodes = hashCodes;
}
示例10: GetRandomLocation
/// <summary>
/// Method searches for a random location on the map. Give true for a list of availible points and false for all points.
/// </summary>
/// <param name="searchForFreePoints"></param>
/// <returns></returns>
public Vector2 GetRandomLocation(bool searchForFreePoints, List<SpawnPoint> points, bool setTaken)
{
if (points.IsNullOrEmpty())
{
return Vector2.zero;
}
SpawnPoint temp = points[(Random.Range(0, points.Count - 1))];
temp.taken = setTaken;
return temp.location;
}
示例11: IsNullOrEmpty_OneItemEnumerable_ReturnsFalse
public void IsNullOrEmpty_OneItemEnumerable_ReturnsFalse()
{
// arrange
IEnumerable<object> oneItemEnumerable = new List<object> {new object()};
// act
// assert
Assert.False(oneItemEnumerable.IsNullOrEmpty());
}
示例12: IsNullOrEmpty_EmptyEnumerable_ReturnsTrue
public void IsNullOrEmpty_EmptyEnumerable_ReturnsTrue()
{
// arrange
IEnumerable<object> emptyEnumerable = new List<object>();
// act
// assert
Assert.True(emptyEnumerable.IsNullOrEmpty());
}
示例13: CreatePackage
public ActionResult CreatePackage(string newPkgName, string newFunctions, string newMaterials, string newCompanies)
{
try
{
Package newPkg = new Package {PackageName = newPkgName};
StringToCollections(newPkg, newMaterials, newFunctions, newCompanies);
//check for repeated functions in packages
List<string> repeatedPackageNames = new List<string>();
List<string> repeatedFunctionNames = new List<string>();
IEnumerable<Employee_Function> tmpFunctionsInt;
foreach (Package aPackage in DB.Packages)
{
tmpFunctionsInt = aPackage.Functions.Intersect(newPkg.Functions);
if (tmpFunctionsInt.Any())
{
repeatedPackageNames.Add(aPackage.PackageName);
foreach (Employee_Function aFunction in tmpFunctionsInt)
{
if (!repeatedFunctionNames.Contains(aFunction.Label))
{
repeatedFunctionNames.Add(aFunction.Label);
}
}
}
}
if (!repeatedPackageNames.IsNullOrEmpty())
{
return new HttpStatusCodeResult(HttpStatusCode.Conflict, "Packages " + String.Join(", ", repeatedPackageNames)
+ " already have the following functions: " + String.Join(", ", repeatedFunctionNames));
}
newPkg.CreatedDate = DateTime.Now;
DB.Packages.Add(newPkg);
DB.SaveChanges();
Dictionary<string, string> rowInfo = new Dictionary<string, string>();
rowInfo.Add("id", newPkg.PackageId.ToString());
rowInfo.Add("pkgName", newPkg.PackageName);
rowInfo.Add("materials", String.Join(" | ", newPkg.GenericMaterials.ToDictionary(mat => mat.GenericMaterialId, mat => mat.Label).Values));
rowInfo.Add("functions", String.Join(" | ", newPkg.Functions.ToDictionary(fun => fun.FunctionId, fun => fun.Label).Values));
rowInfo.Add("companies", newPkg.Companies.Any() ? String.Join(" | ", newPkg.Companies.ToDictionary(com => com.ID, com => com.CompanyCodeName).Values) : "All Companies");
rowInfo.Add("deleteLink", Url.Action("Delete", "Package"));
rowInfo.Add("editLink", Url.Action("GetPackageDetails", "Package"));
return Json(rowInfo);
}
catch (Exception ex)
{
return new HttpStatusCodeResult(HttpStatusCode.InternalServerError, ex.Message);
}
}
示例14: GainItem
public void GainItem(List<string> args)
{
if(args.IsNullOrEmpty())
throw new ArgumentNullException("GainItem requires a list containing the item to gain, and the quantity.");
string itemName = args[0];
int quantity = Convert.ToInt32(args[1]);
InventoryItem item = _itemDatabase.FindItemWithName(itemName);
if(item != default(InventoryItem))
_inventory.GainItem(item, quantity);
DebugMessage("Could not find item " + itemName + " in the inventory database.", LogLevel.LogicError);
}
示例15: GenerateFilterLocationRequest
public static string GenerateFilterLocationRequest(List<ILocation> locations)
{
if (locations.IsNullOrEmpty())
{
return String.Empty;
}
StringBuilder queryBuilder = new StringBuilder();
// queryBuilder.Append("locations=");
for (int i = 0; i < locations.Count - 1; ++i)
{
queryBuilder.Append(GenerateLocationParameters(locations[i], false));
}
queryBuilder.Append(GenerateLocationParameters(locations[locations.Count - 1], true));
return String.Format("locations={0}", StringFormater.UrlEncode(queryBuilder.ToString()));
}