I just noticed that you can do this in C#:
Unit myUnit = 5;
instead of having to do this:
Unit myUnit = new Unit(5);
Does anyone know how I can achieve this with my own structs? I had a look at the Unit struct with reflector and noticed the TypeConverter attribute was being used, but after I created a custom TypeConverter for my st...
I want to pass an int list (List) as a declarative property to a web user control like this:
<UC:MyControl runat="server" ModuleIds="1,2,3" />
I created a TypeConverter to do this:
public class IntListConverter : System.ComponentModel.TypeConverter
{
public override bool CanConvertFrom(
System.ComponentModel.ITypeDescr...
I often have to convert a retreived value (usually as a string) - and then convert it to an int. But in C# (.Net) you have to choose either int16, int32 or int64 - how do you know which one to choose when you don't know how big your retrieved number will be?
...
I'm using Windows Forms and VS2008. I want to store an enum value in my application's settings file.
The settings editor in VS2008 only gives me a limited set of types. Amazingly, enums don't seem to be one of these types that are automatically supported - have I understood this correctly?
From reading up on the subject, it seems lik...
It seems to me its very easy to implement an implicit operator versus a TypeConverter, so I'm assuming they aren't equivalent because of the prevalence of TypeConverters in the framework (see anything that extends FrameworkElement).
But why? Wouldn't it have been much easier to create string->object and object->string implicit operator...
For some reason I need to cast/convert a DateTime into one of many custom objects
This proves to be very difficult to do in a nice generic fashion.
I am thinking of implementing an extension method on object or perhaps extending DateTimeConverter.
But then what would be the generic way to handle this, I have an object and a destinatio...
The DateTimeConverter class provides conversions between DateTime and string. I would also like to support conversions between DateTime and double.
According to MSDN I can extend the DateTimeConverter class to do this - see MSDN DateTimeConverter
I have created a class that inherits from DateTimeConverter and provides the appropriate o...
I have a custom c# type like (just an example):
public class MyVector
{
public double X {get; set;}
public double Y {get; set;}
public double Z {get; set;}
//...
}
And I want it to databind to TextBox.Text:
TextBox textBox;
public MyVector MyVectorProperty { get; set;}
//...
textBox.DataBindings.Add("Text", this, "MyV...
Hello,
i have three double variable a ,b and c
a = 0.000006
b = 6
c = a/b;
so C should be 0.000001
i want to show this value in text box so i wrote
textbox.text = c.tostring();
but it's give result as "1E-06"..
Can anybody help me out how can i put correct value in textbox ?
Thanks
...
I received an NSMutableData from a server and now I want to convert it to an NSString. Any ideas about how to do this?
...
Exception:
Cannot convert the value in attribute 'Text' to object of type
'System.String'. Unable to cast object
of type 'MyApp.Foo' to type
'System.String'.
XAML:
<Window.Resources>
<my:Foo x:Key="foo"></my:Foo>
</Window.Resources>
<TextBox Text="{DynamicResource foo}"></TextBox>
C#
[TypeConverter(typeof(FooConverter)...
I'm trying to get an overall understanding of how you use ICustomTypeDescriptor, TypeDescriptionProvider, TypeConverter, and UITypeEditor to change how a PropertyGrid displays and interfaces with an object.
Can someone tell me if this is right, or if I missed any major concepts or points? I'm really just trying to understand why and whe...
I've applied a TypeConverterAttribute attribute to a property on my WPF FrameworkElement subclass. The property is of type BitmapSource.
But the TypeConverter is never created or called. Is this because the TypeConverter specified on ImageSource takes precedence?
I'm trying to debug a data binding problem. The error message, never make...
I would like to bind any XML document to WPF TreeView using TypeConverter.
My original solution was to use recursion, but when document is large UI is heavily tied up.
Following link talks about TypeConverter but for particular node/element combination:
http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/edd843b7-b378-4c2d-926f-c0...
Hi guys,
I need to convert a long value from int64 to NSData, so I can later run a hash algorithm on it. I perform:
int64_t longNumber = 9000000000000000000L;
NSMutableData *buffer = [NSMutableData dataWithBytes:&longNumber length:sizeof(longNumber)];
NSLog(@"%lld", [buffer bytes]);
NSLog(@"%lld", longNumber);
The resultant console ...
I'm trying to understand how to use Type Converters after reading this answer to one of my other questions. But I'm not sure if I quite get it...
In my particular case I would like to "convert" an enum member into a localized string by getting a resource string depending on what enum member it is. So for example if I had this enum:
pub...
I'm restating this problem to summarise what I've already found:
I have a test TypeConverter, (MyConverter), that for a ConvertToString will output "Converted To String", no matter what the input.
To ensure this is picked up by GetConverter for Int32, I add the following line:
(1) Dim tcp As TypeDescriptionProvider = TypeDescriptor.Ad...
Hi,
I created a custom type converter to create a class from a string. It works when I do this:
<constructor-arg type="MyType" value="value_to_convert"/>
but I also want to do something like this:
<list element-type="MyType">
<object type="MyType" value="value_to_convert1"/>
<object type="MyType" value="value_to_convert2"/>
...
I'm fairly new to C# and .NET - I'm trying to get conversion to work from an integer to an enum. The conversion must be performable by ChangeType (outside of my demo below this is fixed as it's within the data binding framework) and from what I've read it should work with what I'm doing, but I get an exception and if I place breakpoints...
I have a class, Questionnaire, which contains a collection class that wraps a generic list, EntityCollection. I am using ViewState to persist the Questionnaire and its collection of Questions. I am using custom type converters to reduce the ViewState size. Everything works without a type converter for EntityCollection. Would things wo...