casting

casting from response to vector object

How can i cast a response object to a vector object?? if this is not possible what shud i do? ...

Simulating C#'s sbyte (8 bit signed integer) casting in Python

In C#, I can cast things to 8bit signed ints like so: (sbyte)arg1; which when arg1 = 2, the cast returns 2 also. However, obviously casting 128 will return -128. More specifically casting 251 will return -5. What's the best way to emulate this behavior? Edit: Found a duplicate question: http://stackoverflow.com/questions/385572/need...

Casting objects created in LINQ to SQL to a single master object.

I have an interesting problem to solve that would be helped by successfully casting objects created by LINQ to SQL into a single master object that I could pass around. Here is the scenario at a high level. I have a number of stored procedures that fetch data and then all return the exact same columns. The params into the procs and th...

C++: Cast to an interface that is not part of the base class

I have a series of classes representing "smart" map elements: MapTextElement, MapIconElement, etc. The classes are extending various Qt graphics item classes, but also provide common functionality, such as an abstract factory method that returns a property panel specialized for each class. I have declared these common methods in a pure v...

Concatenate arrays of subclasses of the same superclass in MATLAB

I have the following structure in matlab superClass < handle subClassA < superClass subClassB < superClass say I have a vector A of subClassA and a vector B of subClassB. I would like to combine them like this: superVector = [A B]; but Matlab doesn't like this. What's the proper way to cast the subclass back to the superclass...

How to convert MSMQ message body into byte[]?

In my C# application I receive MSMQ messages. Sometimes the message body is XML which I can handle without any problems. Sometimes the message could be of any data type so I just need to put it into a database table. To do this I need to take the message body and convert it in a “byte[]” type. My question is, how to convert the message b...

c# enum and performance

My app has a lot of different lookup values, these values don't ever change, e.g. US States. Rather than putting them into database tables, I'd like to use enums. But, I do realize doing it this way involves having a few enums and a lot of casting from "int" and "string" to and from my enums. Alternative, I see someone mentioned using...

Why are the unsigned CLR types so difficult to use in C#?

I came from a mostly C/C++ background before I began using C#. One of the things I did with my first project in C# was make a class like this class Element{ public uint Size; public ulong BigThing; } I was then mortified by the fact that this requires casting: int x=MyElement.Size; as does int x=5; uint total=MyElement.Size+x;...

NotSupportedException at unboxing SQLite Int64 field with Entity Framework 4

Querying with Entity Framework 4 with a SQLite (v3) database through the sqlite.phxsoftware.com ADO.NET provider (v1.0.66.0), I'm facing the following NotSupportedException while casting the retrieved Int64 properties: Unable to cast the type 'System.Int64' to type 'System.Object'. LINQ to Entities only supports casting Entity Data Mode...

iteration + casting in go

i have this snippet of code that use an iterator on a list for x:= range s.faces.Iter(){ x.Render() } as the compiler points, x is of type interface{} and there isn't a method (i interface)Render() defined in my code. changing to for x:= range s.faces.Iter(){ x.(faceTri).Render() } compile, because there is a method func ...

generics question

I get a warning about unchecked casts on the "return (T) value;" line. Is there a better way to do this, or should I just suppress the warning? class SomeClass<T> { /* ... other methods ... */ private Set<T> aSet; public T filter(Object value) { if (this.aSet.contains(value)) return (T) value; ...

Can "signed char" and "unsigned char" always be cast to each other without loss of data?

In C++ we can have signed char and unsigned char that are of same size but hold different ranges of values. In the following code: signed char signedChar = -10; unsigned char unsignedChar = static_cast<unsigned char>( signedChar ); signedChar = static_cast<signed char>( unsignedChar ); will signed char retain its value regardless of ...

How to cast object to ISingleResult<T> where T is interface C# 3.0

Hello. In my program I have a function which returns object. I know that this object is ISingleResult<T> where T is unknown, but it implements an interface IFoo. How do I cast this object to ISingleResult<IFoo> using C# 3.0? Thank you for your help! ...

VB.Net cast of 2 custom types

Hi! Sorry if this question is very very basic. I need to cast, in the better way, 2 objects of 2 types of 2 custom-classes (in VB.Net): The code: Public Class pluto Public Sub New(ByVal campoPippoPass As String) _campoPippo = campoPippoPass End Sub Private _campoPippo As String = "" Public Property campoPippo...

Topshelf exception

Hello, I'm using topshelf and I'm getting this exception when I try to use the "-i" option to install as a service...please help me.. Unable to cast object of type 'Magnum.CommandLineParser.SwitchElement' to type 'Magnum.CommandLineParser.IArgumentElement'. Exception occurs in this function static void Set(TopshelfArguments args, I...

how to write a cast-to-reference-to-array operator for a class?

I have following class: template <size_t size> class Araye{ public: Araye(int input[]){ for (int i=0;i<size;i++) araye[i]=input[i]; } int araye[size]; }; How should I write a cast-to-reference-to-array operator for this class so that following works: int adad[3]={1,2,3}; Araye<3> araye(adad); int (&reference)[3]=araye; ...

Why cast to Closeable first?

While reading some Java source, I came across this line: ((Closeable) some_obj).close(); some_obj is obviously an instance of a class which implements the Closeable interface. My question is, why do they first cast some_obj to Closeable before invoking close(). Couldn't I just do some_obj.close(); ...

How to cast a type of same class but out of an other package in Java?

There are two classes foo.bar.FileUploader and barbar.foofoo.FileUploader Both are identical and extend Uploader Somewhere in the code the foo.bar.FileUploader is used and are given as a parameter to my function as an Uploader type. Now I need to cast it back to FileUploader but the barbar.foofoo.FileUploader. And this gives an error...

C# cast to interface with List and GroupBy

I'm a bit stumped about how to perform the necessary cast in the following: public IList<IMyClass> Foo() { IList<IMyClass> foo = SomeQuery(); var result = foo.GroupBy(x => x.bar).Select(x => new MyClass()).ToList(); // So now I have a List<MyClass> which needs casting as IList<IMyClass> return result; } using an ex...

Any real example of reinterpret_cast changing a pointer value?

According to C++ Standard, a reinterpret_cast of a pointer T* to some other type pointer Q* can change or not change the pointer value depending on implementation. I'm very interested - it there any real example of a C++ implementation where casting a pointer to some other pointer type with reinterpret_cast changes the pointer? What and...