explicit-conversion

Extension method and Explicit casting

丶灬走出姿态 提交于 2020-01-02 02:04:58
问题 I'm using class from some assembly(source code is not available), so it is not possible to change their's code I need to add extension method for explicit cast operator, is there any way to achieve that? (I have tried to add as regular extension method, but without success) public static explicit operator MembershipUser(this MembershipUser membership, User user) { return new MembershipUser("SimplyMembershipProvider", user.UserName, user.UserId, user.Email, null, null, user.IsApproved, user

Extension method and Explicit casting

不羁的心 提交于 2020-01-02 02:03:02
问题 I'm using class from some assembly(source code is not available), so it is not possible to change their's code I need to add extension method for explicit cast operator, is there any way to achieve that? (I have tried to add as regular extension method, but without success) public static explicit operator MembershipUser(this MembershipUser membership, User user) { return new MembershipUser("SimplyMembershipProvider", user.UserName, user.UserId, user.Email, null, null, user.IsApproved, user

Generic conversion operator templates and move semantics: any universal solution?

独自空忆成欢 提交于 2019-12-21 03:35:14
问题 This is a follow-up of Explicit ref-qualified conversion operator templates in action. I have experimented with many different options and I am giving some results here in an attempt to see if there is any solution eventually. Say a class (e.g. any) needs to provide conversion to any possible type in a convenient, safe (no surprises) way that preserves move semantics. I can think of four different ways. struct A { // explicit conversion operators (nice, safe?) template<typename T> explicit

mysql datetime comparison

本小妞迷上赌 提交于 2019-12-18 10:25:06
问题 For example the following query works fine: SELECT * FROM quotes WHERE expires_at <= '2010-10-15 10:00:00'; But this is obviously performing a 'string' comparison - I was wondering if there was a function built in to MySQL that specifically does 'datetime' comparisons. 回答1: ...this is obviously performing a 'string' comparison No - if the date/time format matches the supported format, MySQL performs implicit conversion to convert the value to a DATETIME, based on the column it is being

Why can't coexist implicit and explicit operator of the same type in C#? [duplicate]

只愿长相守 提交于 2019-12-10 16:41:41
问题 This question already has answers here : Why can't I define both implicit and explicit operators? (2 answers) Closed 2 years ago . Why can not coexist in the same class two operators (explicit and implicit) of the same type? Suppose I have the following: public class Fahrenheit { public float Degrees { get; set; } public Fahrenheit(float degrees) { Degrees = degrees; } public static explicit operator Celsius(Fahrenheit f) { return new Celsius(ToCelsius(f.Degrees)); } public static implicit

Float To Integer Casting?

做~自己de王妃 提交于 2019-12-08 11:37:32
问题 I know that floating point cannot represent every number exactly so some error is bound to happen. But recently I have encountered a problem and I am not getting the explanation right. Please explain me step by step how the conversion affected the output. How did truncating decimal places give me the wrong answer? #include<stdio.h> #include<stdlib.h> #include<math.h> int main() { int x; int y = 0; int n = 0; printf("Enter The Number You Want To Octal Equivalent Of : "); scanf("%d",&x); while

isSet() or operator void*() or explicit opertor bool() or something else?

拜拜、爱过 提交于 2019-12-06 23:53:45
问题 What is the state of the art about functions to check whether a value is set or not ? For example, the below iterator parses cells. Some cells contain a value, other cells are empty. What is the most convenient way? struct iterator { //usage: bool isset() const // if (it.isset()) bool isSet() const // if (it.isSet()) bool empty() const // if (it.empty()) bool is_set() const // if (it.is_set()) bool is_valid() const // if (it.is_valid()) operator void*() const; // if (it) explicit operator

isSet() or operator void*() or explicit opertor bool() or something else?

↘锁芯ラ 提交于 2019-12-05 04:08:23
What is the state of the art about functions to check whether a value is set or not ? For example, the below iterator parses cells. Some cells contain a value, other cells are empty. What is the most convenient way? struct iterator { //usage: bool isset() const // if (it.isset()) bool isSet() const // if (it.isSet()) bool empty() const // if (it.empty()) bool is_set() const // if (it.is_set()) bool is_valid() const // if (it.is_valid()) operator void*() const; // if (it) explicit operator bool() const; // if ((bool)it) or if(it) //thanks @stijn operator bool() const; // if (it) //why not

Extension method and Explicit casting

六月ゝ 毕业季﹏ 提交于 2019-12-05 03:23:54
I'm using class from some assembly(source code is not available), so it is not possible to change their's code I need to add extension method for explicit cast operator, is there any way to achieve that? (I have tried to add as regular extension method, but without success) public static explicit operator MembershipUser(this MembershipUser membership, User user) { return new MembershipUser("SimplyMembershipProvider", user.UserName, user.UserId, user.Email, null, null, user.IsApproved, user.IsLocked, user.CreateDate, user.LastLoginDate, user.LastActivityDate, user.CreateDate, DateTime.MinValue)

How do I perform explicit operation casting from reflection?

自古美人都是妖i 提交于 2019-12-05 02:18:38
I want to use reflection and do either an implicit or explicit coversion using reflection. Given I have defined Foo this way public class Foo { public static explicit operator decimal(Foo foo) { return foo.Value; } public static explicit operator Foo(decimal number) { return new Foo(number); } public Foo() { } public Foo(decimal number) { Value = number; } public decimal Value { get; set; } public override string ToString() { return Value.ToString(); } } When I run this code decimal someNumber = 42.42m; var test = (Foo)someNumber; Console.WriteLine(test); // Writes 42.42 No problems When I try