c# - Using Except() on a Generic collection -


I have asked to use a Linq method which is an object (first, min, max, etc.) Normal archive Now I want to be able to use the method (except linq) and I'm not sure how to do this. Maybe the answer is just in front of me but I think I need help. Is a general method that is related to related descriptive fields. Fills in dates. This method has been declared below:

  Public INIM Merchant & lt; T & gt; FillInMissingDates & lt; T & gt; (Ienumerable & lt; T & gt; archive, string date property name, string description property name) {type type = typef (t); Property Info dateProperty = type.GetProperty (datePropertyName); PropertyInfo DetailsProperty = Type. Gateproperty (detailsproperty_name); ...}  

What I want to accomplish is that datePropertyName is the name of the property that I will use to fill my date gap (not already present in the archive Add default object instance for dates). If I was working with a non-normal class, then I would do something like this:

  foreach (string description in description) {var missingDates = allDates.Except (originalData. Select (d = & gt; D. Description == desc). Select (d => D. Transcondet). Ollist ()); ...}  

But how can I do the usual method with dateProperty and descriptionProperty properties by using FillInMissingDates?

I think the best way would be to define the interface with all properties which you want to use Do the classes using the method to implement this interface in your own way. Then, use the common method and prevent the normal type from getting to the interface.

This example can not do exactly what you want - it fills in the missing dates of items in the matching list, but hopefully it will give you the original idea.

  The public interface is electronsable {string description {get; } Date time? {Date of transaction date; }} Public Class Full Restraint: ITRansactable {...} // Conversion Conversion Conversion to Public Static Zero FillInMissingDates & lt; T & gt; (It's IEnumerable & lt; T & gt; collection, string match, date time default date) where T: ITransactable {foreach (var trans in archive where (t = & gt; t description = match)) {if (! Trans.TransactionDate.HasValue) {trans.TransactionDate = defaultDate; }}}  

Before you can use, you will need to make your calculation eligible for iTransons (at least until C # 4.0 does not come out).

  var list = new list & lt; CompletedTransaction & gt; (); List Christ & lt; ITTransitable & gt; () .FillInMissingDates ("description", DateTime.MinValue);  

Alternatively, you can check usage from the archives. This will allow you to specify the name of a property, if it is not compatible between classes. However you will need to use the reflection to set the property, however.


Comments

Popular posts from this blog

c++ - Linux and clipboard -

What is expire header and how to achive them in ASP.NET and PHP? -

sql server - How can I determine which of my SQL 2005 statistics are unused? -