Click here to Skip to main content
15,904,023 members
Home / Discussions / C#
   

C#

 
AnswerRe: How to make an android phone does calls to people using vc#.net Pin
OriginalGriff11-Jun-18 23:03
mveOriginalGriff11-Jun-18 23:03 
GeneralRe: How to make an android phone does calls to people using vc#.net Pin
Mohammad Abdullaha12-Jun-18 3:58
Mohammad Abdullaha12-Jun-18 3:58 
GeneralRe: How to make an android phone does calls to people using vc#.net Pin
OriginalGriff12-Jun-18 4:37
mveOriginalGriff12-Jun-18 4:37 
AnswerRe: How to make an android phone does calls to people using vc#.net Pin
Pete O'Hanlon11-Jun-18 23:14
mvePete O'Hanlon11-Jun-18 23:14 
GeneralRe: How to make an android phone does calls to people using vc#.net Pin
Mohammad Abdullaha12-Jun-18 3:53
Mohammad Abdullaha12-Jun-18 3:53 
GeneralRe: How to make an android phone does calls to people using vc#.net Pin
Richard MacCutchan12-Jun-18 9:05
mveRichard MacCutchan12-Jun-18 9:05 
GeneralRe: How to make an android phone does calls to people using vc#.net Pin
Richard Andrew x6412-Jun-18 12:10
professionalRichard Andrew x6412-Jun-18 12:10 
GeneralRe: How to make an android phone does calls to people using vc#.net Pin
Richard MacCutchan12-Jun-18 21:13
mveRichard MacCutchan12-Jun-18 21:13 
GeneralRe: How to make an android phone does calls to people using vc#.net Pin
Pete O'Hanlon12-Jun-18 21:26
mvePete O'Hanlon12-Jun-18 21:26 
GeneralRe: How to make an android phone does calls to people using vc#.net Pin
Mohammad Abdullaha13-Jun-18 5:29
Mohammad Abdullaha13-Jun-18 5:29 
AnswerRe: How to make an android phone does calls to people using vc#.net Pin
Gerry Schmitz13-Jun-18 7:42
mveGerry Schmitz13-Jun-18 7:42 
GeneralRe: How to make an android phone does calls to people using vc#.net Pin
Mohammad Abdullaha13-Jun-18 9:48
Mohammad Abdullaha13-Jun-18 9:48 
GeneralRe: How to make an android phone does calls to people using vc#.net Pin
Gerry Schmitz13-Jun-18 9:58
mveGerry Schmitz13-Jun-18 9:58 
Questionfutronic fs80 fingerprint scanner integrat with c# Pin
Member 1020390311-Jun-18 21:52
Member 1020390311-Jun-18 21:52 
AnswerRe: futronic fs80 fingerprint scanner integrat with c# Pin
Richard MacCutchan11-Jun-18 23:13
mveRichard MacCutchan11-Jun-18 23:13 
QuestionArray bytes convert to json when export pdf through webservice Pin
Nishant.Chauhan8010-Jun-18 21:01
Nishant.Chauhan8010-Jun-18 21:01 
QuestionRe: Array bytes convert to json when export pdf through webservice Pin
Richard MacCutchan10-Jun-18 22:20
mveRichard MacCutchan10-Jun-18 22:20 
AnswerRe: Array bytes convert to json when export pdf through webservice Pin
Nathan Minier11-Jun-18 2:23
professionalNathan Minier11-Jun-18 2:23 
QuestionMultiple Loops Code Optimization Pin
Juanleroux10-Jun-18 16:31
Juanleroux10-Jun-18 16:31 
AnswerRe: Multiple Loops Code Optimization Pin
BillWoodruff10-Jun-18 17:58
professionalBillWoodruff10-Jun-18 17:58 
AnswerRe: Multiple Loops Code Optimization Pin
Luc Pattyn11-Jun-18 3:50
sitebuilderLuc Pattyn11-Jun-18 3:50 
Questionnice to know that a generic parameter of a function constrained to 'struct can .. Pin
BillWoodruff10-Jun-18 5:00
professionalBillWoodruff10-Jun-18 5:00 
What say you, my esteemed mentors and peers ? This is non-news; bad news; worth writing up as tip-trick ?

Use a nullable of that same generic parameter as a return value: I was aware there was some behind the scenes compiler magic with a hidden 'HasValue flag in a nullable 'struct that allowed an instance to be assigned null, but I never thought I could use the non-nullable generic parameter in the way shown here:
/* required
using System;
using System.Collections.Generic;
using System.ComponentModel;
*/
public static class ConversionExtensions
{
    public enum ConversionType
    {
        SByte, Byte, Int16, Int32, Int64,
        UInt32, UInt64, Single, Double,
        Guid
    }

    static Dictionary<Type, TypeConverter> TypeToConverter = null;

    public static T? TryParse<T>(this string str) where T : struct
    {
        if (TypeToConverter == null)
        {
            TypeToConverter = new Dictionary<Type, TypeConverter>();

            foreach (string ct in Enum.GetNames(typeof(ConversionType)))
            {
                var t = Type.GetType("System." + ct);

                TypeToConverter.Add(t, TypeDescriptor.GetConverter(t));
            }
        }

        Type type = typeof(T);

        // using C# 7 syntax for in-line out variable
        if (TypeToConverter.TryGetValue(type, out TypeConverter tc))
        {
// tbd: use 'TypeConverter.CanConvertFrom here rather than try/catch
            try
            {
                return (T) tc.ConvertFromString(str);
            }
            catch
            {
                return null;
            }
        }
        else
        {
            throw new KeyNotFoundException($"this converter does not handle Type: {type.FullName}");
        }

        return null;
    }
}

«... thank the gods that they have made you superior to those events which they have not placed within your own control, rendered you accountable for that only which is within you own control For what, then, have they made you responsible? For that which is alone in your own power—a right use of things as they appear.» Discourses of Epictetus Book I:12


modified 10-Jun-18 12:33pm.

AnswerRe: nice to know that a generic parameter of a function constrained to 'struct can .. Pin
Nathan Minier11-Jun-18 2:31
professionalNathan Minier11-Jun-18 2:31 
GeneralRe: nice to know that a generic parameter of a function constrained to 'struct can .. Pin
BillWoodruff11-Jun-18 5:33
professionalBillWoodruff11-Jun-18 5:33 
GeneralRe: nice to know that a generic parameter of a function constrained to 'struct can .. Pin
Nathan Minier13-Jun-18 8:21
professionalNathan Minier13-Jun-18 8:21 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.