Lets say i call method M1 on class A using reflection.
The method does not exist.
Is there any way to put a handler on class A that says, "someone is trying to execute method M1"?
Or
Is it possible to add a method dinamically to a class? I want to add a method M1...Mn that always does MyStaticClass.DoAction("M1...Mn");
Something li...
Forgive my clumsy explanation, but I have a class that contains a List:
public class Document
{
public int OwnerId { get; set; }
public List<User> Users { get; set; }
public Document() { }
}
public class User
{
public string UserName { get; set; }
public string Department { get; ...
This is not a homework ;)
I need to both A) optimize the following code (between a TODO and a ~TODO) and B) convert it to [P]Linq. Better readability is desired. It might make sense to provide answers to A) and B) separately. Thanks!
lock (Status.LockObj)
{
// TODO: find a better way to merge these dictionaries
foreach (KeyValue...
How can i do dynamic group by in linq to objects in #siverlight client side?
i want to do something like this:
var x = "empt.Dept";
var groups = from emp in employees
group emp by x into g
select new { Dept = g.Key, Count = g.Count() };
I tryed also to use reflection and do something like employee.GetType().GetProperty("Dep...
hi all,
I am trying to get the longest and shortest timespan in a list using LINQ.
My code looks something like this
List listofTimeSpans = new List();
adding the timespans to listofTimeSpans in a foreach loop.
Please help me with this.
Thank you.
...
I want to modify a local variable in a function of extension method.
See
int myvar=0;
MyList.Where(
x =>
{
if (condition)
myvar += 1;
return false;
});
return myvar;
Why that is not working?
...
I have set myself upon a journey to educate my coworkers (all have accepted my mission, even the boss).
Every day I seem to find a piece of code that could have been less error prone if my coworkers knew more about the framework, better-know-framework (in courtesy of DNR ;)) is part two of my teaching process. First part is teaching my c...
Hello All
i have a US states list
List<string> state // contain all 51 US states
Now i have a string which contain some text like okl (it means Oklahoma for me). what i want i want 'like' query in List state and get Oklahoma state.
...
I've got some objects which implement this interface:
public interface IRow
{
void Fill(DataRow dr);
}
Usually when I select something out of db, I go:
public IEnumerable<IRow> SelectSomeRows
{
DataTable table = GetTableFromDatabase();
foreach (DataRow dr in table.Rows)
{
IRow row = new MySQLRow(); // Disregard the MySQLR...
Take the following pseudo C# code:
using System;
using System.Data;
using System.Linq;
using System.Collections.Generic;
public IEnumerable<IDataRecord> GetRecords(string sql)
{
// DB logic goes here
}
public IEnumerable<IEmployer> Employers()
{
string sql = "select EmployerID from employer";
var ids = GetRecords(sql).S...
Can I do a LINQ Join from an List to a DataSet? Are there any caveats to doing this?
...
This is tricky to explain.
We have a DataTable that contains a user configurable selection of columns, which are not known at compile time. Every column in the DataTable is of type String. We need to convert this DataTable into a strongly typed Collection of "ReturnItem" objects so that we can then sort and filter using LINQ for use in ...
I have the following LINQ query:
List<FileInputItem> inputList = GetInputList();
var results = from FileInputItem f in inputList
where ( Path.GetDirectoryName(f.Folder).ToLower().Trim() == somePath
|| Path.GetDirectoryName(f.Folder).ToLower().Trim() == someOtherPath )
&& f.Expressi...
I am trying to combine two SortedDictionaries, change the result to a List<KeyvaluePair<string,string>> and Sort() the result. The following statement throws an error:
var combinedEntries = from p in leftDict.Union(rightDict).ToList().Sort(myComparer) select p;
Error: Could not find an implementation of the query pattern for source ty...
I have a method that takes a List<int>, which is a list of IDs. The source of my data is a Dictionary<int, string> where the integers are what I want a list of. Is there a better way to get this than the following code?
var list = new List<int>();
foreach (var kvp in myDictionary)
{
list.Add(pair.Key);
}
ExecuteMyMethod(list);
...
I saw this similar question here but can't figure out how to use Contains in Cartesian product desired result situation:
http://stackoverflow.com/questions/1712105/linq-to-sql-exception-local-sequence-cannot-be-used-in-linq-to-sql-implementatio
Let's say I have following:
var a = new [] { 1, 4, 7 };
var b = new [] { 2, 5, 8 };
var te...
Lets say we have a simple class
public class Foo
{
public string FooName;
}
Now we want to do some simple work on it.
public void SomeCallerMethod(List<Foo> listOfFoos)
{
string[] fooNames = listOfFoo. // What to do here?
}
If I even knew what method to call, I could probably find the rest of the peices.
...
Is there some way of detecting whether an enumerable built using LINQ (to Objects in this case) have been materialized or not? Other than trying to inspect the type of the underlying collection?
Specifically, since enumerable.ToArray() will build a new array even if the underlying collection already is an array I'm looking for a way of ...
Consider the need to search a list of Customer by both first and last names. The desire is to have the results list sorted by the Customer with the most matches in the search terms.
FirstName LastName
---------- ---------
Foo Laurie
Bar Jackson
Jackson Bro
Laurie Foo
Jackson Laurie
...
I have an array...and I need to exclude all the items in this array of string from the masterList.customField as shown below
string[] excludeItem = {"a","b","c"};
CustomDTO[] masterList = service.LoadMasterList();
masterList.Where(c=> masterList.customField NOT IN excludeItem
How do I achieve the NOT IN part above?
...