我有3个任务:
private async Task<Cat> FeedCat() {}
private async Task<House> SellHouse() {}
private async Task<Tesla> BuyCar() {}
Run Code Online (Sandbox Code Playgroud)
他们都需要在我的代码可以继续之前运行,我也需要每个代码的结果.结果没有任何共同之处
如何调用并等待3个任务完成然后获得结果?
我有几个月在SQL Server中存储为1,2,3,4,... 12.我想将它们显示为1月,2月等.在SQL Server中是否有像MonthName(1)= January这样的函数?如果可能的话,我试图避免CASE声明.
我有一个类型,t我想获得具有该属性的公共属性列表MyAttribute.该属性标有AllowMultiple = false,如下所示:
[AttributeUsage(AttributeTargets.Property, AllowMultiple = false)]
Run Code Online (Sandbox Code Playgroud)
目前我拥有的是这个,但我认为有更好的方法:
foreach (PropertyInfo prop in t.GetProperties())
{
object[] attributes = prop.GetCustomAttributes(typeof(MyAttribute), true);
if (attributes.Length == 1)
{
//Property with my custom attribute
}
}
Run Code Online (Sandbox Code Playgroud)
我怎样才能改善这个?我很抱歉,如果这是重复的,那里有大量的反思线程......似乎这是一个非常热门的话题.
有没有办法根据我在运行时知道类的名称来创建类的实例.基本上我会在字符串中有类的名称.
这段代码:
Type.GetType("namespace.a.b.ClassName")
Run Code Online (Sandbox Code Playgroud)
回报null.
我在使用中:
using namespace.a.b;
Run Code Online (Sandbox Code Playgroud)
更新:
类型存在,它在不同的类库中,我需要通过字符串名称来获取它.
我收到错误:
必须在非泛型静态类中定义扩展方法
在线上:
public class LinqHelper
Run Code Online (Sandbox Code Playgroud)
这是基于Mark Gavells代码的助手类.我真的很困惑这个错误意味着什么,因为我确信它在周五离开时工作正常!
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Linq.Expressions;
using System.Reflection;
/// <summary>
/// Helper methods for link
/// </summary>
public class LinqHelper
{
public static IOrderedQueryable<T> OrderBy<T>(this IQueryable<T> source, string property)
{
return ApplyOrder<T>(source, property, "OrderBy");
}
public static IOrderedQueryable<T> OrderByDescending<T>(this IQueryable<T> source, string property)
{
return ApplyOrder<T>(source, property, "OrderByDescending");
}
public static IOrderedQueryable<T> ThenBy<T>(this IOrderedQueryable<T> source, string property)
{
return ApplyOrder<T>(source, property, "ThenBy");
}
public static IOrderedQueryable<T> ThenByDescending<T>(this IOrderedQueryable<T> …Run Code Online (Sandbox Code Playgroud) 自从升级到RC for WebAPI后,我在WebAPI上调用POST时遇到了一些奇怪的问题.我甚至回到了新项目生成的基本版本.所以:
public void Post(string value)
{
}
Run Code Online (Sandbox Code Playgroud)
并从Fiddler打来电话:
Header:
User-Agent: Fiddler
Host: localhost:60725
Content-Type: application/json
Content-Length: 29
Body:
{
"value": "test"
}
Run Code Online (Sandbox Code Playgroud)
当我调试时,字符串"value"永远不会被分配给.它总是为NULL.谁有这个问题?
(我第一次看到更复杂类型的问题)
问题不仅仅是绑定到ASP.NET MVC 4,在安装RC后,新的ASP.NET MVC 3项目也会出现同样的问题
在研究一些Web服务时,我遇到了微软称之为OData的这种"新"技术.通过阅读他们在OData中的描述,我很难区分OData和REST-ful Web服务.有人可以帮我理解差异吗?
我正在尝试将一些JavaScript代码从MicrosoftAjax移动到JQuery.我使用流行的.net方法的MicrosoftAjax中的JavaScript等价物,例如String.format(),String.startsWith()等.在jQuery中它们是否等同于它们?
在我的主页上,我正在使用此方法隐藏垃圾邮件机器人的电子邮件:
<a href="admin [at] example.com"
rel="nofollow"
onclick="this.href='mailto:' + 'admin' + '@' + 'example.com'">Contact me</a>
Run Code Online (Sandbox Code Playgroud)
你怎么看待这件事?有效吗?您还知道或使用其他哪些方法?
c# ×6
.net ×5
reflection ×2
.net-4.5 ×1
algorithm ×1
async-await ×1
email ×1
html ×1
javascript ×1
jquery ×1
linq ×1
odata ×1
rest ×1
spam ×1
sql ×1
sql-server ×1
system.type ×1
t-sql ×1
web-services ×1