Hi Guys,
I'm working on a .NET 4 application, C#, Entity Framework 4, SQL Server 2008.
I have a 7 tables in my database, each representing a specific level of location (Country, State, City, Neighborhood, etc).
Now in my Repository I am trying to define an interface contract which has only one Find() method. To do this, I've created ...
Hello everybody
Static methods always should to encapsulate arguments by parenthesis . So it is much more easy to use extension methods while typing. That is one of the reason why i like extension methods.
I am not sure when time it is better to use extension or static methods. And i am thinking that what would be happen if all static ...
Why I'm unable to extend an abstract class. Is there any work around to achieve this?
In silverlight, Enum.GetNames is missing. So, I would like to extend it and have it in my utility assembly. By then, got into this.
...
With extension methods, we can write handy LINQ operators which solve generic problems.
I want to hear which methods or overloads you are missing in the System.Linq namespace and how you implemented them.
Clean and elegant implementations, maybe using existing methods, are preferred.
...
I have the following Extension Method
Imports System.Runtime.CompilerServices
Namespace Extensions
Public Module IntegerExtensions
<Extension()>
Public Function ToCommaDeliminatedNumber(ByVal int As Integer) As String
Dim _input As String = int.ToString
Select Case int
Case I...
I needed a double[] split into groups of x elements by stride y returning a List. Pretty basic...a loop and/or some linq and your all set. However, I have not been spending much time on extension methods and this looked like a good candidate for some practice. The naive version returns what I am looking for in my current application....
...
Hi!
I've added an extension method that is a shortcut to string.Format:
public static string Format(this string format, params object[] args)
{
return String.Format(format, args);
}
When I invoke this method like this:
"{0}".Format(1);
everything works like a charm.
While
"{0}".Format("1");
does not compile with this error...
I need to implement a static extension method supporting member constraints on some basic primitive types like integers, floats, etc. Here's my code for signed integers:
module MyOperators =
let inline foo (x : ^T) = (^T : (static member Foo : ^T -> int) (x))
type System.Int32 with
static member Foo(x : Int32) = 7 // ...
an extension method on a collection named MeasurementCollection checks if the property Template.Frequency (Enum) of each item has the same value.
public static bool IsQuantized(this MeasurementCollection items)
{
return (from i in items
select i.Template.Frequency)
.Distinct()
...
Basically I have a collection of objects each implement a member of Type IValueCollection
public interface IValueCollection : IEnumerable<decimal>
{
decimal this[int index] { get; set; }
}
MeasurementCollection.Values is of type IValueCollection.
With the logic below I want to pivot a collection of IValueCollection and wrote the...
Hello,
Suppose I have a class AddressType defined as is:
public class AddressType {
public int AddressTypeId { get; set; }
public string Description { get; set; }
}
Having a List object in code, how do I select an AddressType object with a known AddressTypeId property?
I have never used the List.Where extension function.......
I was wondering on how FirstOrDefault extension method works? Which one of the following algorithms does it follows?
Use:
var arr = new[] {1, 2, 3, 4, 5, 6, 7};
return arr.FirstOrDefault(x => x%2 == 0);
Algorithm 1:
for(int i = 0; i < arr.Length; i++)
{
if(arr[i] % 2 == 0)
return arr[i];
}
return 0;
Algorithm 2:
var list ...
I am starting to play with extension methods and i came across with this problem:
In the next scenario i get a:
"extension method has a type constraint that can never be satisfied"
Public Interface IKeyedObject(Of TKey As IEquatable(Of TKey))
ReadOnly Property InstanceKey() As TKey
End Interface
<Extension()> _
Public Function To...
Hi, I started with the IQueryable extension methods from this example on CodePlex.
What i believe i need is an IQueryable extension method to "Where", where the method signature looks like:
public static IQueryable<T> Where<T>(this IQueryable<T> source, string columnName, string keyword)
and effectively does this (assuming T.columnNa...
I'm tired of this dictionary idiom:
Dictionary<Guid,Contact> Contacts;
//...
if (!Contacts.ContainsKey(id))
{
contact = new Contact();
Contacts[id] = contact;
}
else
{
contact = Contacts[id];
}
It would be nice if there was a syntax tha...
Invoking an extension method that works on a interface from an implementor seems to require the use of the this keyword. This seems odd.
Does anyone know why?
Is there an easier way to get shared implementation for an interface?
This irks me as I'm suffering multiple inheritance/mixin withdrawl.
Toy example:
public interface ITest
...
If I try to call my extension method which is defined like this:
Module LinqExtensions
<System.Runtime.CompilerServices.Extension()> _
Public Function ToSortableBindingList(Of TSource)(ByVal source As IEnumerable(Of TSource)) As IBindingList
If (source Is Nothing) Then
Throw New ArgumentNullException("source")
End If
...
Hi,
i ask myself if it is a good design if an extension method uses
another in the same extension class.
public class ClassExtensions
{
public static bool IsNotNull<T>(this T source)
where T : class
{
return !source.IsNull();
}
public static bool IsNull<T>(this T source)
where T : class
{
retu...
actually I don't know whether they should work
I made a library in C# and I've been told by people that one of mine methods don't work in VB.NET as extension
http://valueinjecter.codeplex.com/Thread/View.aspx?ThreadId=227498
this is the method:
public static PropertyDescriptorCollection GetProps(this object o)
{
return GetProps(o.G...
Quick question. I just read that if you wanted to add a function to e.g. the List module, you can define a new List module with that function:
module List
let foo = // ...
Does this have the effect of adding foo to the main List module, or do you have to explicitly open the new List? The former seems like Ruby's "monkey patching"; I...