Returning different data types C#

Posted by user1810659 on Stack Overflow See other posts from Stack Overflow or by user1810659
Published on 2012-11-22T22:57:25Z Indexed on 2012/11/22 22:59 UTC
Read the original article Hit count: 170

Filed under:
|
|
|
|

i have create a class library (DLL) with many different methods. and the return different types of data(string string[] double double[]). Therefore i have created one class i called CustomDataType for all the methods containing different data types so each method in the Library can return object of the custom class and this way be able to return multiple data types I have done it like this:

public  class CustomDataType
{
    public double Value;
    public string Timestamp;
    public string Description;
    public string Unit;

   // special for GetparamterInfo
    public string OpcItemUrl;
    public string Source;
    public double Gain;
    public double Offset;
    public string ParameterName;
    public int ParameterID;

    public double[] arrayOfValue;
    public string[] arrayOfTimestamp;

    //
    public string[] arrayOfParameterName;
    public string[] arrayOfUnit;
    public string[] arrayOfDescription;
    public int[]    arrayOfParameterID;
    public string[] arrayOfItemUrl;
    public string[] arrayOfSource;
    public string[] arrayOfModBusRegister;
    public string[] arrayOfGain;
    public string[] arrayOfOffset;

}

The Library contains methods like these:

public CustomDataType GetDeviceParameters(string deviceName)
    {
        ......................
        code



      getDeviceParametersObj.arrayOfParameterName;  

      return getDeviceParametersObj;

    }

    public CustomDataType GetMaxMin(string parameterName, string period, string maxMin)
    {
        .....................................code



                        getMaxMingObj.Value             =   (double)reader["MaxMinValue"];
                        getMaxMingObj.Timestamp         =   reader["MeasurementDateTime"].ToString();
                        getMaxMingObj.Unit              =   reader["Unit"].ToString();
                        getMaxMingObj.Description       =   reader["Description"].ToString(); 

        return getMaxMingObj;
    }

    public CustomDataType GetSelectedMaxMinData(string[] parameterName, string period, string mode)
    {................................code

        selectedMaxMinObj.arrayOfValue          =   MaxMinvalueList.ToArray();
        selectedMaxMinObj.arrayOfTimestamp      =   MaxMintimeStampList.ToArray();
        selectedMaxMinObj.arrayOfDescription    =   MaxMindescriptionList.ToArray();
        selectedMaxMinObj.arrayOfUnit           =   MaxMinunitList.ToArray();
        return selectedMaxMinObj;

    }

As illustrated thi different methods returns different data types,and it works fine for me but when i import the DLL and want to use the methods Visual studio shwos all the data types in the CustomDataType class as suggestion for all the methods even though the return different data.This is illusrtated in the picture below. As we can see from the picture with the suggestion of all the different return data the user can get confused and choose wrong return data for some of the methods. So my question is how can i improve this. so Visual studio suggest just the belonging return data type for each method.

enter image description here

© Stack Overflow or respective owner

Related posts about c#

Related posts about c++