我有下一个结构的DTO:
public class DTO
{
public int Id {get;set;}
[JsonProperty("Id")]
public int ServerId {get;set;}
}
Run Code Online (Sandbox Code Playgroud)
从服务器我收到下一个型号的json:
public class ServerModel
{
public int Id {get;set;}
}
Run Code Online (Sandbox Code Playgroud)
我想=> Id从服务器映射到ServerId属性将服务器映射中的json反序列化为DTO .但目前我得到错误:
名为"Id"的成员已存在
DTO.使用JsonPropertyAttribute指定其他名称.
我能解决这个问题吗?或者我只是可以更改我的ServerModel以匹配我在客户端(DTO)上的内容?
在SQL Server中,我可以使用此SQL语句:
SELECT *
FROM Customers
WHERE Country LIKE '%land%';
Run Code Online (Sandbox Code Playgroud)
此查询将返回包含字符串的值land.
是否可以按字符串的位置对返回值进行排序land?
例:
输入值:"新西兰,美国,Landcountry,Alandia"
产值:"Landcountry,Alandia,New Zealand"
我有阵列.此数组中的每个元素都是object,它也包含数组.所以我需要得到数组中存在于数组中的每个项目的总和.
我接下来试过了:
function getSum(total, item) {
return total + item;
}
var sum = array.reduce((total, item) => total + item.data.reduce(getSum));
Run Code Online (Sandbox Code Playgroud)
但它不是总和,而是字符串,以Object... 开头
我有项目的解决方案。我也有 msbuild 文件的解决方案目录文件夹。
在 msbuild 文件中,我有下一个代码:
<PropertyGroup Label="Build Directories">
<RootPath>$([System.IO.Path]::GetFullPath('$(MSBuildProjectDirectory)'))</RootPath>
</PropertyGroup>
<ItemGroup>
<MSBuildProjectInfrastructure Include="$(RootPath)MyApp.Services.Infrastructure.sln">
<AdditionalProperties>Configuration=$(Configuration);Platform=$(Platform);</AdditionalProperties>
</MSBuildProjectInfrastructure>
</ItemGroup>
Run Code Online (Sandbox Code Playgroud)
效果不佳,因为我需要进入父目录才能找到 MyApp.Services.Infrastructure.sln
结构 :
SolutionFolder
-- MsBuildsFolder
-- ProjectFile
Run Code Online (Sandbox Code Playgroud)
这是非常相似的问题,但没有解决我的问题
我创建了两个扩展方法:FilterAnyType上运行IEnumberable<T>,并FilterMovieType上进行操作IEnumerable<Movie>:
public static IEnumerable<T> FilterAnyType<T>(this IEnumerable<T> source, Func<T,bool> predicate)
{
//code goes here
}
public static IEnumerable<Movie> FilterMovieType<Movie>(this IEnumerable<Movie> source, Func<Movie, bool> predicate)
{
//code goes here
}
Run Code Online (Sandbox Code Playgroud)
然后,我创建了两个不同的列表:
var movies = new List<Movie>();
var customers = new List<Customer>();
Run Code Online (Sandbox Code Playgroud)
正如预期的那样,该FilterAnyType方法可用于的两个实例movie和customers。但是,该方法FilterMovieType也可用于customer实例,并且我没有想到这一点。
我正在学习扩展方法(因此有这种做法),而我的理解方式是,该this关键字用于标识扩展方法将被“添加”到的对象的类型。
鉴于此,我希望FilterMovieType仅适用于的实例IEnumerable<Movie>。为什么也可以使用IEnumerable<Customer>?
谢谢!!
我想将简单的html页面添加为IIS的自定义错误。所以我添加404.html和500.html页面进行项目并添加下一个配置:
<httpErrors errorMode="Custom" existingResponse="Replace">
<remove statusCode="404" />
<remove statusCode="500" />
<error statusCode="404" path="404.html" responseMode="File" />
<error statusCode="500" path="500.html" responseMode="File" />
</httpErrors>
Run Code Online (Sandbox Code Playgroud)
HTML页面位于Views/Shared文件夹中。但是每次我走到一条不存在的道路时,我都会/foo/bar收到The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.不是我的错误消息。
对于ASP.Net的自定义错误,我添加下一个配置:
<customErrors mode="On" redirectMode="ResponseRewrite" defaultRedirect="~/Home/404">
<error statusCode="404" redirect="~/Home/404" />
<error statusCode="500" redirect="~/Home/500" />
</customErrors>
Run Code Online (Sandbox Code Playgroud)
并filters.Add(new HandleErrorAttribute());从FilterConfig文件中删除此行。
我发现html页面正确路径或更改/为的可能问题,\但没有人发现对我有用的解决方案。
我使用IIS7 +
我有DateTime和date的值作为字符串.字符串日期可以是未知的格式(在我的箱子2 1:"MMM dd yyyy"或"dd MMM").我需要检查日期是否相等.
除了尝试使用第一种和第二种格式解析字符串日期以及是否返回DateTime而不是与DateTime类型进行比较之外,还有其他解决方案吗?
我使用 Typescript 创建了类/viewModel。我将此类中的一个字段设置为私有字段,以便在尝试获取所有其他类属性时跳过它。
对吗?我怎样才能跳过我的私有财产?
Object.keys(myObject).forEach(property => {
//some stuff
}
});
Run Code Online (Sandbox Code Playgroud)
我的班级示例:
class MyModel{
id: any = ko.observable('');
name: any = ko.observable('');
address: any = ko.observable('');
city: any = ko.observable('');
state: any = ko.observable('');
country: any = ko.observable('');
private secretField= ko.observable('');
}
Run Code Online (Sandbox Code Playgroud) 我有tableEntity包含byte[]属性
[StorageTableName("TestTable")]
public class TestTableEntity : TableEntity
{
public byte[] Data { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
在这个属性中我想把一些文件转换成字节(如果它不正确 - 请建议另一个解决方案).
var table = tableStorage.Table<TestTableEntity>();
await table.CreateIfNotExistsAsync();
var entity = new TestTableEntity
{
Data = data, //byte[]
PartitionKey = partitionKey, //date
RowKey = schemaName// string
};
await table.InsertOrUpdateAsync(entity);
Run Code Online (Sandbox Code Playgroud)
插入的步骤我得到错误
远程服务器返回错误:(413)请求正文太大并超出了允许的最大限制.
因为数组真的很大.
有什么方法可以解决这个问题吗?
c# ×4
arrays ×2
javascript ×2
.net ×1
asp.net ×1
asp.net-mvc ×1
azure ×1
datetime ×1
directory ×1
ecmascript-6 ×1
http-error ×1
iis ×1
json ×1
json.net ×1
knockout.js ×1
large-files ×1
mapping ×1
modifiers ×1
msbuild ×1
parent ×1
reduce ×1
sql ×1
sql-like ×1
sql-server ×1
string ×1
sum ×1
targets ×1
typescript ×1
where ×1