Hi,
Is there a rule for knowing when one has to pass the generic type parameters in the client code when calling an extension method?
So for example in the Program class why can I (a) not pass type parameters for top.AddNode(node), but where as later for the (b) top.AddRelationship line I have to pass them?
class Program
{
stati...
I have a Dictionary<string,int> and I simply want to decrement the value in my dictionary by one.
I have this but not sure if its best practice.
foreach (KeyValuePair<string, int> i in EPCs)
{
EPCs[i.Key] = i.Value - 1;
}
UPDATE: The reason I am trying to decrement the value is becase the value is a index number relating to a posi...
First, I wish to write myself a generic type for operations against the underlying Active Directory.
For those of you who know about AD and the System.DirectoryServices namespace, the DirectoryEntry class is the top most important along with the DirectorySearcher class.
When speaking the AD language, everything is a DirectoryEntry. Wit...
Suppose you have a generic interface and an implementation:
public interface MyInterface<T> {
void foo(T param);
}
public class MyImplementation<T> implements MyInterface<T> {
void foo(T param) {
}
}
These two types are framework types I provide. In the next step I want allow users to extend that interface as well as redecla...
Hi,
I want to create a re-usable library. I was going to use extension methods however I run into some issues in some cases for the client to have to specify in the calling method the types.
QUESTION - If I use an abstract base class as the basis, can I specify an attribute/property in the class to be generic (e.g. the key property m...
Example:
System.Web.Security.MembershipCollection implements IEnumerable and not IEnumberable<T>. Why doesn't it implement the latter, when it seems that it would be better (e.g. use LINQ)?
Or, is it not necessarily better?
...
Hi,
Is there a way to implement the "CreateNode" method in my library abstract below? Or can this only be done in client code outside the library? I current get the error "Cannot create an instance of the abstract class or interface 'ToplogyLibrary.AbstractNode"
public abstract class AbstractTopology<T>
{
// Properties
publi...
Hi, I am trying to create a method that takes a DataTable or a DataRowCollection and converts it to an array of a generic type. Something like this:
public static T[] ConvertToArray<T>(DataTable dataTable)
{
List<T> result = new List<T>();
foreach (DataRow dataRow in dataTable.Rows)
result.Add((T)dat...
I'm trying to get the next item in a list of strings (postal codes). Normally I'd just foreach till I find it and then get the next in the list but I'm trying to be a bit more intuitive and compact than that (more of an exercise than anything).
I can find it easily with a lambda:
List<string> postalCodes = new List<string> { "A1B", "A2...
I've got this code that works:
def testTypeSpecialization: String = {
class Foo[T]
def add[T](obj: Foo[T]): Foo[T] = obj
def addInt[X <% Foo[Int]](obj: X): X = {
add(obj)
obj
}
val foo = addInt(new Foo[Int] {
def someMethod: String = "Hello world"
})
foo.someMethod
}
But, I'd lik...
Hello, as per the title I am struggling to find the cause of an "unchecked or unsafe operations" warning in some code.
If I have the following code, it compiles without any warnings:
public void test()
{
Set<String> mySet = new HashSet<String>();
Set<String> myNewSet = mySet;
//do stuff
}
Now, if I change where mySet c...
This method that uses method-level generics, that parses the values from a custom POJO, JXlistOfKeyValuePairs (which is exactly that). The only thing is that both the keys and values in JXlistOfKeyValuePairs are Strings.
This method wants to taken in, in addition to the JXlistOfKeyValuePairs instance, a Class<T> that defines which data ...
I am looking into creating an Entity Framework 4 generic repository for a new ASP.NET MVC project i am working on. I have been looking at various tutorials and they all seem to use the Unit of Work pattern ...
From what i have been reading, EF is using this already within the ObjectContext and you are simply extending this to make your ...
Hi,
What's the recommended way to cover off unit testing of generic classes/methods?
For example (referring to my example code below). Would it be a case of have 2 or 3 times the tests to cover testing the methods with a few different types of TKey, TNode classes? Or is just one class enough?
public class TopologyBase<TKey, TNode, ...
The question stems from database tables comparison. Let's say we put left row in the instance Left and the right one into instance Right of the same type. And we'got many tables and respective types.
How to implement more or less generic routine resulting in a collection of diffs e.g.
propertyName , leftValue , rightValue for each suc...
I'm writing myself a class library to manage Active Directory.
I have an interface:
Public Interface ISourceAnnuaire(Of T as {IGroupe, ITop, IUniteOrganisation, IUtilisateur})
Readonly Property Changements As Dictionary(Of T, HashSet(Of String))
End Interface
This Changements property is used to save in memory the changes that oc...
I'm trying to use DbLinq with a SQLite database, but I'm running into a problem when I try to cast an ITable as a Queryable<TEntity>.
There is a known bug in DbLinq (Issue 211), which might be the source of my problem, but I wanted to make sure my code is sound and, if it is, find out if there might be something I can do to work around ...
I'm trying to make a generic class that takes 3 types, either a simple string, IList<string> or a IList<OntologyStore>.
public class OntologyStore
{
}
public sealed class jim<T> where T:new()
{
string J;
IList<string> X = null;
IList<OntologyStore> X1 = null;
public jim()
{
if (typeof(T) == typeof(String))
...
I've created an F# class to represent an array that allocates one element for each value of a specific enum. I'm using an explicit constructor that creates a dictionary from enum values to array indices, and an Item property so that you can write expressions like:
let my_array = new EnumArray<EnumType, int>
my_array.[EnumType.enum_value...
I have 2 scenarios.
This fails:
class F<X>
{
public X X { get; set; }
}
error CS0102: The type 'F<X>' already contains a definition for 'X'
This works:
class F<X>
{
class G
{
public X X { get; set; }
}
}
The only logical explanation is that in the second snippet the type parameter X is out of scope, which is not true...