我需要创建能够将平面对象转换为递归对象的函数.这是我的例子:我有平面阵列:
var flatArray = [
{
Description: "G",
guid: "c8e63b35",
parent: null,
},
{
Description: "Z",
guid: "b1113b35",
parent: "c8e63b35",
},
{
Description: "F",
guid: "d2cc2233",
parent: "b1113b35",
},
{
Description: "L",
guid: "a24a3b1a",
parent: null,
},
{
Description: "K",
guid: "cd3b11caa",
parent: "a24a3b1a",
},
]
Run Code Online (Sandbox Code Playgroud)
结果应该是:
recursiveArray = [
{
Description: "G",
guid: "c8e63b35",
parent: null,
Children: [
{
Description: "Z",
guid: "b1113b35",
parent: "c8e63b35",
Children: [
{
Description: "F",
guid: "d2cc2233",
parent: "b1113b35",
}
]
},
]
}, …Run Code Online (Sandbox Code Playgroud) 我想知道是否可以从c#中的其他项目访问内部类变量.我知道在常规使用中这是不可能的,我在下面解释.
我有一个项目(P1 [类库])包含这些类...
internal class Settings
{
public static long size {get;set;}
public static DoSomethingInternalOnly()
{
}
}
public class Program
{
public static Main()
{
}
}
Run Code Online (Sandbox Code Playgroud)
......和另一个(P2)包含:
public class Program
{
public static Main()
{
//P1.CopyOfSettings.size = 2048; ???
}
}
Run Code Online (Sandbox Code Playgroud)
在Settings类中,我存储了app的内部变量(和方法),这些变量在其他项目中是看不到的.但是这些设置需要以某种方式从P2传递到P1所以我需要P2中的第二类"Settings2"包含相同的变量(仅变量!)作为带有public关键字的"Settings".
我觉得创建包含相同变量的几个类是浪费时间并使代码不可读.有没有更好的方法来实现这一目标?
我想知道是否有可能(在 javascript 或 jquery 但没有任何插件的情况下)在当前视口中获取所有元素(例如表行 tr)而不遍历每个元素?我找到了很多如何检查指定元素是否在当前视口中的示例,但我需要的是一个函数返回当前视口中所有元素的列表。我需要这个来进行虚拟化,因为这个表应该有无限的容量,从两百万行循环遍历每一行效率很低:)
有什么合理的方法可以做到这一点吗?
我的 Xamarin Forms 应用程序中有以下按钮
<Button
Grid.Column="1"
Grid.Row="0">
<Button.ImageSource>
<FontImageSource Glyph="" FontFamily="{StaticResource IconFont}" Color="{StaticResource BaseColor}"/>
</Button.ImageSource>
</Button>
Run Code Online (Sandbox Code Playgroud)
在哪里IconFont:
<OnPlatform x:TypeArguments="x:String" x:Key="IconFont">
<On Platform="Android" Value="materialdesignicons-webfont.ttf#Material design" />
<On Platform="iOS" Value="Material Design Icons" />
</OnPlatform>
Run Code Online (Sandbox Code Playgroud)
一切正常。现在,因为我的所有图标都在里面materialdesignicons-webfont并且我永远不会使用不同的图标,所以我决定将整个样式移动到 App.xaml。我想设置这样的默认属性:
<Style TargetType="FontImageSource">
<Setter Property="FontFamily" Value="{StaticResource IconFont}" />
<Setter Property="Color" Value="{StaticResource BaseColor}" />
</Style>
Run Code Online (Sandbox Code Playgroud)
并仅通过传递字形来使用按钮。
<Button
Grid.Column="1"
Grid.Row="0">
<Button.ImageSource>
<FontImageSource Glyph=""/>
</Button.ImageSource>
</Button>
Run Code Online (Sandbox Code Playgroud)
对于一些原因图标不渲染不指定FontFamily和Color直接FontImageSource。我错过了什么吗?
有没有办法以更简单的方式调用我的按钮?铁
<Button
Grid.Column="1"
Grid.Row="0"
MDGlyph="" />
Run Code Online (Sandbox Code Playgroud) Microsoft.Extensions.DependencyInjection.IServiceScope我在课堂上注入时遇到问题。
我的服务实现:
public class AccountService : IAccountService
{
private readonly IConfiguration _configuration;
private readonly IServiceScope _services;
public AccountService(
IConfiguration configuration,
IServiceScope services) // <-- I can't inject this
{
_configuration = configuration;
_services = services;
}
public async Task CreateAccount(ExternalAccount externalAccount)
{
(some code...)
}
}
Run Code Online (Sandbox Code Playgroud)
在startup.cs中:
services.AddTransient<IAccountService, AccountService>();
Run Code Online (Sandbox Code Playgroud)
问题是项目在上述行之后崩溃并出现以下错误:
某些服务无法构建(验证服务描述符“ServiceType:IDS.Quickstart.Account.IAccountService 生命周期时出错:瞬态实现类型:IDS.Quickstart.Account.AccountService”:无法解析类型“Microsoft.Extensions”的服务。尝试激活“IDS.Quickstart.Account.AccountService”时出现 DependencyInjection.IServiceScope”。) ---> System.InvalidOperationException:验证服务描述符“ServiceType:IDS.Quickstart.Account.IAccountService 时出错”生命周期:瞬态实现类型:IDS。 Quickstart.Account.AccountService”:尝试激活“IDS.Quickstart.Account.AccountService”时无法解析类型“Microsoft.Extensions.DependencyInjection.IServiceScope”的服务。
我的代码拒绝工作的原因是什么?
我需要创建应用程序,它将在循环中ping多个地址.我在stackoverflow上阅读了很多例子,最后得到了工作代码:
public void Check(List<string> addresses)
{
List<Task<PingReply>> pingTasks = new List<Task<PingReply>>();
foreach (string address in addresses)
{
pingTasks.Add(PingAsync(address));
}
Task.Factory.ContinueWhenAll(pingTasks.ToArray(), _ => { }).ContinueWith(t =>
{
StringBuilder pingResult = new StringBuilder();
foreach (var pingTask in pingTasks)
{
pingResult.Append(pingTask.Result.Address);
pingResult.Append(" ");
pingResult.Append(pingTask.Result.Status);
pingResult.Append(" ");
pingResult.Append(pingTask.Result.RoundtripTime.ToString());
pingResult.Append(" \n");
}
Console.WriteLine(pingResult.ToString());
},
CancellationToken.None,
TaskContinuationOptions.None,
TaskScheduler.FromCurrentSynchronizationContext());
}
public static Task<PingReply> PingAsync(string address)
{
var tcs = new TaskCompletionSource<PingReply>();
using (Ping ping = new Ping())
{
ping.PingCompleted += (obj, sender) =>
{
tcs.SetResult(sender.Reply);
};
ping.SendAsync(address, …Run Code Online (Sandbox Code Playgroud) 我需要创建一个返回分层json结果的SQL查询(postgres 9.5.3).这是我到目前为止编写的代码
WITH RECURSIVE q AS (
WITH c AS (
SELECT pc."Id", pc."Description"
FROM "ProductCategories" pc
WHERE pc."Active" = true
)
SELECT pc, ARRAY[c] as "Children", ARRAY[pc."Id"] as "Path"
FROM "ProductCategories" pc
LEFT JOIN c ON pc."Id" = c."Id"
WHERE NULLIF(pc."ParentId", 0) IS NULL
AND pc."Active" = true
UNION ALL
SELECT pc_descendant, array_append(q."Children", c), q."Path" || pc_descendant."Id"
FROM q
JOIN "ProductCategories" pc_descendant ON pc_descendant."ParentId" = (q.pc)."Id"
LEFT JOIN c ON pc_descendant."Id" = c."Id"
WHERE pc_descendant."Active" = true
)
SELECT …Run Code Online (Sandbox Code Playgroud) 有没有办法减少svg路径厚度?我有以下 svg 格式的图标,但此图标是由单个路径制作的。调整属性“填充”或“笔画宽度”不起作用。
我想要做的是将可见边框的厚度减少一半。
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" viewBox="0 0 32 32">
<g>
<path d="M24,14.059V5.584L18.414,0H0v32h24v-0.059c4.499-0.5,7.998-4.309,8-8.941C31.998,18.366,28.499,14.556,24,14.059z M17.998,2.413L21.586,6h-3.588V2.413z M2,30V1.998h14v6.001h6v6.06c-1.752,0.194-3.352,0.89-4.652,1.941H4v2h11.517 c-0.412,0.616-0.743,1.289-0.994,2H4v2h10.059C14.022,22.329,14,22.661,14,23c0,2.829,1.308,5.351,3.349,7H2z M23,29.883 c-3.801-0.009-6.876-3.084-6.885-6.883c0.009-3.801,3.084-6.876,6.885-6.885c3.799,0.009,6.874,3.084,6.883,6.885 C29.874,26.799,26.799,29.874,23,29.883z M20,12H4v2h16V12z" style="/* transform: scale(0.5, 0.5); *//* stroke: black; */"/>
<g>
<polygon points="28,22 24.002,22 24.002,18 22,18 22,22 18,22 18,24 22,24 22,28 24.002,28 24.002,24 28,24 "/>
</g>
</g>
</svg>Run Code Online (Sandbox Code Playgroud)
有没有可以做到这一点的在线编辑器?或者也许有一些我不知道的 css 技巧?
我有以下查询:
SELECT s."Description",
sp.*
FROM "Supplier" as s
OUTER APPLY (
SELECT p."Id", p."Description", p."Price"
FROM "Products" as p
WHERE p."SupplierId" = s."Id"
FOR JSON auto
) as sp
Run Code Online (Sandbox Code Playgroud)
我正在尝试根据OUTER APPLY结果构建 json 数组,但我卡在这里是因为有一个错误,No column name was specified for column 1 of 'sp'.我在 stackoverflow 上发现了类似的问题,但没有外部应用的示例。
你能解释一下这个查询有什么问题吗?
我有Delphi的问题.
我写了一个这样的函数:
function MyFunction(arr: array of AnsiString): Boolean;
begin
//code here
end;
Run Code Online (Sandbox Code Playgroud)
而现在,当我将一个AnsiString直接传递给函数的数组时,就像这样,一切都很完美:
MyFunction(['one', 'two', 'three']);
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试像这样存储这个数组时:
var arr: array of AnsiString;
procedure MyProcedure;
begin
arr[0] := ['one', 'two', 'three'];
MyFunction(arr[0]);
end;
Run Code Online (Sandbox Code Playgroud)
存在不匹配错误.
我是Delphi的初学者,但这真的令人困惑.
c# ×3
algorithm ×2
javascript ×2
.net ×1
.net-core ×1
arrays ×1
async-await ×1
delphi ×1
html ×1
internal ×1
ping ×1
postgresql ×1
recursion ×1
sql ×1
sql-server ×1
svg ×1