我想为我的 SignInManager 创建一个自定义类,所以我创建了一个继承自的类,SignInManager<>如下所示:
public class ApplicationSignInManager : SignInManager<ApplicationUser>
{
private readonly UserManager<ApplicationUser> _userManager;
private readonly ApplicationDbContext _dbContext;
private readonly IHttpContextAccessor _contextAccessor;
public ApplicationSignInManager(
UserManager<ApplicationUser> userManager,
IHttpContextAccessor contextAccessor,
IUserClaimsPrincipalFactory<ApplicationUser> claimsFactory,
IOptions<IdentityOptions> optionsAccessor,
ILogger<SignInManager<ApplicationUser>> logger,
ApplicationDbContext dbContext,
IAuthenticationSchemeProvider schemeProvider
)
: base(userManager, contextAccessor, claimsFactory, optionsAccessor, logger, schemeProvider)
{
_userManager = userManager ?? throw new ArgumentNullException(nameof(userManager));
_contextAccessor = contextAccessor ?? throw new ArgumentNullException(nameof(contextAccessor));
_dbContext = dbContext ?? throw new ArgumentNullException(nameof(dbContext));
}
}
Run Code Online (Sandbox Code Playgroud)
然后我将它添加到服务配置中Startup.cs:
services.AddDefaultIdentity<ApplicationUser>(configure =>
{
configure.User.AllowedUserNameCharacters += " …Run Code Online (Sandbox Code Playgroud) 我有一个带有以下签名的方法:
public Guid FindTermIDFromCustomProperty()
{
// Logic here to find an item and return the guid
}
Run Code Online (Sandbox Code Playgroud)
我的问题是,如果在函数中没有找到任何项目,那么将不会返回GUID - 这不用说了!但有没有办法返回一些平淡的GUID?
更好的是,我可以采用更通用的方法,不仅仅是针对GUID,而且通常在我返回强类型时?我真的不想将对象用作返回类型,必须有更好的方法.
提前致谢.
我将我的模型类设置为整数属性,就像它们存储在数据库中一样.因此,示例模型可能如下所示:
public class TaskModel
{
public int TaskId { get; set; }
public int TaskStatus { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
但是在我的实际业务类中,我想使用枚举,因此匹配的业务类看起来像:
public class Task
{
public int TaskId { get; set; }
public Status TaskStatus { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
然后,我想使用Automapper的LINQ投影功能来查询这些业务类,例如:
return db.Tasks.Where( t => t.TaskStatus == 1 ).Project().To<Task>();
Run Code Online (Sandbox Code Playgroud)
但是,当我这样做时,我收到此错误:
无法从System.Int32到MyNamespace.TaskStatus创建映射表达式
我已经能够通过设置映射来解决它:
Mapper.CreateMap<TaskModel, Task>()
.ForMember(t => t.TaskStatus, opt => opt.MapFrom(m => (TaskStatus)m.TaskStatus))
.ReverseMap();
Run Code Online (Sandbox Code Playgroud)
这似乎有效(到目前为止),但我的问题是有更好或更干燥的方法来做到这一点.问题是我需要为大量模型和类中的大量属性执行此操作.似乎应该有一种更简单的方法来完成本质上简单的转换,必须编写100行的映射代码.
我在C#WinForm程序中有登录表单和主表单.
当我处于主窗体并且用户没有按任何键或移动鼠标5分钟时 - 我想转到登录表单.
如何在C#WinForm中执行此操作?
提前致谢
我有一个使用GDI +绘制的自定义UserControl.它是一个透明控件,在父控件的顶部绘制小形状.
所有父窗口都创建控件,为其绘制一个Rectangle以在其中绘制自身,然后在用户单击非透明区域时接收事件.
绘图部分工作正常,但现在我需要做的是尽可能无缝地将所有MouseMove,MouseClick等事件转发到父控件,如果这些事件发生在形状之外.
使用GraphicsPath绘制形状,我已经能够使用GraphicsPath.IsVisible()检测鼠标位置是否在形状上.
我希望以一种在父级上需要零或最少额外代码的方式执行此操作.父母不一定知道MouseMove事件是否是从子控件转发的,它应该平等对待它们.
我必须使用pinvoke/SendMessage()来执行此操作吗?或者使用.NET框架有更简单的方法吗?
当两者都是instanceof对象时,javascript中对象和函数之间的确切区别是什么?
var obj = {};
function t(){}
console.log(obj instanceof Object); //true
console.log(t instanceof Object); //true
console.log(typeof obj); //object
console.log(typeof t); //function
Run Code Online (Sandbox Code Playgroud) 我正在尝试匹配以下 </strong> ....<strong> 之间的内容
\n\n\n\n\n"\\n<strong>地址:</strong>\xc2\xa0<br>\\nHennessy Park Hotel, 65, Ebene Cybercity, Ebene \\n<br>\\<strong>电话:</strong>\ xc2\xa0(230)\xc2\xa0403\xc2\xa07200<br>\\n\\n<strong>传真:</strong>\xc2\xa0(230)\xc2\xa0403\xc2\xa07201<br> \\n<strong>联系人:</strong>\xc2\xa0<a href="/contact.html">发送电子邮件</a><br>\\n\\n<p>\\n ”
\n
有没有办法做到这一点。目前我正在使用
\n\nMatch result = Regex.Match(box.InnerHtml, @"<\\/strong>(.*?)<strong>", RegexOptions.ECMAScript);\nRun Code Online (Sandbox Code Playgroud)\n\n但我没有得到我想要的内容。
\n我有一个“主框架”(仅包含 CommandBar)和一些子框架,它们最初位于集线器中。基本上,当通过“OnNavigated..”单击一个集线器元素时,框架会发生变化。
现在我有一些按钮(例如 1 和 2)不应该是可见的,只有在选择了某些帧时:
我已经尝试过使用 getter 和 setter 方法:
在 Master-Frame 代码方法中:
public static Visibility setVisibility
{
set { Button1.Visibility = value; }
}
Run Code Online (Sandbox Code Playgroud)
并在后面的 Frame1 代码中:
MasterFrame.setVisibility = Visibility.Visible;
Run Code Online (Sandbox Code Playgroud)
但是我从 Button1 收到错误“对象引用是...”,因为我必须使用“静态”修饰符才能从 Frame1 访问按钮。
我怎样才能访问按钮?
我什至不知道我是否对代码隐藏使用了“正确”的方法,但是 MVVM 似乎没有用,因为这不是 CRUD 应用程序(没有用户输入的简单信息。)
出于某种原因,我们得到"InvalidOperationException:Object目前正在其他地方使用."
在我们的自定义OnPaint中,下面(实际上几乎是一行代码的行副本......那里有那么少).
我们已经登录下面的异常处理程序来检测我们是否以某种方式从非UI线程调用OnPaint ......并且没有被触发,但我们记录了该错误(请参阅下面的堆栈跟踪).
在我们遇到这些错误的机器上,我们也看到了来自其他控件的可怕的Red X ofom(可能在他们的OnPaints周围没有try/catch).
它们可能是相关的,但如果仅从UI线程调用此代码,我无法弄清楚可能导致该错误的原因.
有任何想法吗?
这是堆栈跟踪:
System.InvalidOperationException:Object目前正在其他地方使用.
在 System.Windows.Fornd.DtrolBorderSimple的
System.Drawing.Graphics.DrawRectangle(Pen pen,Int32 x,Int32 y,Int32 width,Int32 height)的System.Drawing.Graphics.CheckErrorStatus(Int32 status)处
(图形图形,矩形范围,Colour彩色,ButtonBorderStyle风格)
在System.Windows.Forms.ControlPaint.DrawBorder(图形图像,矩形范围,Colour彩色,ButtonBorderStyle风格)
在MyUserControl.OnPaint(PaintEventArgs的E)
这是班级:
public class MyUserControl : UserControl
{
// Override this to set your custom border color
protected Color mBorderColor = SystemColors.ControlDarkDark;
public MyeUserControl()
: base()
{
this.BorderStyle = BorderStyle.None;
this.Padding = new Padding(1);
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
try
{
ControlPaint.DrawBorder(e.Graphics, this.ClientRectangle, mBorderColor, ButtonBorderStyle.Solid);
}
catch (Exception ex)
{
// check if we're not …Run Code Online (Sandbox Code Playgroud) 我需要一些帮助.
我正在尝试将信息存储在列表中.
例如,用户输入数字,年龄,地址和头发颜色......
我想在列表中创建列表来存储信息,如下所示:
[0] Number
----[0] Age
----------[0] Address
----------[1] Adrress
--------------[0] Hair Color
Run Code Online (Sandbox Code Playgroud)
如果有更好的方法,请帮助我!
列表中的列表我会很困惑,但如果它是更好的解决方案,我没有问题.
我有一个查询(其中包括)寻找可以在某一天进行轮班的人.
SELECT secud_id, secud_fname, secud_sname, user_id, user_owner, user_level, shift_start, GROUP_CONCAT(DISTINCT uq_name SEPARATOR ' ') quals
FROM user_data
INNER JOIN users ON user_data.secud_ulink = users.user_id
LEFT JOIN user_quals ON users.user_id = user_quals.uq_user
LEFT JOIN shifts ON shifts.shift_user = users.user_id
WHERE users.user_owner = 2
AND users.user_level= 'Personnel'
AND (date(shifts.shift_start) <> '2016-03-16' OR date(shifts.shift_start) IS NULL)
AND users.user_active = 1
GROUP BY users.user_id
ORDER BY secud_sname ASC
Run Code Online (Sandbox Code Playgroud)
为了解释结构,用户是用户主表,user_quals持有各种证书等(对于该用户可能是空的,或者有许多条目),user_data为用户保存各种信息并且轮班保存班次日期和时间,地点等(也可能有很多或没有).
我主要得到的是我想要的东西 - 具有属于特定组织(user_owner)的资格的活跃用户列表,其user_level为Personnel,在该日期没有转移,但是如果他们是发现在另一个日期有转变当然符合WHERE条款.如果他们在那个日期有转变,即使它们可能在其他行中返回,我也不希望它们出现.
任何指导都非常感谢.
所以我有这门课
namespace WindowsFormsApplication2
{
public class Records
{
public string name, surname;
public int num;
}
}
Run Code Online (Sandbox Code Playgroud)
我想创建一个这个类的数组,尝试了一切,它仍然无法工作,我开始认为这是一个错误,我使用Visual Studio 2012,这是我的代码.任何帮助将不胜感激.
(表单上有一个记录的数据网格,我从文本框中读取,信息与制表符分开)
namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
Records[] userRecs = new Records[20];
public int count = 0;
private void Form1_Load(object sender, EventArgs e)
{
getText();
}
public void getText()
{
FileStream fs = new FileStream("D:\\filestr.txt",FileMode.Open);
StreamReader sr = new StreamReader(fs);
for (string readed = sr.ReadLine(); readed != null; readed = sr.ReadLine()) …Run Code Online (Sandbox Code Playgroud) 我有这个哈希:
{
a: [1,2],
b: [1,2,3]
}
Run Code Online (Sandbox Code Playgroud)
我需要生成一个这样的字符串:
一个= 1&A = 2&B = 1&B = 2&B = 3
我怎么解决这个问题 ?我正在看看lodash,但我无法解决它.
谢谢.
c# ×9
javascript ×2
winforms ×2
asp.net-core ×1
automapper ×1
list ×1
mousemove ×1
mvvm ×1
mysql ×1
nested-lists ×1
paint ×1
parent ×1
projection ×1
regex ×1
xaml ×1