Here is a C# program that tries Marshal.SizeOf on a few different types:
using System;
using System.Runtime.InteropServices;
[StructLayout(LayoutKind.Sequential)]
class AClass { }
[StructLayout(LayoutKind.Sequential)]
struct AStruct { }
[StructLayout(LayoutKind.Sequential)]
class B { AClass value; }
[StructLayout(LayoutKind.Sequent...
I just started messing with generics and I want to make sure I got this right, any help?
public interface Cart<T extends CartItem> {
public void setItems(List<T> items);
public List<T> getItems();
}
public interface CartItem {
public BigDecimal getQty();
public void setQty(BigDecimal qty);
// more
}
public class Ca...
I'm currently building a node editor (as in Blender) and am having trouble getting delegates to property accessors from a generic type. So far the question here has brought me closest, but I'm having trouble that I think is specifically related to the type of object being generic.
For reference, a "Node" is synonymous with an object, an...
Inspired by Javascripts variable Arguments in Max()/Min() and list comprehension in functional languages I tried to get the same in VB.NET using Generic Extension methods given IEnumerable(of T) as resulttype. This works well excepts for strings. Why?
These kind of extension methods may be considered a bad idea. Any strong reason Why t...
I am looking for a better 'pattern' for working with a list of elements which each need processed and then depending on the outcome are removed from the list.
You can't use .Remove(element) inside a foreach (var element in X)... you also can't use for (int i = 0; i < elements.Count(); i++) and .RemoveAt(i).
Previously I have done craz...
I'm trying to create the extension method AddRange for HashSet so I can do something like this:
var list = new List<Item>{ new Item(), new Item(), new Item() };
var hashset = new HashSet<Item>();
hashset.AddRange(list);
This is what I have so far:
public static void AddRange<T>(this ICollection<T> collection, List<T> list)
{
fore...
//The class is defined like so....
public class CreateNewAccountHandler : ICommandHandler<CreateNewAccountCommand, CreateNewAccountResponse>
{
public CreateNewAccountResponse ExecuteCommand(CreateNewAccountCommand command)
{
throw new NotImplementedException();
}
}
//And here it the code which won...
I'm trying to add generic service support to our IoC container, and I have a question.
Let's say I have the following type:
public interface IService<T> { ... }
public class Service<T> : IService<T> { ... }
and then the following code:
Type type = typeof(Service<>); // <-- notice no specific type here
ConstructorInfo ctor = LogicToF...
Are there any good algorithms for determining the "best" type to instantiate in order to fulfill a request?
For instance say I have the following classes:
public interface ISometype<T> {}
public class SomeTypeImpl<T>:ISometype<T> {}
public class SomeSpecificTypeImpl<T>:ISometype<T> where T: ISpecificSpecifier {}
public interface ISpeci...
HashSet does not have an AddRange method, so I want to write an extension method for it. This is what I have:
public static void AddRange<T>(this ICollection<T> collection, IEnumerable<T> list)
{
foreach (var item in list)
{
collection.Add(item);
}
}
I have a base class, Media, and a derived class, Photo. This is t...
I have a class declared as:
public class Foo<T> : Panel where T : Control, IFooNode , new()
{
...
}
I added it by hand to test it, but I will eventually need something that can be displayed in the Forms designer. The Forms designer doesn't like this, it says:
Could not find type 'FooTestNameSpace.Foo'.
Please make sure that the ...
Hi there,
I do need a solution for loading lists of objects - lookups where only one property is referenced from the current object as in this example.
class LookupObjectAddress
{
[...]
public string City
{ get; set; }
[...]
}
class WorkingObject
{
// references the property from LookupObjectAddress
public string City
{ get; s...
Hi all,
I'm new to generics and have been trying to figure out how i can return an instance of a class whose base is generic from a factory. See sample code below. The issues are highlighted in factory class:
public abstract class MyGenericBaseClass<T>
{
public string Foo()
{...}
}
public sealed class MyDerivedIntClass : MyGen...
Is there any way that one can encapsulate Dictionary to be a new type like DataDictionary so that instead of needing to change the definition in however many places it is used, it can be changed in only a few. Or should I just wrap this in another class that exposes only the aspects that I need?
...
Is it necessary to parametrize the entire interface for this scenario, even though Bar is only being used in a single method?
public interface IFoo<T>{
void method1(Bar<T> bar);
//Many other methods that don't use Bar....
}
public class Foo1 implements IFoo<Yellow>{
void method1(Bar<Yellow> bar){...};
//Many othe...
In searching for an answer to an interesting situation which I had recently encountered I came upon the following question: Type safety, Java generics and querying
I have written the following class (cleaned up a bit)
public abstract class BaseDaoImpl<T extends Serializable> extends HibernateDaoSupport implements BaseDao<T> {
/**
...
Hi,
Could anyone help me with the line where TEntity : class, IEntity, new() in the following class declaration.
public abstract class BaseEntityManager<TEntity>
where TEntity : class, IEntity, new()
Thanks for your help in advance.
...
I'm using Delphi 2009. Is it possible to write a class helper for a generic class, i.e. for TQueue . The obvious
TQueueHelper <T> = class helper of TQueue <T>
...
end;
does not work, nor does
TQueueHelper = class helper of TQueue
...
end;
...
I'm working on a List implementation. Because of this, I'll have to override the methods
Collection.containsAll(Collection<?> c);
Collection.removeAll(Collection<?> c);
Collection.retainAll(Collection<?> c);
But as it's explained by Sun, they accept collections with any kind of content (note the <?>). So the collection is not checked ...
Here's a thinned out version of the classes I have.
public abstract class BaseParent { }
public abstract class ChildCollectionItem<T>
where T : BaseParent
{
// References a third-party object that acts as the parent to both the collection
// items and the collection itself.
public T parent;
// References the collection to w...