本文整理汇总了C#中DataRecord.GetValueOrNull方法的典型用法代码示例。如果您正苦于以下问题:C# DataRecord.GetValueOrNull方法的具体用法?C# DataRecord.GetValueOrNull怎么用?C# DataRecord.GetValueOrNull使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DataRecord
的用法示例。
在下文中一共展示了DataRecord.GetValueOrNull方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: get_value_or_null_returns_null_if_column_is_not_found
public void get_value_or_null_returns_null_if_column_is_not_found()
{
var data = new DataRecord(new HeaderRecord(true, "Name", "Age", "Gender", "Relationship Status"), true, "Kent", "25", "M");
Assert.Null(data.GetValueOrNull("foo"));
Assert.Null(data.GetValueOrNull("name"));
Assert.Null(data.GetValueOrNull("GENDER"));
Assert.Null(data.GetValueOrNull("Relationship Status"));
}
示例2: get_value_or_null_throws_if_column_name_is_null
public void get_value_or_null_throws_if_column_name_is_null()
{
var data = new DataRecord(new HeaderRecord(new string[] { "Name", "Age", "Gender" }));
var ex = Assert.Throws<ArgumentNullException>(() => data.GetValueOrNull(null));
}
示例3: get_value_or_default_returns_value_in_column
public void get_value_or_default_returns_value_in_column()
{
var data = new DataRecord(new HeaderRecord(true, "Name", "Age", "Gender", "Relationship Status"), true, "Kent", "25", "M");
Assert.Equal("Kent", data.GetValueOrNull("Name"));
Assert.Equal("25", data.GetValueOrNull("Age"));
Assert.Equal("M", data.GetValueOrNull("Gender"));
}
示例4: get_value_or_null_throws_if_there_is_no_header
public void get_value_or_null_throws_if_there_is_no_header()
{
var data = new DataRecord(null);
var ex = Assert.Throws<InvalidOperationException>(() => data.GetValueOrNull("anything"));
Assert.Equal("No header record is associated with this DataRecord.", ex.Message);
}
示例5: CreateCSVUser
protected User CreateCSVUser(DataRecord record)
{
var role = (int)Enum.Parse(typeof(Role), record.GetValueOrNull("Role") ?? "Student");
var password = record.GetValueOrNull("Password");
if (string.IsNullOrEmpty(password))
{
password = this.RandomPassword();
}
var user = new User
{
Id = Guid.NewGuid(),
Username = record.GetValueOrNull("Username") ?? string.Empty,
Password = password,
Email = record.GetValueOrNull("Email") ?? string.Empty,
Name = record.GetValueOrNull("Name") ?? string.Empty,
OpenId = record.GetValueOrNull("OpenId") ?? string.Empty,
Deleted = false,
IsApproved = true,
ApprovedBy = this.GetCurrentUser().Id,
CreationDate = DateTime.Now,
};
if (!string.IsNullOrEmpty(user.OpenId) && !this.UserOpenIdAvailable(user.OpenId, Guid.Empty))
{
user.OpenId = string.Empty;
}
user.UserRoles.Add(new UserRole { RoleRef = role, UserRef = user.Id });
return user;
}