func

Does C have __func__ functionality for names of the arguments of a function?

与世无争的帅哥 提交于 2019-12-06 11:58:33
问题 Does the "C" standard support something similar to __func__ for the function arguments' names? 回答1: if you want a quick and dirty solution for this make pre-processor macros like this... #define FUNCTION_HEADER(a) a { const char* __func__ = #a; #define FUNCTION_FOOTER() } ... and use it for your function headers and footers like this (tested with VS 2008): #include <windows.h> #define FUNCTION_HEADER(a) a { const char* __func__ = #a; #define FUNCTION_FOOTER() } FUNCTION_HEADER( int WINAPI

Mapping Expression<Func<Type1,bool>> Expression<Func<Type2, bool>>

旧巷老猫 提交于 2019-12-06 11:52:24
I want to pass my query from Business Layer to Service Layer but when doing this i have to convert my DTO to Entity model. Normally i can convert Type1 to Type2 via Autommaper but now i want to map Expression<Func<Type1,bool>> to Expression<Func<Type2, bool>> I got error from Automapper Missing type map configuration or unsupported mapping. Mapping types: Expression`1 -> Expression`1 How can i achieve this? luksan I just updated my answer to the another question you commented on, which I think addresses this: AutoMapper for Func's between selector types As for the error you posted above, that

How create a generic Func delegate

给你一囗甜甜゛ 提交于 2019-12-06 06:33:04
问题 I have this method public static T F<T>(T arg) { return arg; } and I want to create a Func delegate to F. I try this public Func<T, T> FuncF = F; but it's not syntactically correct. How I can do that. 回答1: Only classes and methods can be generic in and of themselves. A field that uses generic parameters must be within a generic class context: public class Test<T> { public static T F(T arg) { return arg; } public Func<T, T> FuncF = F; } Or if the type parameter for F should not be connected to

C# creating function queue

南楼画角 提交于 2019-12-06 01:31:03
I have written a class called QueueManager: class QueueManager { Queue functionsQueue; public bool IsEmpty { get { if (functionsQueue.Count == 0) return true; else return false; } } public QueueManager() { functionsQueue = new Queue(); } public bool Contains(Action action) { if (functionsQueue.Contains(action)) return true; else return false; } public Action Pop() { return functionsQueue.Dequeue() as Action; } public void Add(Action function) { functionsQueue.Enqueue(function); } public void Add(Func<CacheObject,Boolean> function) { functionsQueue.Enqueue(function); } and when I create an

Dictionary<T, Func>: how to use T as Func's generic type?

南笙酒味 提交于 2019-12-05 21:59:29
I didn't know how to express it clearly. I have this interface: interface IConverter { Dictionary<Type, Func<string, object>> ConversionMethods { get; } } Basically, it defines a contract saying that a class implementing it should provide conversion methods for all the custom types it uses (be them enums or anything). Is it possible to replace object in Func 's generic types with its corresponding dictionary key's type (so it is impossible to have two unmatching types)? I think it's not possible, but the alternatives are a bit annoying (using dynamic or object , creating a specialized

Better way to Sort a List by any property

£可爱£侵袭症+ 提交于 2019-12-05 21:31:59
My method receives all DataTables parameters to sort table by column clicked. I call this method from controller of each page list. I'm looking for a better way to do this like a generic method for all types: string , int , decimal , double , bool ( nullable or not ). But I can't find it. My current code: public List<T> OrderingList<T>(List<T> list, DataTablesParam model) { var iColumn = model.Order.FirstOrDefault().Column; var property = typeof(T).GetProperty(model.Columns.ToArray()[iColumn].Data); var param = Expression.Parameter(typeof(T)); var final = Expression.Property(param, property);

Use reflection to assign value of Func<Product, object> property

爱⌒轻易说出口 提交于 2019-12-05 19:57:09
If I have a class Product: public class Product { public string Title { get; set; } public string Make { get; set; } public Decimal Price { get; set; } //(Edit) - Added non-string } And I have a property in another class declared as: Func<Product, object> SortBy { get; set; } I can set SortBy using: SortBy = p => p.Title; But how would I, using reflection, make the same assignment if I had the property name for SortBy stored as a string e.g. string sortField = "Title"; SortBy = /*Some reflection using sortField*/; You need to use expression trees to create a new method at runtime: var p =

How to create a Func<> delegate programmatically

这一生的挚爱 提交于 2019-12-05 19:23:12
I have a small dependency injection framework, and I am trying to make it resolve Lazy<> instances dynamically. The idea is to do something like that: DIContainer.Register<IDbCommand,SqlCommand>(); var lazyCommand = DIContainer.Resolve<Lazy<IDbCommand>>(); I read the other day that Autofac was able of doing that. I am stuck trying to set the constructor for that Lazy<> instance. In the next test code, a exception is thrown because the desired type constructor is expecting a Func<arg> , but I am passing a Func<Object> : static readonly Type _lazyType = typeof(Lazy<>); static Object ResolveTest

Use a c# Func as part of an IQueryable without executing into memory call

笑着哭i 提交于 2019-12-05 19:05:09
I'm trying to build a query that will execute against the database as an IQueryable, and not in memory (IEnumerable). The query will be used for several different purposes and each purpose has a slightly different way in which the Total property is calculated. Because I'm using a Func for calculating the total, i get an error advising me that sql doesn't know how to deal with the Invoke method of my Func, which is understandable. To get past the problem, i have had to list the groupings into memor by calling ToList() which is not good for performance. Is there a way that i can execute this

Func(Of Tin, Tout) using a lambda expression with ByRef argument gives incompatible signature error

跟風遠走 提交于 2019-12-05 18:24:51
问题 Why does this: Private [Function] As Func(Of Double, String) = Function(ByRef z As Double) z.ToString gives the following error: Nested function does not have a signature that is compatible with delegate String)'. While this: Private [Function] As Func(Of Double, String) = Function(ByVal z As Double) z.ToString Does not? (The difference is ByRef/ByVal) Furthermore, how might I implement such a thing? 回答1: You are getting this error because the delegate type Function (ByVal z As Double) As