【c# – Linq数据映射:列属性上Storage属性的使用】教程文章相关的互联网学习教程文章

C#-Exchange Web服务:UseDefaultCredentials属性【代码】

This Microsoft page表示通过将UseDefaultCredentials属性设置为true,不需要登录名和密码即可与Exchange服务器进行通信.但是,这不是我的经验. 我的代码创建了一个称为service的ExchangeService实例:ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010);如果我按如下所示手动设置凭据,则一切正常:service.Credentials = new WebCredentials("my@email.address", "my password");但是,如果我删除该行并将...

首页> C#>您打算如何声明一个依赖属性?【代码】

我正在阅读有关如何制作参数化样式的教程(here).在其中,它使用了一些依赖属性.它这样声明它们:public static Brush GetTickBrush(DependencyObject obj) {return (Brush)obj.GetValue(TickBrushProperty); } public static void SetTickBrush(DependencyObject obj, Brush value) {obj.SetValue(TickBrushProperty, value); } public static readonly DependencyProperty TickBrushProperty =DependencyProperty.RegisterAttached...

C#-反射-按名称访问自定义属性【代码】

我正在尝试查看给定的方法是否用属性装饰(有问题的属性是NUnit.Framework.TestAttribute),但是无论该属性是什么版本,我都需要能够检查该属性.当前,我在使用反射的项目中具有nunit.framework.dll版本2.6.2,在测试中具有dll版本2.6.0.反射找不到属性. 有什么办法可以做吗bool isTest = method.GetCustomAttributes(typeof(TestAttribute), true).Length > 0;不能访问TestAttribute dll的正确版本? 其中method是MethodInfo类型.解决方...

C#使用具有Delegate.CreateDelegate值类型的属性【代码】

以Jon Skeet的文章Making reflection fly and exploring delegates为例,我试图使用Delegate.CreateDelegate方法将属性复制为委托.这是一个示例类:public class PropertyGetter {public int Prop1 {get;set;}public string Prop2 {get;set;}public object GetPropValue(string propertyName){var property = GetType().GetProperty(propertyName).GetGetMethod();propertyDelegate = (Func<object>)Delegate.CreateDelegate(typeof...

c#-按aspx中的属性查找元素【代码】

<div id="foo" runat="server" data-id="bar"></div>在后面的代码中,可以直接在id上或使用FindControl()访问此div. 但是,有什么方法可以基于id以外的其他属性在aspx上搜索元素?例如上面的data-id =“ bar”.解决方法:此扩展方法(使用递归)可能会有所帮助:public static IEnumerable<Control>FindControlByAttribute(this Control control, string key) {var current = control as System.Web.UI.HtmlControls.HtmlControl;if (cu...

c#-使用MVC 5 RouteArea属性时找不到默认区域视图【代码】

我有一个涉及多个领域的MVC5项目.我有一个默认区域(名为Default),其中有一个默认控制器(名为DefaultController).这可以在站点路线上访问.[RouteArea] public class DefaultController : Controller {[Route]public ActionResult Index(){return View("Index");} }public static void RegisterRoutes(RouteCollection routes) {routes.LowercaseUrls = true;routes.IgnoreRoute("{resource}.axd/{*pathInfo}");routes.MapMvcAttribu...

C#-通过基于样式的属性覆盖样式【代码】

我有一个按钮的基本样式:<Style x:Key="ButtonStyle_base" TargetType="{x:Type Button}"><Setter Property="Template"><Setter.Value><ControlTemplate TargetType="{x:Type Button}"><Grid Name="grid" Margin="0,0,0,0"><Rectangle Name="rectangle" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" ><Rectangle.Effect><DropShadowEffect BlurRadius="3" Opacity="0.4" ShadowDepth="6"/></Rectangle.Effect></R...

c#-对象属性不正确时,Wcf(400)错误的请求【代码】

我有一个Wcf(启用了ajax)服务,该服务接受方法调用的对象.我的Wcf方法如下:[OperationContract] [XmlSerializerFormat] [WebInvoke(Method = "POST", UriTemplate = "/XML/GetTypes", BodyStyle = WebMessageBodyStyle.Bare, ResponseFormat = WebMessageFormat.Xml)] XElement XMLGetTypes(TypeRequest TypeRequest) {return Utilities.Convert.ObjectToXElement(TypeRequest.Execute(TypeRequest)); }“ TypeRequest”对象如下:...

c#-ASP.Net中基于会话的静态属性将在所有用户之间共享吗?【代码】

对于以下两个静态属性,这两个属性将在ASP.net网站中的所有用户之间共享吗?似乎Property2将在ASP.Net网站的所有用户之间共享,但不确定Property1.public static object Property1 { get { return HttpContext.Current.Session["some_key"]; } set { HttpContext.Current.Session["some_key"] = value;} }public static object Property2 { get;set;}解决方法:Property1仅在用户当前会话的范围内.静态部分没有改变,因为它只是指向用...

c#-通过反射通过自定义属性对实体进行Linq排序【代码】

获得了具有Country属性和String属性Name的Customer类.客户还实现IComparable< Country>.像这样:public int CompareTo(Country other) {return string.Compare(this.Name, other.Name); }现在:var custList = new List<Customer>{...};custList.OrderBy(cust => cust.Country).ToList(); //Sorts as charm.如果尝试通过反射排序:var itemProp = typeof(Customer).GetProperty("Country");custList = c.Customers.ToList().OrderB...

c#-授权角色不起作用的属性?【代码】

我正在尝试使此工作正常进行,但到目前为止还没有运气.我的Authorize属性可以单独使用,但是一旦我声明了用户必须与之分开的角色,我就会从Webapi中返回以下消息{"message":"Authorization has been denied for this request."}启动文件public void Configuration(IAppBuilder app) {//HttpConfiguration config = new HttpConfiguration();ConfigureOAuth(app);// simple injectorSimpleInjectorConfig.Register();AutoMapperConfig....

c#-获取实现类型的具体属性【代码】

鉴于以下课程public Foo {public Foo() {this.Bar = new Bar();}public IBar Bar{ get; set;} }public Bar : IBar {// implemented properties}如何使用反射获得Foo属性Bar的具体实现?instance.GetType().GetProperty("Bar").PropertyType仅产生接口.解决方法:如果您尝试获取实现IBar的类型,则应获取其值并采用该类型:var type = instance.GetType().GetProperty("Bar").GetValue(instance,null).GetType()

C#-App Config中不允许使用tracemode属性【代码】

我正在尝试使用4.0 .Net Framework跟踪用C#编写的SOAP Web服务. 在遵循了本教程之后:http://msdn.microsoft.com/en-us/library/ty48b824%28v=vs.110%29.aspx我通过以下方式配置了Web服务客户端的应用程序配置:<system.diagnostics> <trace autoflush="true"/> <sources><source name="System.Net"><listeners><add name="TraceFile"/></listeners></source><source name="System.Net.Sockets"><listeners><add name="TraceFile"/...

c#-获取QuickFix / n的会话属性(用户名和密码)【代码】

我已经将我的用户名和密码放在FIX配置文件中.因此,我必须认为我应该能够从某些内部变量(例如会话变量或SessionSetting变量或session.SessionDataDictionary或其他变量)获取用户名和密码.但是,我没有找到直接从内部变量获取用户名和密码的解决方案.[SESSION] BeginString=FIX.4.4 SenderCompID= xxxxx Username= xxxx Password= xxxx从逻辑上讲,这可能是非常可行的.但是,没有人建议这样做,或者我还没有在Google上看到任何人这样做.我...

c#-属性路由的区别?【代码】

以下内容有什么区别?[Route("movies/genre/{genre}")] public ActionResult ViewByGenre(string genre="action")代替[Route("movies/genre/{genre=action}")] public ActionResult ViewByGenre(string genre)解决方法:在本陈述中[Route("movies/genre/{genre}")] public ActionResult ViewByGenre(string genre="action")路径中的genre参数不是可选的,只有ViewByGenre函数会对其赋值. 这里[Route("movies/genre/{genre=action}")]...