我有这个 POCO 类,其属性使用自定义属性:
应用程序状态标志 POCO 类
public class ApplicationStatusFlags
{
public int ApplicationId { get; set; }
[SectionFlag("APPLICANTPERSONALDETAILS")]
public bool PersonalDetailsStatus { get; set; }
[SectionFlag("APPLICANTECREGISTRATION")]
public bool EcRegistrationStatus { get; set; }
[SectionFlag("APPLICANTCV")]
public bool CvUpload { get; set; }
[SectionFlag("APPLICANTSTATEMENT")]
public bool IceAttributeStatement { get; set; }
[SectionFlag("APPLICANTCPD")]
public bool CpdUpload { get; set; }
[SectionFlag("APPLICANTORGCHART")]
public bool OrgChartUpload { get; set; }
[SectionFlag("APPLICANTSPONSORDETAILS")]
public bool SponsorDetails { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
节标志属性类
[AttributeUsage(AttributeTargets.All)]
public class SectionFlagAttribute : …Run Code Online (Sandbox Code Playgroud) 我想在自定义属性中实现本地化,以检查该属性是否是有效的 IP 地址或主机名。到目前为止,验证工作正常,但我的问题是,尽管我的本地切换为德语,但我只收到默认的英语错误消息。我正在处理资源文件。我不想为此实现客户端验证。我知道有实现适配器的方法,但如果我错了,请纠正我,这仅用于客户端验证。
我的自定义验证类:
public class IPAddressOrHostnameAttribute : ValidationAttribute
{
public IPAddressOrHostnameAttribute(string propertyName, object desiredvalue, string errorMessage)
{
PropertyName = propertyName;
DesiredValue = desiredvalue;
ErrorMessage = errorMessage;
}
private string PropertyName { get; }
private object DesiredValue { get; }
protected override ValidationResult IsValid(object value, ValidationContext context)
{
var instance = context.ObjectInstance;
var type = instance.GetType();
var propertyValue = type.GetProperty(PropertyName).GetValue(instance, null);
if (propertyValue.ToString() == DesiredValue.ToString() && value != null)
{
if (Regex.IsMatch(value.ToString(), AckConstants.VALIDIPADDRESSREGEX)
|| Regex.IsMatch(value.ToString(), AckConstants.VALIDHOSTNAMEREGEX))
{
return ValidationResult.Success;
} …Run Code Online (Sandbox Code Playgroud) 我正在开发一个Windows Phone应用程序.
我有一个自定义按钮,里面有一个图像.这是它的XAML代码:
<ControlTemplate x:Key="ImageButton" TargetType="Button">
<Grid>
<Image Margin="45,8,35,8" Source="Images/Delete.png"/>
</Grid>
</ControlTemplate>
Run Code Online (Sandbox Code Playgroud)
如何以编程方式更改图像源属性?
在DB我有Role和User一对多关系的实体.
我想要做的是建立自定义授权过滤器.我见过的所有教程都使用默认ASP.NET会员资格.我所知道的是,我需要继承,AuthorizationAttribute但不知道我需要覆盖哪些方法以及如何实现它们.
public class UserAuth : AuthorizeAttribute
{
}
Run Code Online (Sandbox Code Playgroud)
在DB:
角色
public class Role
{
[Key]
public int RoleID { get; set; }
[Required]
public int RolenameValue { get; set; }
[MaxLength(100)]
public string Description { get; set; }
// // // // //
public Rolename Rolename
{
get { return (ProjectName.Domain.Enums.Rolename)RolenameValue; }
set { RolenameValue = (int)value; }
}
public virtual ICollection<User> Users { get; set; } …Run Code Online (Sandbox Code Playgroud) 我有以下代码似乎没有正确行事.有一个属性有一个属性不是类型FieldMapAttribute,但它仍然进入if条件,我检查匹配该类型属性的计数.
foreach (PropertyInfo _property in _properties)
{
var attributes = _property.GetCustomAttributes(false);
if (attributes.Select(a => a.GetType() == typeof(FieldMapAttribute)).Count() > 0)
{
colname = (attributes.Select(a => a.GetType() == typeof(FieldMapAttribute)).Cast<FieldMapAttribute>().First()).DbColumnName;
}
}
Run Code Online (Sandbox Code Playgroud)
有人可以帮我理解这里发生了什么吗?
我有一个带有两个自定义属性的锚点。带星号的那个是后来添加的。
HTML代码如下:
<ul class="dropdown">
<li class="orange"><a href="#" data-jumpslide="2" **goto-page="newpage"**><div class="list-item one-liner"><div class="left"><span id="functionality-icon"></span></div> <div class="right">When to do it</div><div class="clear"></div></div></a></li>
<li class="orange"><a href="#" data-jumpslide="3" **goto-page="newpage"**><div class="list-item one-liner"><div class="left"><span id="functionality-icon"></span></div> <div class="right">Key faces</div><div class="clear"></div></div></a></li>
<li class="orange"><a href="#" data-jumpslide="5" **goto-page="newpage"**><div class="list-item one-liner"><div class="left"><span id="functionality-icon"></span></div> <div class="right">Functionalities</div><div class="clear"></div></div></a></li>
</ul>
Run Code Online (Sandbox Code Playgroud)
我想在下面的 Jquery 代码中获取这个新添加的自定义属性的值。由于某种原因,attr不起作用。
你知道它是如何工作的吗:
$('a[data-jumpslide]').each(function(idx, ele){
$(ele).on('click', function(){
alert($(this).data("goto-page"));
var slideToJump = $(this).data('jumpslide');
window.slider.go(false, slideToJump+1);
});
});
Run Code Online (Sandbox Code Playgroud)
谢谢。
我得到了一段HTML:
<input type="radio" name="radioBtn" onChange="rdbtn()" value="100" isprm="true">
<input type="radio" name="radioBtn" onChange="rdbtn()" value="110" isprm="true">
Run Code Online (Sandbox Code Playgroud)
我想将自定义属性值传递给变量.这是我尝试过但不起作用的:
function rdbtn(){
var radioVal = $(this).val();
var radioPRM = $("input[id=radioVal]:checked").attr('isprm');
...
}
Run Code Online (Sandbox Code Playgroud)
和
$('input[id=radioVal]').data("isprm");
Run Code Online (Sandbox Code Playgroud)
没运气.你有任何想法如何让它工作?谢谢.
我想知道条件方法是否可以在类属性上具有条件.
例如 :
class Class1
{
public bool _doStuff;
[Conditional(_doStuff)]
public static void Stuff() {
// Do the stuff
}
}
Run Code Online (Sandbox Code Playgroud)
喜欢的[Conditonal("DEBUG")].
有谁知道这个?
我不知道用什么语法谷歌这个.
考虑这个属性:
[MyAttribute(MyOption=true,OtherOption=false)]
Run Code Online (Sandbox Code Playgroud)
那是什么Name=value部分?我如何在自己的自定义属性中实现它?
一个能DescriptionAttribute在枚举包含TextBox"ES文本?我问,因为我有一个包含大量TextBoxes 的文件,我希望将它们的内容与我拥有的值相匹配.我怀疑我能做到这一点,但我完全不确定.
即
[DescriptionAttribute(textBox1.Text)]
a,
Run Code Online (Sandbox Code Playgroud) 尝试使用一些自定义属性创建元素
function x(){
var f=document.createElement("div");
this.name="monkey";
return f;
}
x.prototype.myFunction=function(){
alert(arguments[0]+this.name);
};
var c=new x();
c.myFunction("hello");
Run Code Online (Sandbox Code Playgroud)
浏览器说c.myFunction不是一个函数
c# ×5
html ×2
javascript ×2
jquery ×2
.net ×1
asp.net ×1
asp.net-core ×1
asp.net-mvc ×1
attributes ×1
c#-4.0 ×1
enums ×1
linq ×1
reflection ×1