following setup, i have several generic functions, and i need to choose the type and the function identified by two strings at runtime.
my first try looked like this:
public static class FOOBAR
{
public delegate void MyDelegateType(int param);
public static void foo<T>(int param){...}
public static void bar<T>(int param){....
I have the need for an object to object mapper in my application. I've tried out a few, but haven't been able to find anything that fits my needs, so I'm writing my own. Currently I have an interface like below:
public interface IMapper<T, R> {
T Map(R obj);
}
I then implement an AccountMapper that maps a Customer to an Account ...
I have a static generic class that helps me move events around with very little overhead:
public static class MessageBus<T> where T : EventArgs
{
public static event EventHandler<T> MessageReceived;
public static void SendMessage(object sender, T message)
{
if (MessageReceived != null)
MessageReceived(sen...
Trying to find out if a provided Type is of a given generic type (with any generic types inside)
Let me Explain:
bool IsOfGenericType(Type baseType, Type sampleType)
{
/// ...
}
Such that:
IsOfGenericType(typeof(Dictionary<,>), typeof(Dictionary<string, int>)); // True
IsOfGenericType(typeof(IDictionary<,>), typeof(Dictionary<st...
I need to create a generic type, but I do not know the type at compile time. I would like to do this:
Type t = typeof(whatever);
var list = new List<t>
this won't compile, because t is not a valid type. But it does know all about a valid type. Is there a way to dynamically create the generic list from a System.Type like this? I may ne...
Hi,
Any see why I'm getting a "Argument 1: cannot convert from 'ToplogyLibrary.RelationshipBase' to 'TRelationship'" in the code below, in CreateRelationship() ?
public class TopologyBase<TKey, TNode, TRelationship>
where TNode : NodeBase<TKey>, new()
where TRelationship : RelationshipBase<TKey>, new()
{
// Properties
p...
What is Action<string>, how can it be used?
...
This is NOT homework.
Part 1
Is it possible to write a generic method, something like this:
<T extends Number> T plusOne(T num) {
return num + 1; // DOESN'T COMPILE! How to fix???
}
Short of using a bunch of instanceof and casts, is this possible?
Part 2
The following 3 methods compile:
Integer plusOne(Integer num) {
...
I get "E2511 Type parameter 'T' must be a class type" on the third class.
type TSomeClass=class
end;
ParentParentClass<T>=class
end;
ParentClass<T: class> = class(ParentParentClass<T>)
end;
ChildClass<T: TSomeClass> = class(ParentClass<T>)
end;
I'm trying to write a lite Generic Array wrapper for any data type(ParentParentClass) ,...
I have an interface IGenericRepository<TEntity> where TEntity : IEntity and an implementation GenericRepository<TEntity> where TEntity : Entity.
I'm trying to inject a specific IGenericRepository<Section> into a class using StructureMap:
ObjectFactory.Initialize(x =>
{
x.For(typeof(IGenericRepository<>)).Use(typ...
It is possible to create a Func object what references a generic method? like the LINQ OrderBy:
public static IOrderedEnumerable<TSource> OrderBy<TSource, TKey>(
this IEnumerable<TSource> source,
Func<TSource, TKey> keySelector
)
...
I have the following abstract class design, I was wondering if anyone can suggest any improvements in terms of stronger enforcement of our requirements or simplifying implementing of the ControllerBase.
//Dependency Provider base
public abstract class ControllerBase<TContract, TType> where TType : TContract, class
{
public static TC...
NavigatorItem NavItem = (NavigatorItem)cboItems.SelectedItem;
lblTitle.Text = NavItem.Title;
RadWrapPanel Panel = new RadWrapPanel();
Type t = NavItem.ItemsType; //<------ The Type inside my List is here.
List<???> items = (List<???>)NavItem.Items; // <----Here Is the problem
foreach (object i...
type
TParent=class
public
member1:Integer;
end;
TChild=class(TParent)
public
member2:Integer;
end;
TGArray<T: TParent>=class
public
function test:T;
end;
implementation
var g:TGArray<TChild>;
function TGArray<T>.test:T;
begin
Result:=??.create; // <<<< Problem !
end;
...
I have 3 generict type list.
List<Contact> = new List<Contact>();
List<Address> = new List<Address>();
List<Document> = new List<Document>();
And save it on a variable with type object. Now i nedd do Cast Back to List to perfom a foreach, some like this:
List<Contact> = (List<Contact>)obj;
But obj content change every time, and i h...
Is there any issues in using version 2,to get the same results as version 1.
Or is this just bad coding.
Any Ideas
public class Customer
{
public int CustomerID { get; set; }
public string EmailAddress { get; set; }
int Age { get; set; }
}
public interface ICustomer
{
void AddNewCustomer(Customer Customer);
void A...
Let's say I have a class library that defines a couple entity interfaces:
public interface ISomeEntity { /* ... */ }
public interface ISomeOtherEntity { /* ... */ }
This library also defines an IRepository interface:
public interface IRepository<TEntity> { /* ... */ }
And finally, the library has an abstract class called Repository...
I'm writing a XML (de)serializer using Text.XML.Light and Scrap your Boilerplate (at http://github.com/finnsson/Text.XML.Generic) and so far I got working code for "normal" ADTs but I'm stuck at deserializing existentials.
I got the existential data type
data DataBox where
DataBox :: (Show d, Eq d, Data d) => d -> DataBox
and I'm t...
Hi all!
I'm working on an AVL Tree. The tree itself seems to be working but I need a iterator to walk through the values of the tree. Therefore I tried to implement the IEnumerator interace. Unfortunately I get a compile time error implementing IEnumerator and IComparable. First the code and below that the error.
class AvlTreePreOrderE...
Hi
I tried to implement a generic binary search algorithm in scala. Here it is :
type Ord ={
def <(x:Any):Boolean
def >(x:Any):Boolean
}
def binSearch[T <: Ord ](x:T,start:Int,end:Int,t:Array[T]):Boolean = {
if (start > end) return false
val pos = (start + end ) / 2
if(t(pos)==x) true
else if (t(pos) < x) binSearch(x,pos+1,end,...