I have the following code:
public static T ParameterFetchValue<T>(string parameterKey)
{
Parameter result = null;
result = ParameterRepository.FetchParameter(parameterKey);
return (T)Convert.ChangeType(result.CurrentValue, typeof(T), CultureInfo.InvariantCulture);
}
The type of result.CurrentVal...
I've been reading Bruce Eckel's Thinking In Java and in the chapter on generics, he briefly mentions the Nice programming language as something that handles parametrized types better than Java, but compiles into Java bytecode.
Does anyone have any experience with this? Generics make my head hurt, so the prospect of an alternative that i...
I have a class called DataSet with various constructors, each specifying a different type of variable. It might look a bit like this:
public class DataSet
{
private HashSet Data;
public DataSet( DataObject obj )
{
Data = new <DataObject>HashSet();
Data.add( obj );
}
public DataSet( ObjectRelations...
Hi all,
I've got a control that's declared thus:
public partial class MessageBase<T> : UserControl
{
protected T myEntry;
public MessageBase()
{
InitializeComponent();
}
public MessageBase(T newEntry)
{
InitializeComponent();
myEntry = newEntry;
...
Hi, all
I'm trying to combine a number of List<T> where T:IGetTime (i.e T will always have method getTime()).
Then I'm trying order the items by the DateTime that getTime() returns.
My LINQ looks like this:
public static List<T> Combine(List<T> one, List<T> two, List<T> three)
{
var result = from IGetTime item in one
...
All I am trying to do is
XmlSerializer serializer = new XmlSerializer(typeof(Stack<int>));
and I get the following at runtime:
System.InvalidOperationException: You must implement a default accessor on
System.Collections.Generic.Stack`1 [[System.Int32, mscorlib, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089]] b...
I thought a great way to test my understanding of generic functions would be to create a function that would spit out a hex representation of a hash using one of the classes that inherits from HashAlgorithm. Since all of the HashAlgorithm classes offer ComputeHash, I thought this would be simple. When I construct such a function. though,...
Can anyone explain to me why I would want to use IList over List in C#?
Related question: Why is it considered bad to expose List<T>
...
Duplicate of: http://stackoverflow.com/questions/361336/what-are-generics-in-c#
I have a VB background and I'm converting to C# for my new job. I'm also trying to get better at .NET in general. I've seen the keyword "T" used a lot in samples people post. What does the "T" mean in C#? For example:
public class SomeBase<T> where T : ...
I'm trying to create a UserControl that inherits from a generic class. It does not directly inherit from a generic class, but through an intermediate class that does not use generics. This compiles and works at runtime, but I get an error at design time.
Here's my generic parent class:
Public Class GenericParent(Of T)
Inherits Us...
Here's a simple syntax question (I hope), I know how to constrain one generic type using the where clause, but how to constrain two generic types?
Maybe the easiest way is to write down what my best guess as to the syntax was.
public class GenericDaoGetByIdTests<TDao, TComponent> : BaseDaoTests
where TDao : IDao<TComponent>, TCompon...
I am working on code generation and ran into a snag with generics. Here is a "simplified" version of what is causing me issues.
Dictionary<string, DateTime> dictionary = new Dictionary<string, DateTime>();
string text = dictionary.GetType().FullName;
MessageBox.Show(text);
With the above code snippet the value for "text" is as follows...
Coming from a C++ background, I've run into a snag with overloading based on a specific instance of a generic type. The following doesn't work since only once instance of the code for the Foo<T> class is ever generated, so inside the Method, the type of this is simply Foo<T>, not Foo<A> or Foo<B> as I'd hoped. In C++ I'm used to templa...
is there any difference between:
lock((IDictionary) _collection).SyncRoot)
or
lock(_collection)
...
Is there a way to generate a class constraint with CodeDom.
Because when I use something like
var method = new CodeMemberMethod();
var genericParam = new CodeTypeParameter("InterfaceType");
genericParam.Constraints.Add("class");
method.TypeParameters.Add(genericParam);
the generated code is like
private InterfaceType GetImpl<Interfa...
I come from a C++ background where I can use template mixins to write code that refers to FinalClass which is a template parameter that is passed in. This allows reusable functions to be "mixed-in" to any derived class, by simply inheriting from ReusableMixin with a template paramter of MyFinalClass. This all gets inlined into the clas...
Specifically, with a SortedMap<Vector<String>, int> I get "dimensions expected after this (int) token." Help!
...
Is there a way in Java to have a map where the type parameter of a value is tied to the type parameter of a key? What I want to write is something like the following:
public class Foo {
// This declaration won't compile - what should it be?
private static Map<Class<T>, T> defaultValues;
// These two methods are just fine
...
I'm currently working on a hobby project, written in Java, containing about two different JFrames with about 3-4 JPanels each. The problem I'm facing is that I'm not so sure how to handle the interaction with my controller and different view classes.
For instance, I've an article by Sun on Java App. design with MVC, where they list the ...
I have a few classes such that:
public class XMLStatusMessage extends XMLMessage
{}
public abstract class XMLMessage implements IMessage
{}
public interface IMessageListener
{
public void onMessage( IMessage message );
}
public interface XMLMessageListener <T extends XMLMessage> extends
IMessageListener
{
public void onMe...