I would like to build a generic class that I can use to implement Parameterized Properties in C#. The basic code I want is this:
public class ParameterizedProperty<typeReturn, typeIndexer> {
private typeReturn oReturn = default(typeReturn);
public typeReturn this[typeIndexer oIndexer] {
get { return oReturn[oIndexer]; }...
Hi there, I have two ILIst of these objects:
class ProductionMachineType
{
string code { get; set; }
IEnumerable<string> ProductionToolsLink { get; set; }
}
class ProductionTools
{
string code { get; set; }
}
I am looking for a fast Linq method that make me able to query the IList<Produ...
I want to pass a converter to a method, and the constraint must be that the converter always gets a string as argument. I tried the following, but it won't compile:
class Test
{
public void Foo(string val, Converter<Tin,Tout> conv)
where Tin:string
{
myObj = conv(val);
}
}
...
Suppose I have the following class hierarchy:
Class A {...}
Class B : A {...}
Class C : A {...}
What I currently have is
Class D<T> where T : A {...}
but I'd like something of the form
Class D<T> where T in {B,C}
This is due to some odd behavior I'm not responsible for where B and C have common methods which aren't in A, but ...
I've written a small utility method but it always produces a ClassCastException, any ideas why? and how to fix it?
<T> T[] subArray(int begin, int end, T[] array) {
int size = end - begin;
Object[] newArray = new Object[size];
for (int i = 0; i < size; i++) {
newArray[i] = array[begin + i];
}
return (T[]) new...
I am working on a class library and am having some trouble with generics. I have a ITransaction interface which has a collection of ITransactionItem. Each ITranscation can be either a CapitalCall or Distribution. A CapitalCall is a ITransaction but has a few additional properties. A CapitalCallItem is a ITransactionItem with a few additi...
I have a class with these properties:
public List<CommitmentItem<ITransaction, ITransactionItem>> CommitmentItems;
public List<CapitalCallCommitmentItem> CapitalCallCommitmentItems;
CapitalCallCommitmentItem inherits CommitmentItem. I want the CapitalCallCommitmentItems property to return all CommitmentItems where the type is of Capit...
I have a generic list class:
TMyObjectlist<T: TMyObject> = class(TObjectList<T>);
and a derived list class:
TMyDerivedObjectList = class(TMyObjectList<TMyDerivedObject>);
I want to check if an instance MyList of TMyDerivedObjectList inherits from TMyObjectList, however:
MyList.InheritsFrom(TMyObjectlist<TMyObject>)
returns False...
I would like to create a list of objects in which there is a generic list.
So what I have is this object:
public class agieDBColumn where dataTp:IComparable{
private string _header;
private string _longHeaderName;
private List _data;
public string header {
get { return _header; }
set { _header = value; }
}
public string longH...
I have the following abstract classes:
public abstract class AbSuperClass1<K,S> {
//class definition
}
and:
public abstract class AbSuperClass2<K,S> {
public abstract <Q extends AbSuperClass1<K,S>> void method(Q arg);
...
}
I then have two concrete implementations
public class Concrete1 extends AbSuperClass<String, Str...
I'd like to implement a function with both generics and varargs.
public class Question {
public static <A> void doNastyThingsToClasses(Class<A> parent, Class<? extends A>... classes) {
/*** something here ***/
}
public static class NotQuestion {
}
public static class SomeQuestion extends Question {
}
...
I want to write an extension method that tests if an attribute is applied on a method call, and I'd like to specify the method as a lambda expression. Currently, I have the following (working) approach, but I really don't like the way this code looks:
// Signature of my extension method:
public static bool HasAttribute<TAttribute, TDele...
I'm trying to serialize an entity and all its related entities for storing as xml before physically deleting the entity (leaving an audit trail).
I'm using a DataContractSerializer which seems to be getting around the shallow serialization performed when using an XmlSerializer.
The only trouble is that only related entities that have b...
I am trying to use MEF to Export the following:
[Export(typeof(IRepository<>))]
public class Repository<T> : IRepository<T>
where T : class
{
With an import of
[Import(typeof(IRepository<>))]
private IRepository<Contact> repository;
But I keep getting an error message when composing MEF of:
====================================...
In a Rest Service using the JAX-RS specification, I can define a generic service like
@GET
@Path("something")
@Produces( { MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public List<MyPojo> getMyPojoList() {
...
}
Something magic happens in Jersey because when invoking
javax.ws.rs.ext.MessageBodyWriter#writeTo(T t,
...
I'm looking to 'generalise' some code in a .NET 3.5 MVC application and have stumbled into a problem.
Background
I have a SomeController class with some actions:
public ActionResult Renew(string qualification, int tierId) { ... }
public ActionResult Reinstate(string qualification, int tierId) { ... }
public ActionResult Withdraw(strin...
Hi
I have two objects MetaItems and Items.
MetaItem is template for objects and Items contains actual values. For example "Department" is treated as meta-item and "Sales", "UK Region", "Asia Region" are treated as items.
Additionally I want to maintain parent-child relation on these meta-items and items.
I have following code for s...
Assume I have a table called User. Using LINQ desinger, I will end up with the following:
A file called User.dbml
A data context class called UserDataContext which subclasses from System.Data.Linq.DataContext
A class called User which is mapped from the User table. A UserDataContext object will have a property called Users which is...
As you can see, having a non void return type is important.
class TestValid {
public String f(List<String> list) {
return null;
}
public Integer f(List<Integer> list) {
return null;
}
public void test() {
f(Arrays.asList("asdf"));
f(Arrays.asList(123));
}
}
class TestInvalid {
public void f(List<String> list) {
...
I have the following code:
var commitmentItems = new List<CommitmentItem<ITransaction>>();
commitmentItems.Add(new CapitalCallCommitmentItem());
And I get the following error:
Argument '1': cannot convert from 'Models.CapitalCallCommitmentItem' to
'Models.CommitmentItem<Models.ITransaction>'
However, CapitalCallCommitmentItem ...