Is there a way to force-cast between different types of different assemblies? I need to execute a function, whose assembly has been loaded with Assembly.Load(ReadAllBytes(...)), but it fails in argument casting. So, is there any way to "reinterpret_cast" objects in c#?
EDIT
Most basic example of my casting problem is:
Assembly ass = A...
Hi Folks
Is it possible to check an elements ComplexType?
i have this (simplified):
complexType Record
complexType Customer extension of Record
complexType Person extension of Record
<xsl:template match="/">
<records>
<xsl:apply-templates />
</records>
</xsl:template>
<xsl:template match="!!! TYPECHECK FOR RECORD !!!" ...
Update: I have filed a bug report with Microsoft Connect, please vote for it!
Update 2: Microsoft have marked the bug report as fixed
Posted by Microsoft on 18/08/2010 at 17:25
This bug will be fixed in a
future version of the runtime. I'm
afraid it's too early to tell if that
will be in a service pack or the next
major...
To convert between some LINQ to SQL objects and DTOs we have created explicit cast operators on the DTOs. That way we can do the following:
DTOType MyDTO = (LinqToSQLType)MyLinq2SQLObj;
This works well.
However when you try to cast using the LINQ .Cast() extension method it trows an invalid cast exception saying cannot cast type Lin...
Hello all,
in Redis (http://code.google.com/p/redis) there are scores associated to elements, in order to take this elements sorted. This scores are doubles, even if many users actually sort by integers (for instance unix times).
When the database is saved we need to write this doubles ok disk. This is what is used currently:
snprin...
I want to do it:
int main () {
bla bla bla
void *onetype;
switch (USER_INPUT_TYPE) {
CASE CONVERT_TO_CHAR:
convert onetype VOID TO CHAR >>> HOW???
CASE CONVERT_TO_INT:
convert onetype VOID TO INT >>> HOW???
LOT OF CASES...
}
}
Yes, I know type casting, but type casting is a 'temporary'...
I'm using a function I found here to save a webpage to memory with cURL:
struct WebpageData {
char *pageData;
size_t size;
};
size_t storePage(void *input, size_t size, size_t nmemb, void *output) {
size_t realsize = size * nmemb;
struct WebpageData *page = (struct WebpageData *)output;
page->pageData = (char *)re...
I want to do a select that do a cast only for a specific ID but it doesn't seems to work.
Example :
SELECT
CASE
WHEN(@ID <> 1) THEN Code
WHEN(@ID = 1) THEN Cast(Code AS int)
END Code FROM ....
Any Idea ?
...
Hi,
Lets say I have the following class:
class BritneySpears
{
public:
int getValue() { return m_value; };
private:
int m_value;
};
Which is an external library (that I can't change). I obviously can't change the value of m_value, only read it. Even subclassing BritneySpears won't work.
What if I define the following ...
i was wondering if the solution for this documented here is still the solution or is there any other way getting an int from 4 bytes?
thank you.
EDIT: im getting the byte[] from sockets .read
EDIT: int recvMsgSize = in.read(Data, 0, BufferSize); if recvMsgSize is -1 i know the connection has been dropped.
how do i detect this when im...
After another question about iterators I'm having some doubts about custom containers. In my container, iterator is a subclass of const_iterator, so that I get conversion from non-const to const "for free". But is this allowed or are there any drawbacks or non-working scenarios for such a setup?
...
I recently began to start using functions to make casting easier on my fingers for one instance I had something like this
((Dictionary<string,string>)value).Add(foo);
and converted it to a tiny little helper function so I can do this
ToDictionary(value).Add(foo);
Is this a code smell?
Also, what about simpler examples? For example...
I have programed an application on windows XP and in Visual Studio with c++ language.
In that app I used LoadResource() API to load a resource for giving a file in the resource memory.
It returned a pointer of memory block and I wanna cast the pointer to the std stream to use for compatibility.
Could anyone help me?
...
I have an nHibernate query using Criteria, and I am trying to cast a string to bool in the query itself. I have done the same with casting a string to int, and that works well (the "DataField" property is "1" as a string):
var result = Session
.CreateCriteria<Car>()
.Add(Restrictions.Eq((Projections.Cast(NHibernateUtil.Int32,
...
I was reading a question on making a generic property, but I'm a little confused by the last example from the first answer (I've included the relevant code below):
You have to know the type at compile
time. If you don't know the type at
compile time then you must be storing
it in an object, in which case you can
add the follo...
You would think there would be a way using DirectCast, TryCast, CType etc but all of them seem to choke on it e.g.:
CType("Yes", Boolean)
You get:
System.InvalidCastException -
Conversion from string "Yes" to type
'Boolean' is not valid.
...
I'm having some trouble to do the following:
int[] tmpIntList = (int[])MyArrayList.toArray(someValue);
MyArrayList contains only numbers. I get a typecast error since ArrayList only returns Object[] but why isnt it possible to turn it into a int[] ?
...
I'm trying to do cast a List to an IEnumerable, so I can verify that different lists are not null or empty:
Suppose myList is a List < T > . Then in the caller code I wanted:
Validator.VerifyNotNullOrEmpty(myList as IEnumerable<object>,
@"myList",
@"Clas...
so when casting like in the statement below :-
int randomNumber=(int) (Math.random()*5)
it causes the random no. generated to get converted into an int..
Also there's this method I just came across Integer.parseInt() which does the same !
i.e return an integer
Why two different ways to make a value an int ?
Also I made a search an...
I have a c function being called from python. Python gives the function an integer, but I would like to use it as another data type in C. I am currently using
PyArg_ParseTuple (args, "i", &value) and then manually doing a cast on value.
Is there a way to do this cast through PyArg?
...