473,699 Members | 2,912 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Generics, Type and typeof()

hi @all,

I have the following interface declaration:

public interface IBaseDao<Twhere T : BasePOJO
List<TFindAll(T ype entityClass);

The parameter entityClass should be typeof(T).

I thought of something like

List<TFindAll(T ype<TentityClas s);

but there is not such a generic for Type.

So, is this possible?
--stefan <--
Sep 11 '08 #1
3 2075
Can you clarify what it is you want to do? I can interpret that a few
different ways...

Perhaps if you indicate how you want to call it and what you want to happen?

Sep 11 '08 #2
I agree with the first commenter that it's hard to understand what
you're trying to do.

Given what you've said, one possible interpretation says maybe this
would be what you're looking for:

public interface IBaseDao<Twhere T : BasePOJO
List<TFindAll(T entityClass);

Is that it, or do we just need more information?


On Sep 11, 8:05*am, Stefan Hoffmann <stefan.hoffm.. .@explido.de>
hi @all,

I have the following interface declaration:

* * *public interface IBaseDao<Twhere T : BasePOJO
* * *{
* * * * *List<TFindAll( Type entityClass);
* * *}

The parameter entityClass should be typeof(T).

I thought of something like

* * *List<TFindAll( Type<TentityCla ss);

but there is not such a generic for Type.

So, is this possible?

--stefan <--
Sep 11 '08 #3
hi Marc, Kyle,

I should have give you my actual case:

I'm trying to convert an interface from Jave to C#. In Jave it looks
like this:

public interface IBaseDAO<T extends BasePOJO>
List<TfindAll(C lass<TentityCla ss);

I found an Java guy, who explained it: it's basically a hack, as the
implementation looks like:

public List<TfindAll(C lass<TentityCla ss)
List<Tresults = getHibernateTem plate().loadAll (entityClass);
return results;

It seems that they can't use

public List<TfindAll()
return GetHibernateTem plate().LoadAll (typeof(T));

as we can do in C#.

Thanks for your efforts.
--stefan <--
Sep 11 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

by: Tom Jastrzebski | last post by:
Hello everybody, Here is the problem I came across experimenting with Generics. I would like to write a class or a struct adding integer to any other, initially undefined *numeric type*. So, my struct would look more or less like: struct MySum<T> where T : struct { public static T AddInteger(T value, int i) { return value + i;
by: Luc Vaillant | last post by:
I need to initialise a typed parameter depending of its type in a generic class. I have tried to use the C++ template form as follow, but it doesn't work. It seems to be a limitation of generics vs C++ templates. Does anyone knows a workaround to do this ? Thx : public class C<T> { private T myValue;
by: Cedric Rogers | last post by:
I wasn't sure if I could do this. I believe I am stretching the capability of what generics can do for me but here goes. I have a generic delegate defined as public delegate bool RuleDelegate<T>(T item); In my class my goal is to use a generic list collection to contain my generic delegates. This will allow me to pass this List to another library and call this list of functions. This could provide a new way to build rule base...
by: Wiktor Zychla [C# MVP] | last post by:
suppose I have a class class MyContainter { List<something1list1; List<something2list2; ... List<somethingnlistn; othertype1 otherfield1; ...
by: LongBow | last post by:
Hello all, First of all, sorry for multiple question per one thread. I have two questions. First what I think might be the easier problem. I am capturing data from an embedded device which I need to display data. One particular piece of data is a 32 bit floating point value. The problem I am having is converting the 4-byte value which is read via an RS-232 link. How can I cast the 4-byte value to a value type float correctly? I have...
by: Bryan Kyle | last post by:
Hi All, I'm fairly new to C# and Generics and I'm wondering if anyone has some suggestions for me. I'm trying to implement a simple DAO framework using generics to keep my code as clean as I can, however I'm getting an error with what seems to me to be correct code. The error I'm getting is: Error 1 Cannot implicitly convert type 'Sample.PersonDao' to
by: Marc Gravell | last post by:
Given a generic method "of T", is there a good way of ensuring that any static ctor on T has executed? Following code demonstrates (TestClass1) that via generics you can use the Type instance long before the static ctor fires. With a generic class and the "new()" clause, I can force this in the static ctor of the generic class, but this is not always convenient, plus may (possibly?) be seen as a no-op . Sample; ideally I'd get "Static...
by: Random | last post by:
I want to define a generics method so the user can determine what type they expect returned from the method. By examining the generics argument, I would determine the operation that needs to be performed and do just that. However, out of the two possible ways of doing this, neither seems to work. I thought I could either... 1) overload the method just based on the generics argument Public Function GetData (Of T As SqlDataReader)...
by: =?Utf-8?B?SGF5U2VlZA==?= | last post by:
Is there some way to use Generics in dynamic code using the Type.GetType("MyClassName") as an argument? List<Type.GetType("MyClassName") oList = new List<Type.GetType("MyClassName") > .... or is there a way to declare a generic using strings that hold class
by: =?Utf-8?B?QnJpYW4=?= | last post by:
What is the easiest way to convert primitives to a byte array? I tried the BinaryFormatter serialization but it serializes objects so when I serialized an and int it took 54 bytes instead of 4. I tried something like the following but it won't compile (I admit I use generics a lot but haven't written many so this may be way off): class X<T> { public byte ToByteArray(T val) {
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, weíll explore What is ONU, What Is Router, ONU & Routerís main usage, and What is the difference between ONU and Router. Letís take a closer look ! Part I. Meaning of...
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.