- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我想在 Asp.net Identity 2.0 中扩展 UserValidator 或类似的东西,不仅检查唯一的电子邮件,而且检查我选择的唯一值。下面是我想用 Alias 做什么的例子。这可能吗,还是我必须在所有可以更新 Alias 的地方写一张支票?
public class ApplicationUserManager : UserManager<ApplicationUser, int>
{
public ApplicationUserManager(IUserStore<ApplicationUser, int> store)
: base(store)
{
this.UserValidator = new UserValidator<ApplicationUser, int>(this)
{
AllowOnlyAlphanumericUserNames = false,
RequireUniqueEmail = true
//This does not exist
//RequireUniqueAlias = true
};
}
}
public class ApplicationUser : IdentityUser<int, CustomUserLogin, CustomUserRole,
CustomUserClaim>
{
[Required]
public string Alias { get; set; }
}
最佳答案
有点棘手但可行,需要自定义 UserValidator。查看 Microsoft.AspNet.Identity.Core 源代码对我很有帮助。
CustomUserValidator,由于正文字符限制删除了一些注释:
public class CustomUserValidator<TUser> : UserValidator<TUser, int>
where TUser : ApplicationUser
{
public bool RequireUniqueAlias { get; set; }
public CustomUserValidator(UserManager<TUser, int> manager) : base(manager)
{
this.Manager = manager;
}
private UserManager<TUser, int> Manager { get; set; }
public override async Task<IdentityResult> ValidateAsync(TUser item)
{
if (item == null)
{
throw new ArgumentNullException("item");
}
var errors = new List<string>();
await ValidateUserName(item, errors);
if (RequireUniqueEmail)
{
await ValidateEmail(item, errors);
}
if (RequireUniqueAlias)
{
await ValidateAlias(item, errors);
}
if (errors.Count > 0)
{
return IdentityResult.Failed(errors.ToArray());
}
return IdentityResult.Success;
}
private async Task ValidateUserName(TUser user, List<string> errors)
{
if (string.IsNullOrWhiteSpace(user.UserName))
{
errors.Add(String.Format(CultureInfo.CurrentCulture, CustomResources.PropertyTooShort, "Name"));
}
else if (AllowOnlyAlphanumericUserNames && !Regex.IsMatch(user.UserName, @"^[A-Za-z0-9@_\.]+$"))
{
// If any characters are not letters or digits, its an illegal user name
errors.Add(String.Format(CultureInfo.CurrentCulture, CustomResources.InvalidUserName, user.UserName));
}
else
{
var owner = await Manager.FindByNameAsync(user.UserName);
if (owner != null && !EqualityComparer<int>.Default.Equals(owner.Id, user.Id))
{
errors.Add(String.Format(CultureInfo.CurrentCulture, CustomResources.DuplicateName, user.UserName));
}
}
}
// make sure email is not empty, valid, and unique
private async Task ValidateEmail(TUser user, List<string> errors)
{
if (!user.Email.IsNullOrWhiteSpace())
{
if (string.IsNullOrWhiteSpace(user.Email))
{
errors.Add(String.Format(CultureInfo.CurrentCulture, CustomResources.PropertyTooShort, "Email"));
return;
}
try
{
var m = new MailAddress(user.Email);
}
catch (FormatException)
{
errors.Add(String.Format(CultureInfo.CurrentCulture, CustomResources.InvalidEmail, user.Email));
return;
}
}
var owner = await Manager.FindByEmailAsync(user.Email);
if (owner != null && !EqualityComparer<int>.Default.Equals(owner.Id, user.Id))
{
errors.Add(String.Format(CultureInfo.CurrentCulture, CustomResources.DuplicateEmail, user.Email));
}
}
private async Task ValidateAlias(TUser user, List<string> errors)
{
if (!user.Alias.IsNullOrWhiteSpace())
{
if (string.IsNullOrWhiteSpace(user.Alias))
{
errors.Add(String.Format(CultureInfo.CurrentCulture, CustomResources.PropertyTooShort, "Alias"));
return;
}
}
var owner = Manager.Users.FirstOrDefault(x => x.Alias == user.Alias);
if (owner != null && !EqualityComparer<int>.Default.Equals(owner.Id, user.Id))
{
errors.Add(String.Format(CultureInfo.CurrentCulture, CustomResources.DuplicateAlias, user.Alias));
}
}
}
除了小的修改之外,您还需要添加自定义资源文件,如果您希望自定义 Asp.net Identity 2.0 用户名已采用验证消息或其他消息,这也非常有用。添加资源文件,例如 CustomResources.resx。在文件资源管理器中打开文件夹并在记事本或类似工具中编辑 CustomResource.resx。替换为以下数据:
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="DefaultError" xml:space="preserve">
<value>An unknown failure has occured.</value>
<comment>Default identity result error message</comment>
</data>
<data name="DuplicateEmail" xml:space="preserve">
<value>Email '{0}' is already taken.</value>
<comment>error for duplicate emails</comment>
</data>
<data name="DuplicateName" xml:space="preserve">
<value>Name {0} is already taken.</value>
<comment>error for duplicate usernames</comment>
</data>
<data name="ExternalLoginExists" xml:space="preserve">
<value>A user with that external login already exists.</value>
<comment>Error when a login already linked</comment>
</data>
<data name="InvalidEmail" xml:space="preserve">
<value>Email '{0}' is invalid.</value>
<comment>invalid email</comment>
</data>
<data name="InvalidToken" xml:space="preserve">
<value>Invalid token.</value>
<comment>Error when a token is not recognized</comment>
</data>
<data name="InvalidUserName" xml:space="preserve">
<value>User name {0} is invalid, can only contain letters or digits.</value>
<comment>usernames can only contain letters or digits</comment>
</data>
<data name="LockoutNotEnabled" xml:space="preserve">
<value>Lockout is not enabled for this user.</value>
<comment>error when lockout is not enabled</comment>
</data>
<data name="NoTokenProvider" xml:space="preserve">
<value>No IUserTokenProvider is registered.</value>
<comment>Error when there is no IUserTokenProvider</comment>
</data>
<data name="NoTwoFactorProvider" xml:space="preserve">
<value>No IUserTwoFactorProvider for '{0}' is registered.</value>
<comment>Error when there is no provider found</comment>
</data>
<data name="PasswordMismatch" xml:space="preserve">
<value>Incorrect password.</value>
<comment>Error when a password doesn't match</comment>
</data>
<data name="PasswordRequireDigit" xml:space="preserve">
<value>Passwords must have at least one digit ('0'-'9').</value>
<comment>Error when passwords do not have a digit</comment>
</data>
<data name="PasswordRequireLower" xml:space="preserve">
<value>Passwords must have at least one lowercase ('a'-'z').</value>
<comment>Error when passwords do not have a lowercase letter</comment>
</data>
<data name="PasswordRequireNonLetterOrDigit" xml:space="preserve">
<value>Passwords must have at least one non letter or digit character.</value>
<comment>Error when password does not have enough letter or digit characters</comment>
</data>
<data name="PasswordRequireUpper" xml:space="preserve">
<value>Passwords must have at least one uppercase ('A'-'Z').</value>
<comment>Error when passwords do not have an uppercase letter</comment>
</data>
<data name="PasswordTooShort" xml:space="preserve">
<value>Passwords must be at least {0} characters.</value>
<comment>Error message for passwords that are too short</comment>
</data>
<data name="PropertyTooShort" xml:space="preserve">
<value>{0} cannot be null or empty.</value>
<comment>error for empty or null usernames</comment>
</data>
<data name="RoleNotFound" xml:space="preserve">
<value>Role {0} does not exist.</value>
<comment>error when a role does not exist</comment>
</data>
<data name="StoreNotIQueryableRoleStore" xml:space="preserve">
<value>Store does not implement IQueryableRoleStore<TRole>.</value>
<comment>error when the store does not implement this interface</comment>
</data>
<data name="StoreNotIQueryableUserStore" xml:space="preserve">
<value>Store does not implement IQueryableUserStore<TUser>.</value>
<comment>error when the store does not implement this interface</comment>
</data>
<data name="StoreNotIUserClaimStore" xml:space="preserve">
<value>Store does not implement IUserClaimStore<TUser>.</value>
<comment>error when the store does not implement this interface</comment>
</data>
<data name="StoreNotIUserConfirmationStore" xml:space="preserve">
<value>Store does not implement IUserConfirmationStore<TUser>.</value>
<comment>error when the store does not implement this interface</comment>
</data>
<data name="StoreNotIUserEmailStore" xml:space="preserve">
<value>Store does not implement IUserEmailStore<TUser>.</value>
<comment>error when the store does not implement this interface</comment>
</data>
<data name="StoreNotIUserLockoutStore" xml:space="preserve">
<value>Store does not implement IUserLockoutStore<TUser>.</value>
<comment>error when the store does not implement this interface</comment>
</data>
<data name="StoreNotIUserLoginStore" xml:space="preserve">
<value>Store does not implement IUserLoginStore<TUser>.</value>
<comment>error when the store does not implement this interface</comment>
</data>
<data name="StoreNotIUserPasswordStore" xml:space="preserve">
<value>Store does not implement IUserPasswordStore<TUser>.</value>
<comment>error when the store does not implement this interface</comment>
</data>
<data name="StoreNotIUserPhoneNumberStore" xml:space="preserve">
<value>Store does not implement IUserPhoneNumberStore<TUser>.</value>
<comment>error when the store does not implement this interface</comment>
</data>
<data name="StoreNotIUserRoleStore" xml:space="preserve">
<value>Store does not implement IUserRoleStore<TUser>.</value>
<comment>error when the store does not implement this interface</comment>
</data>
<data name="StoreNotIUserSecurityStampStore" xml:space="preserve">
<value>Store does not implement IUserSecurityStampStore<TUser>.</value>
<comment>error when the store does not implement this interface</comment>
</data>
<data name="StoreNotIUserTwoFactorStore" xml:space="preserve">
<value>Store does not implement IUserTwoFactorStore<TUser>.</value>
<comment>error when the store does not implement this interface</comment>
</data>
<data name="UserAlreadyHasPassword" xml:space="preserve">
<value>User already has a password set.</value>
<comment>error when AddPassword called when a user already has a password</comment>
</data>
<data name="UserAlreadyInRole" xml:space="preserve">
<value>User already in role.</value>
<comment>Error when a user is already in a role</comment>
</data>
<data name="UserIdNotFound" xml:space="preserve">
<value>UserId not found.</value>
<comment>No user with this id found</comment>
</data>
<data name="UserNameNotFound" xml:space="preserve">
<value>User {0} does not exist.</value>
<comment>error when a user does not exist</comment>
</data>
<data name="UserNotInRole" xml:space="preserve">
<value>User is not in role.</value>
<comment>Error when a user is not in the role</comment>
</data>
</root>
打开 CustomResources.resx 并添加您的属性,在我的例子中是“DuplicateAlias”作为名称。现在打开 CustomResource.Designer 并在 internal static global::System.Globalization.CultureInfo Culture
/// <summary>
/// Looks up a localized string similar to An unknown failure has occured..
/// </summary>
internal static string DefaultError {
get {
return ResourceManager.GetString("DefaultError", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Email '{0}' is already taken..
/// </summary>
internal static string DuplicateEmail {
get {
return ResourceManager.GetString("DuplicateEmail", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Name {0} is already taken..
/// </summary>
internal static string DuplicateName {
get {
return ResourceManager.GetString("DuplicateName", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Alias {0} is already taken..
/// </summary>
internal static string DuplicateAlias {
get {
return ResourceManager.GetString("DuplicateAlias", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to A user with that external login already exists..
/// </summary>
internal static string ExternalLoginExists {
get {
return ResourceManager.GetString("ExternalLoginExists", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Email '{0}' is invalid..
/// </summary>
internal static string InvalidEmail {
get {
return ResourceManager.GetString("InvalidEmail", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Invalid token..
/// </summary>
internal static string InvalidToken {
get {
return ResourceManager.GetString("InvalidToken", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to User name {0} is invalid, can only contain letters or digits..
/// </summary>
internal static string InvalidUserName {
get {
return ResourceManager.GetString("InvalidUserName", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Lockout is not enabled for this user..
/// </summary>
internal static string LockoutNotEnabled {
get {
return ResourceManager.GetString("LockoutNotEnabled", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to No IUserTokenProvider is registered..
/// </summary>
internal static string NoTokenProvider {
get {
return ResourceManager.GetString("NoTokenProvider", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to No IUserTwoFactorProvider for '{0}' is registered..
/// </summary>
internal static string NoTwoFactorProvider {
get {
return ResourceManager.GetString("NoTwoFactorProvider", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Incorrect password..
/// </summary>
internal static string PasswordMismatch {
get {
return ResourceManager.GetString("PasswordMismatch", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Passwords must have at least one digit ('0'-'9')..
/// </summary>
internal static string PasswordRequireDigit {
get {
return ResourceManager.GetString("PasswordRequireDigit", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Passwords must have at least one lowercase ('a'-'z')..
/// </summary>
internal static string PasswordRequireLower {
get {
return ResourceManager.GetString("PasswordRequireLower", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Passwords must have at least one non letter or digit character..
/// </summary>
internal static string PasswordRequireNonLetterOrDigit {
get {
return ResourceManager.GetString("PasswordRequireNonLetterOrDigit", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Passwords must have at least one uppercase ('A'-'Z')..
/// </summary>
internal static string PasswordRequireUpper {
get {
return ResourceManager.GetString("PasswordRequireUpper", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Passwords must be at least {0} characters..
/// </summary>
internal static string PasswordTooShort {
get {
return ResourceManager.GetString("PasswordTooShort", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to {0} cannot be null or empty..
/// </summary>
internal static string PropertyTooShort {
get {
return ResourceManager.GetString("PropertyTooShort", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Role {0} does not exist..
/// </summary>
internal static string RoleNotFound {
get {
return ResourceManager.GetString("RoleNotFound", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Store does not implement IQueryableRoleStore<TRole>..
/// </summary>
internal static string StoreNotIQueryableRoleStore {
get {
return ResourceManager.GetString("StoreNotIQueryableRoleStore", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Store does not implement IQueryableUserStore<TUser>..
/// </summary>
internal static string StoreNotIQueryableUserStore {
get {
return ResourceManager.GetString("StoreNotIQueryableUserStore", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Store does not implement IUserClaimStore<TUser>..
/// </summary>
internal static string StoreNotIUserClaimStore {
get {
return ResourceManager.GetString("StoreNotIUserClaimStore", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Store does not implement IUserConfirmationStore<TUser>..
/// </summary>
internal static string StoreNotIUserConfirmationStore {
get {
return ResourceManager.GetString("StoreNotIUserConfirmationStore", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Store does not implement IUserEmailStore<TUser>..
/// </summary>
internal static string StoreNotIUserEmailStore {
get {
return ResourceManager.GetString("StoreNotIUserEmailStore", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Store does not implement IUserLockoutStore<TUser>..
/// </summary>
internal static string StoreNotIUserLockoutStore {
get {
return ResourceManager.GetString("StoreNotIUserLockoutStore", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Store does not implement IUserLoginStore<TUser>..
/// </summary>
internal static string StoreNotIUserLoginStore {
get {
return ResourceManager.GetString("StoreNotIUserLoginStore", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Store does not implement IUserPasswordStore<TUser>..
/// </summary>
internal static string StoreNotIUserPasswordStore {
get {
return ResourceManager.GetString("StoreNotIUserPasswordStore", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Store does not implement IUserPhoneNumberStore<TUser>..
/// </summary>
internal static string StoreNotIUserPhoneNumberStore {
get {
return ResourceManager.GetString("StoreNotIUserPhoneNumberStore", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Store does not implement IUserRoleStore<TUser>..
/// </summary>
internal static string StoreNotIUserRoleStore {
get {
return ResourceManager.GetString("StoreNotIUserRoleStore", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Store does not implement IUserSecurityStampStore<TUser>..
/// </summary>
internal static string StoreNotIUserSecurityStampStore {
get {
return ResourceManager.GetString("StoreNotIUserSecurityStampStore", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Store does not implement IUserTwoFactorStore<TUser>..
/// </summary>
internal static string StoreNotIUserTwoFactorStore {
get {
return ResourceManager.GetString("StoreNotIUserTwoFactorStore", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to User already has a password set..
/// </summary>
internal static string UserAlreadyHasPassword {
get {
return ResourceManager.GetString("UserAlreadyHasPassword", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to User already in role..
/// </summary>
internal static string UserAlreadyInRole {
get {
return ResourceManager.GetString("UserAlreadyInRole", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to UserId not found..
/// </summary>
internal static string UserIdNotFound {
get {
return ResourceManager.GetString("UserIdNotFound", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to User {0} does not exist..
/// </summary>
internal static string UserNameNotFound {
get {
return ResourceManager.GetString("UserNameNotFound", resourceCulture);
}
}
关于c# - Asp.net Identity 2.0 使用自定义唯一属性扩展 UserValidator,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39123039/
#include using namespace std; class C{ private: int value; public: C(){ value = 0;
这个问题已经有答案了: What is the difference between char a[] = ?string?; and char *p = ?string?;? (8 个回答) 已关闭
关闭。此题需要details or clarity 。目前不接受答案。 想要改进这个问题吗?通过 editing this post 添加详细信息并澄清问题. 已关闭 7 年前。 此帖子已于 8 个月
除了调试之外,是否有任何针对 c、c++ 或 c# 的测试工具,其工作原理类似于将独立函数复制粘贴到某个文本框,然后在其他文本框中输入参数? 最佳答案 也许您会考虑单元测试。我推荐你谷歌测试和谷歌模拟
我想在第二台显示器中移动一个窗口 (HWND)。问题是我尝试了很多方法,例如将分辨率加倍或输入负值,但它永远无法将窗口放在我的第二台显示器上。 关于如何在 C/C++/c# 中执行此操作的任何线索 最
我正在寻找 C/C++/C## 中不同类型 DES 的现有实现。我的运行平台是Windows XP/Vista/7。 我正在尝试编写一个 C# 程序,它将使用 DES 算法进行加密和解密。我需要一些实
很难说出这里要问什么。这个问题模棱两可、含糊不清、不完整、过于宽泛或夸夸其谈,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开,visit the help center . 关闭 1
有没有办法强制将另一个 窗口置于顶部? 不是应用程序的窗口,而是另一个已经在系统上运行的窗口。 (Windows, C/C++/C#) 最佳答案 SetWindowPos(that_window_ha
假设您可以在 C/C++ 或 Csharp 之间做出选择,并且您打算在 Windows 和 Linux 服务器上运行同一服务器的多个实例,那么构建套接字服务器应用程序的最明智选择是什么? 最佳答案 如
你们能告诉我它们之间的区别吗? 顺便问一下,有什么叫C++库或C库的吗? 最佳答案 C++ 标准库 和 C 标准库 是 C++ 和 C 标准定义的库,提供给 C++ 和 C 程序使用。那是那些词的共同
下面的测试代码,我将输出信息放在注释中。我使用的是 gcc 4.8.5 和 Centos 7.2。 #include #include class C { public:
很难说出这里问的是什么。这个问题是含糊的、模糊的、不完整的、过于宽泛的或修辞性的,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开它,visit the help center 。 已关
我的客户将使用名为 annoucement 的结构/类与客户通信。我想我会用 C++ 编写服务器。会有很多不同的类继承annoucement。我的问题是通过网络将这些类发送给客户端 我想也许我应该使用
我在 C# 中有以下函数: public Matrix ConcatDescriptors(IList> descriptors) { int cols = descriptors[0].Co
我有一个项目要编写一个函数来对某些数据执行某些操作。我可以用 C/C++ 编写代码,但我不想与雇主共享该函数的代码。相反,我只想让他有权在他自己的代码中调用该函数。是否可以?我想到了这两种方法 - 在
我使用的是编写糟糕的第 3 方 (C/C++) Api。我从托管代码(C++/CLI)中使用它。有时会出现“访问冲突错误”。这使整个应用程序崩溃。我知道我无法处理这些错误[如果指针访问非法内存位置等,
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 我们不允许提问寻求书籍、工具、软件库等的推荐。您可以编辑问题,以便用事实和引用来回答。 关闭 7 年前。
已关闭。此问题不符合Stack Overflow guidelines 。目前不接受答案。 要求我们推荐或查找工具、库或最喜欢的场外资源的问题对于 Stack Overflow 来说是偏离主题的,因为
我有一些 C 代码,将使用 P/Invoke 从 C# 调用。我正在尝试为这个 C 函数定义一个 C# 等效项。 SomeData* DoSomething(); struct SomeData {
这个问题已经有答案了: Why are these constructs using pre and post-increment undefined behavior? (14 个回答) 已关闭 6
我是一名优秀的程序员,十分优秀!