コード例 #1
0
 public static void IsDelegate <T>(string argName)
 {
     if (!TypsFw.IsDelegate(typeof(T)))
     {
         throw new ArgumentException("EMCommon.TypeArgument_NotDelegate", argName);
     }
 }
コード例 #2
0
ファイル: EventWeakListener.cs プロジェクト: cwdotson/FwNs
        private static Func <EventHandler <TEventArgs>, THandler> PrepareHandlerConverter <TEventArgs, THandler>() where TEventArgs : EventArgs
        {
            ParameterExpression expression  = Expression.Parameter(typeof(EventHandler <TEventArgs>));
            ParameterExpression expression2 = Expression.Parameter(typeof(object));
            ParameterExpression expression3 = Expression.Parameter(typeof(TEventArgs));

            Expression[]          arguments        = new Expression[] { expression2, expression3 };
            ParameterExpression[] parameters       = new ParameterExpression[] { expression2, expression3 };
            ParameterExpression[] expressionArray3 = new ParameterExpression[] { expression };
            Expression <Func <EventHandler <TEventArgs>, THandler> > expression4 = Expression.Lambda <Func <EventHandler <TEventArgs>, THandler> >(Expression.Lambda <THandler>(Expression.Invoke(expression, arguments), parameters), expressionArray3);
            TypeBuilder   builder1 = TypeGeneration.Module.DefineType("HandlerConverters.Converter" + _handlerConverterCounter++, TypeAttributes.Public);
            MethodBuilder method   = builder1.DefineMethod("Convert", MethodAttributes.Static | MethodAttributes.Public);

            expression4.CompileToMethod(method);
            return(TypsFw.CreateDelegate <Func <EventHandler <TEventArgs>, THandler> >(builder1.CreateType().GetMethod("Convert", BindingFlags.Public | BindingFlags.Static)));
        }
コード例 #3
0
ファイル: Cmprsn.cs プロジェクト: cwdotson/FwNs
            public ProjectionComparer(MemberInfo member, Expression value, CultureInfo locale, bool ascending)
            {
                PropertyInfo info = member as PropertyInfo;

                if (info != null)
                {
                    member = info.GetGetMethod(true);
                }
                MethodInfo method = member as MethodInfo;

                if ((method != null) && TypsFw.CanBeDelegateSource(method))
                {
                    this._keySelector = TypsFw.CreateDelegate <Func <T, TKey> >(method);
                }
                else
                {
                    ParameterExpression   expression = null;
                    ParameterExpression[] parameters = new ParameterExpression[] { expression };
                    this._keySelector = Expression.Lambda <Func <T, TKey> >(Expression.MakeMemberAccess(expression, member), parameters).Compile();
                }
                this._subComparer = Cmprsn.CreateKeyComparer <TKey>(value, true, locale);
                this._ascending   = ascending ? 1 : -1;
            }