小编Ale*_*ndr的帖子

TextBlock中的无穷大符号

我需要无限符号 TextBlock

如果我写"∞"TextBlock.Text都是好的,用TextBlock"∞"符号.

<TextBlock Text="&#8734;"/> 
Run Code Online (Sandbox Code Playgroud)

但是,如果我使用Converter.

<TextBlock Text="{Binding MyValue, Converter={StaticResource MyConverter}}"/> 
Run Code Online (Sandbox Code Playgroud)

我有"&#8734;"文字TextBlock.

 public class MyConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {           
           return "&#8734;";           
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
           throw new NotImplementedException();
        }
    }
Run Code Online (Sandbox Code Playgroud)

有什么解决方案吗?

c# unicode ivalueconverter windows-phone-8

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

通用集合中的协方差C#

我有一些类和接口

public interface IGeoObject
    {
        GeoCoordinate GetGeocoordinate();
    }

public class User : IGeoObject
    {
        public GeoCoordinate GetGeocoordinate()
        {
            //...
            return GeoCoordinate;           
        }
    }  

public class Venue : IGeoObject
    {    
        public GeoCoordinate GetGeocoordinate()
        {
            //...
            return GeoCoordinate;
        }
    }

public class Place : IGeoObject
    {    
        public GeoCoordinate GetGeocoordinate()
        {
            //...
            return GeoCoordinate;
        }
    }
Run Code Online (Sandbox Code Playgroud)

我有,类型的示例变量用户 List<User>

我有签名的方法

double GetMinDistance(List<IGeoObject> objects, GeoCoordinate position)
Run Code Online (Sandbox Code Playgroud)

我无法传递用户GetMinDistance,因为泛型类型的协方差不起作用.

我可以创建额外的列表和使用方法.ConvertAll(或.CasT<T>):

List<IGeoObject> list = new List<User>(listUser).ConvertAll(x => (IGeoObject)x);
var dist = GeoTest.GetMinDistance(list, …
Run Code Online (Sandbox Code Playgroud)

.net c# generics

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

在数据库查询中使用关键字async/await

我在Windows Phone 8应用程序中有一个本地数据库.该应用程序包含对数据库的大量查询,我不希望对UI的响应性产生不良影响.

例如,我有一个用户表和方法,用于通过id从数据库中获取用户.

目前的变种

public class CacheDataContext : DataContext
{
    public static string DBConnectionString = "Data Source=isostore:/Cache.sdf";

    public CacheDataContext(string connectionString)
            : base(connectionString) { }

    public static AutoResetEvent OperationOnDatabaseUser = new AutoResetEvent(true);

    public Table<User> UserItems;
}

public class CacheDataContextUser : CacheDataContext
{
    public CacheDataContextUser(string connectionString)
        : base(connectionString) { }

    public User GetUser(string id)
    {
        try
        {
            OperationOnDatabaseUser.WaitOne();
            using (CacheDataContext context = new CacheDataContext(DBConnectionString))
            {
                //find user in the data base and return 
            }
        }
        finally
        {
            OperationOnDatabaseUser.Set();
        } …
Run Code Online (Sandbox Code Playgroud)

c# thread-safety windows-phone-7 async-await windows-phone-8

0
推荐指数
1
解决办法
2524
查看次数

解析具有不同类型值的json(Newtonsoft.Json)

帮我解析jsonNewtonsoft.Json

  {
    "_id": 160,
    "location": {
        "type": "Point",
        "coordinates": [43.59043144045182, 39.72119003534317]
    },  
},
{
    "_id": 161, 
    "location": {
        "type": "LineString",
        "coordinates": [
            [43.58780105200211, 39.719191789627075],
            [43.58817794899264, 39.719465374946594]
        ]
    },  
},
{
    "_id": 152, 
        "location": {
            "type": "Polygon",
            "coordinates": [
                [43.590524759627954, 39.71930980682373],
                [43.590474249766544, 39.71926689147949],
                [43.59043151061995, 39.71934735774994],
                [43.59073456936772, 39.71958339214325],
                [43.59076565222992, 39.71949219703674]
            ]
        },
}
Run Code Online (Sandbox Code Playgroud)

coordinates具有类型List<double>List<List<double>>取决于键type(多边形,线串,点)。

c# json json.net windows-phone-7 windows-phone-8

0
推荐指数
1
解决办法
1507
查看次数

如何在泛型方法中检查泛型类型

我在 Java 中需要这样的东西(C# 示例)

 class Program
    {
        static void Main(string[] args)
        {
            Method<String>();
        }

        static void Method<T>()
        {
            Type typeT = typeof(T);
            Type typeString = typeof(String);
            if (typeT == typeString)
            {
                Console.WriteLine("Is String");
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

我有通用方法,需要在方法中检查类型 T。

protected <T> MyClass<T> myMethod(MyClass<T> myObj){
   // if  T is string do ..., else do ... 
}
Run Code Online (Sandbox Code Playgroud)

java generics

0
推荐指数
1
解决办法
3038
查看次数