I'm checking out the Delphi 2009 Trial, but run into problems with the generics stuff right away.
The following code does not compile, and I haven't the slightest idea why it's giving me E2015 for the Equals() method:
type
TPrimaryKey<T> = class(TObject)
strict private
fValue: T;
public
constructor Create(AValue: T);
...
Has anyone else run into this problem before? I've got a method that calls a generic method with a delegate, inside of a generic class. I've marked the class as Serializable, and it serializes without complaint. But, when I try to deserialize an object of this class, it pegs the CPU and hangs the machine.
Code example:
public delegate ...
VB.Net2005
Simplified Code:
MustInherit Class InnerBase(Of Inheritor)
End Class
MustInherit Class OuterBase(Of Inheritor)
Class Inner
Inherits InnerBase(Of Inner)
End Class
End Class
Class ChildClass
Inherits OuterBase(Of ChildClass)
End Class
Class ChildClassTwo
Inherits OuterBase(Of ChildClassTwo)
End Clas...
Previously, I had a class that wrapped an internal System.Collections.Generic.List<Item> (where Item is a class I created). The wrapper class provided several collection-level properties that provided totals, averages, and other computations on items in the list. I was creating a BindingSource around this wrapped List<> and another Bin...
Hi,
I have a class storing the name of a WS method to call and the type and value of the only parameter that service receives (it will be a collection of parameters but lets keep it simple for the example):
public class MethodCall
{
public string Method { get; set; }
public Type ParType { get; set; }
public string ParValue { get; ...
Hello,
what is the difference in using a standard
type sl: TStringList
compared to using a generic TList
type sl: TList<string>
?
As far as I can see, both behave exactly the same.
Is it just another way of doing the same thing?
Are there situations where one would be better than the other?
Thanks!
Holger
...
hi,
here is my example code:
Public Class Parent
Private _TestProperty As String
Private WithEvents _Child As IList(Of Child)
Public Property Test() As String
Get
Return _TestProperty
End Get
Set(ByVal value As String)
_TestProperty = value
End Set
End Property
...
The code below gives an error: Property 'Int32 Key' is not defined for type 'ConsoleApplication1.IKeyed`1[TKey]' when the expression e is created but is fine when func f is created, can anyone explain why and if there is a way to fix it?
Module Module1
Sub Main()
Dim g = New keyedThingGetter(Of KeyedThing, Integer)
...
In C# I sometimes wish I could make special methods for certain "instantiations" of generic classes.
UPDATE: The following code is just a dumb example of a more abstract problem - don't focus too much on time series, just the principles of "adding extra methods" for certain T.
Example:
class Timeseries<T>
{
...
TimeSeries<T>...
Hi guys
I can't figure out why the following wont work, any ideas??
public interface IFieldSimpleItem
{ }
public interface IFieldNormalItem : IFieldSimpleItem
{ }
public class Person
{
public virtual T Create<T>()
where T : IFieldSimpleItem
{
return default(T);
}
}
public class Bose : Person
{
...
My class contains a Dictionary<T, S> dict, and I want to expose a ReadOnlyCollection<T> of the keys. How can I do this without copying the Dictionary<T, S>.KeyCollection dict.Keys to an array and then exposing the array as a ReadOnlyCollection?
I want the ReadOnlyCollection to be a proper wrapper, ie. to reflect changes in the underl...
public class Item
{
private int _rowID;
private Guid _itemGUID;
public Item() { }
public int Rid
{
get
{
return _rowID;
}
set { }
}
public Guid IetmGuid
{
get
{
retu...
So, let's say I want to write a class that operates on different kinds of numbers, but I don't a priori know what kind of numbers (i.e. ints, doubles, etc.) I will be operating on.
I would like to use generics to create a general class for this scenario. Something like:
Adder<Double> adder = new Adder<Double>();
adder.add(10.0d, 10....
private void activateRecords(long[] stuff) {
...
api.activateRecords(Arrays.asList(specIdsToActivate));
}
Shouldn't this call to Arrays.asList return a list of Longs? Instead it is returning a List<long[]>
public static <T> List<T> asList(T... a)
The method signature is consistent with the results, the varargs throws th...
My present contract engagement is at a large E-Commerce company. Their code base which has origins going back to .Net 1.0 has caught me by surprise to contain many issues that raise the level of smell beyond the last crap I took.
That notwithstanding and trying to diffuse my level of distraction from it, I go along merrily trying to ad...
I want to build two-dimentional array of strings where length of one dimention is 2. Similar to this
string[,] array = new string[,]
{
{"a", "b"},
{"c", "d"},
{"e", "f"},
{"g", "h"}
}
Doing
List<string[]> list = new List<string[]>();
list.Add(new string[2] {"a", "b"});
list.Add(new string[2] {"c", "d"});
list.Add(new...
I'm having some trouble with a generic method I'm writing. It has the following signature;
public static ThingCollection<T> GetThings<T>(...) where T : Thing
There are several classes; ThingA, ThingB and ThingC that inherit from Thing; and I want to be able to have code something like this in the method.
var things = new ThingCollec...
The following code does not compile:
public class GenericsTest {
public static void main(String[] args) {
MyList<?> list = new MyList<Object>();
Class<?> clazz = list.get(0);
// Does not compile with reason
// "Type mismatch: cannot convert from Object to Class"
MyList list2 = new MyList...
Why EAccessViolation is raised?
uses
Generics.Collections;
...
var
list: TList<TNotifyEvent>;
...
begin
list := TList<TNotifyEvent>.Create();
try
list.Add(myNotifyEvent);
list.Remove(myNotifyEvent); // EAccessViolation at address...
finally
FreeAndNil(list);
end;
end;
procedure myNotifyEvent(Sender: TObj...
I am binding a generic List to an <asp:ListView /> control to display a tag cloud. The elements in the list are Tag objects, where Tag is basically just something like:
public class Tag {
public string Name { get; set; }
public int Total { get; set; }
}
I create the List<Tag> object and then bind it to a ListView but when the ...