Given Type a and Type b, how can I, at runtime, determine whether there's an implicit conversion from a to b?
If that doesn't make sense, consider the following method:
public PropertyInfo GetCompatibleProperty<T>(object instance, string propertyName)
{
var property = instance.GetType().GetProperty(propertyName);
bool isCompatib...
Pretty simple question I need to get an integer from the user and I only know how to get a string from them. So if there is a way to get an integer from the user or to convert the string to an integer please let me know.
...
Given the following XML:
<table>
<col width="12pt"/>
<col width="24pt"/>
<col width="12pt"/>
<col width="48pt"/>
</table>
How can I convert the width attributes to numeric values that can be used in mathematical expressions? So far, I have used substring-before to do this. Here is an example template (XSLT 2.0 only) that shows...
I have a Set in Scala (I can choose any implementation as I am creating the Set. The Java library I am using is expecting a java.util.Set[String].
Is the following the correct way to do this in Scala (using scala.collection.jcl.HashSet#underlying):
import com.javalibrary.Animals
var classes = new scala.collection.jcl.HashSet[String]
c...
I am sure I am missing something simple, however I am trying to convert a strongly typed list of objects that all implement an interface in to a list of that interface type.
Below is a sample to demonstrate the error:
public void ExampleCode(){
List<Cube> cubes = new List<Cube>();
List<Shape> allShapes;
allShapes = cubes;/...
Hey guys, I have a table of guesses, within each guess is just a date. I was wondering how I would go about turning two or more dates into an average.
<div id="logic">
<% foo = Date.today %>
<% bar = Date.today + 10 %>
<%= (foo + bar) / 2 %>
Something like this, but obviously Ruby wont let me divide the two dates, any help much appr...
Hi.
typedef void (__thiscall* LPVOIDPROC) (void);
class ClassA
{
LPVOIDPROC m_pProc;
void SetProc(LPVOIDPROC pProc) { m_pProc = pProc; }
void OnSomeEvent() { m_pProc(); }
}
class ClassB
{
ClassA* pCA;
void Proc() { /* ... */ }
void Init()
{
// Assume pCA != NULL
pCA->Set((LPVOIDPROC)&ClassB::Proc); // error ...
How can operator bool() cause an error when declaring operator std::string in a class and also serving as an implicit conversion to string by itself?
#include <iostream>
#include <string>
using namespace std;
class Test {
public:
operator std::string() { cout << "op string" << endl; return "whatever";}
operator bool() { cout <<...
I need to convert array of Objects into a Long/Integer.. Problem is that those Objects are sometimes BigIntegers, sometimes BigDecimals and sometimes even something else. Is there any good libraries for accomplishing this?
for example...
for (Object[] o : result) {
Long l = SomeClass.convertToLong(o[0]);
Integer i = SomeClass.c...
Hi,
I have a case where I should get the elements from an array and I do not know if the type is double or integer.
[array objectAtIndex:2]
and the problem is that I can not identify the type. If i knew the type I simply would perform:
[[item objectAtIndex:2] intValue] or
[[item objectAtIndex:2] doubleValue]
Is there any way to detect...
I know the type of object (let's say IAnimal) I need to instantiate, and the name (lets say Tiger). How do I write the code to instantiate Tiger, given that the variable that knows the object name is a string. I'm likely missing something simple here, but am currently stuck on this.
Update: I meant Class Tiger : IAnimal, changed abov...
I have a table with a column of type varchar where the majority of rows have numerical looking values, that is, each string contains nothing but the digits 0 through 9.
+------+
| n |
+------+
| 123 |
| 234 |
| BLAH | -- This row is an exception to the rule.
| 456 |
| 789 |
+------+
In MySQL, this works: SELECT * FROM t WHERE n...
the Text property of control on winform is always string type, so if i wanna expose property of other type for custom control, i have to do the conversion as following, if i have dozens of properties to expose, it will be such pain for me.
public int ImageGroupLength
{
get
{
return int.Parse(this.image...
I am trying to get a difference between the type casting methods.
eg.
Method 1
public byte fun()
{
object value=1;
return (byte)value; // this gives me error
}
Method 2
public byte fun()
{
object value=1;
return byte.Parse(value.ToString()); // this runs
}
Method 3
public byte fun()
{
object value=1;
return Co...
Hi,
I'm using PropertyGrid control for editing some objects in my application. I'm using custom TypeConverters and TypeEditors for better user interface.
I have problem with custom TypeConverter for boolean properties. If I have this class:
public class MyClass {
public string Name { get; set; }
[System.ComponentModel.TypeCon...
I'm trying to create a class that will allow me to add/multiply/divide objects of the same class together or add/multiply numeric arguments to each member of the class
So my class is for coordinates (I am aware there are great packages out there that do everything I want better than I could ever hope to on my own, but now I'm just curio...
I have a Type, a String and an Object.
Is there some way I can call the parse method or convert for that type on the string dynamically?
Basically how do I remove the if statements in this logic
object value = new object();
String myString = "something";
Type propType = p.PropertyType;
if(propType == Type.GetType("DateTime"))
{
...
I am using ASP.NET MVC2 and Entity Framework. I am going to simplify the situation a little; hopefully it will make it clearer, not more confusing!
I have a controller action to create address, and the country is a lookup table (in other words, there is a one-to-many relationship between Country and Address classes). Let's say for clari...
Is there a way to do automatic implicit type conversion in Java? For example, say I have two types, 'FooSet' and 'BarSet' which both are representations of a Set. It is easy to convert between the types, such that I have written two utility methods:
/** Given a BarSet, returns a FooSet */
public FooSet barTOfoo(BarSet input) { /* ... */...
I am getting a string from the user and then doing some checking to make sure it is valid, here is the code I have been using;
char digit= userInput.charAt(0) - '0';
This had been working fine until I did some work on another method, I went to compile and have been receiving a 'possible loss of precision' error since then.
What am I ...