便携式相当于MethodBase.GetCurrentMethod类库 [英] Portable Class Library equivalent to MethodBase.GetCurrentMethod

查看:1508
本文介绍了便携式相当于MethodBase.GetCurrentMethod类库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有便携式相当于MethodBase.GetCurrentMethod

阶级库?

我是新来PCLS。我justing寻找到我是否可以使用PCL举办一些客户端code,它一定会在Silverlight中使用,并且可以用在别的地方。经扫描的来源,我可以看到很多呼叫MethodBase.GetCurrentMethod的,这似乎并没有在PCL存在。

的**编辑**

我撕开这个样本出来有问题的库。 IsNullOrEmpty()使用String.IsNullOrWhiteSpace(字符串),它似乎没有用,所以该位是一种忽悠。

 使用系统;
使用System.Linq的;
使用的System.Reflection;
使用System.Linq.Ex pressions;

命名空间LinqToLdap.PCL
{
    公共静态类QueryableExtensions
    {
        内部静态布尔IsNullOrEmpty(此字符串str)
        {
            返回string.IsNullOrEmpty(STR);
        }

        公共静态的IQueryable< TSource> FilterWith< TSource>(这IQueryable的< TSource>源字符串过滤器)
        {
            如果(来源== NULL)抛出新ArgumentNullException(源);

            如果(filter.IsNullOrEmpty())抛出新的异常(过滤器不能为空,空,或空白。);

            如果(!filter.StartsWith(())
            {
                过滤器=(+过滤+);
            }

            返回source.Provider.CreateQuery< TSource>(
                防爆pression.Call(
                    空值,
                    ((MethodInfo的)MethodBase.GetCurrentMethod())
                        .MakeGenericMethod(新[] {typeof运算(TSource)}),
                    新的[] {source.Ex pression,防爆pression.Constant(过滤器)}
                    )
                );
        }
    }
}
 

解决方案

(我自己的'微软的便携式库项目)

我们,因为它不支持在Windows 8的.NET的地铁应用程序不要将其暴露在PCL。什么是你的这种方法的使用?

s there Portable Class Library equivalent to MethodBase.GetCurrentMethod?

I'm new to PCLs. I'm justing looking into whether I can use a PCL to hold some client code that will definitely be used on Silverlight and may be used elsewhere. Having scanned the source, I can see plenty of calls to MethodBase.GetCurrentMethod which doesn't seem to exist in the PCL.

** EDIT **

I've ripped this sample out of the library in question. IsNullOrEmpty() was using String.IsNullOrWhiteSpace(String) which doesn't seem to be available, so that bit's a fudge.

using System;
using System.Linq;
using System.Reflection;
using System.Linq.Expressions;

namespace LinqToLdap.PCL
{
    public static class QueryableExtensions
    {
        internal static bool IsNullOrEmpty(this String str)
        {
            return string.IsNullOrEmpty(str);
        }

        public static IQueryable<TSource> FilterWith<TSource>(this IQueryable<TSource> source, string filter)
        {
            if (source == null) throw new ArgumentNullException("source");

            if (filter.IsNullOrEmpty()) throw new Exception("Filters cannot be null, empty, or white-space.");

            if (!filter.StartsWith("("))
            {
                filter = "(" + filter + ")";
            }

            return source.Provider.CreateQuery<TSource>(
                Expression.Call(
                    null,
                    ((MethodInfo)MethodBase.GetCurrentMethod())
                        .MakeGenericMethod(new[] { typeof(TSource) }),
                    new[] { source.Expression, Expression.Constant(filter) }
                    )
                );
        }
    }
}

解决方案

(I 'own' the Portable Library project at Microsoft)

We don't expose it in PCL because it's not supported in Windows 8 .NET for Metro apps. What's your usage of this method?

这篇关于便携式相当于MethodBase.GetCurrentMethod类库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆