小编jai*_*mie的帖子

带有异步等待和GetType()的可移植类库.IsValueType

我需要在同一个可移植类库中进行以下调用:

public class Foobar
{
    void Foo()
    {
        var b = GetType().IsValueType; //<-- 2
    }

    async Task<IEnumerable<T>> Bar<T>() 
        where T : class, IBaz, new()
    {
        return await Task.Factory.StartNew(() => new List<T>(new[]   //<-- 1
            {
                new T {Qux = Guid.NewGuid().ToString()}
            }));
    }

    interface IBaz 
    {
        string Qux { get; set; }
    }
}
Run Code Online (Sandbox Code Playgroud)

设置以下目标框架:

  • .net Framework 4.5
  • 银光5
  • Windows Phone 8
  • .Net for Windows Store应用程序

我得到此构建错误:
找不到'async'修饰符所需的所有类型.您是否针对错误的框架版本,或缺少对程序集的引用?

我试图安装bcl但仍然得到相同的错误.如果我删除Sliverlight目标异步工作,但我失去了Type类的IsValueType道具...

.net c# async-await portable-class-library

10
推荐指数
1
解决办法
4112
查看次数

RESTful WCF服务图像上传问题

1 namespace Uploader  
2 {  
3     using System;  
4     using System.IO;  
5     using System.ServiceModel;  
6     using System.ServiceModel.Description;  
7     using System.ServiceModel.Web;  
8     using System.Drawing;  
9     using System.Drawing.Imaging;  
10     using System.Net;  
11     using System.Xml;  
12   
13     [ServiceContract(Namespace = "http://Uploader")]  
14     public interface IUploaderService  
15     {  
16         [OperationContract, WebInvoke(Method = "POST",UriTemplate = "File/{fileName}")]  
17         bool UploadFile(string fileName, Stream fileContents);  
18     }  
19   
20     [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]  
21     public class UploaderService : IUploaderService  
22     {  
23         public bool UploadFile(string fileName, Stream fileContents)  
24         { …
Run Code Online (Sandbox Code Playgroud)

c# rest wcf

7
推荐指数
1
解决办法
2万
查看次数

SQL 2008 - INFORMATION_SCHEMA视图中的外键约束

我正在编写ac#unit test,它针对目标数据库验证ORM类的字符串属性,始终是SQL 2008,以及数据映射到的类.

检查指定的外键在DB中是否有效很容易:

    static private bool ConstraintExsits(string table, string column, ConstraintType constraintType)
    {
        string constraintTypeWhereClause;
        switch (constraintType)
        {
            case ConstraintType.PrimaryKey:
                constraintTypeWhereClause = "PRIMARY KEY";
                break;
            case ConstraintType.ForeignKey:
                constraintTypeWhereClause = "FOREIGN KEY";
                break;
            default:
                throw new ArgumentOutOfRangeException("constraintType");
        }

        var cmd = new SqlCommand(
                           @"SELECT a.CONSTRAINT_NAME
                            FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS a 
                            JOIN INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE b on a.CONSTRAINT_NAME = b.CONSTRAINT_NAME
                            WHERE a.TABLE_NAME = @table AND b.COLUMN_NAME = @column AND a.CONSTRAINT_TYPE = '" + constraintTypeWhereClause + "'",
                           Connection);
        cmd.Parameters.AddWithValue("@table", table.Trim('[').Trim(']'));
        cmd.Parameters.AddWithValue("@column", column.Trim('[').Trim(']'));
        return !string.IsNullOrEmpty((string)cmd.ExecuteScalar());
    }
Run Code Online (Sandbox Code Playgroud)

现在采取以下外键关系: …

c# sql orm

5
推荐指数
1
解决办法
3340
查看次数

标签 统计

c# ×3

.net ×1

async-await ×1

orm ×1

portable-class-library ×1

rest ×1

sql ×1

wcf ×1