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.
I want to create the regular expression in javascript which will check the valid conditional string like
-1 OR (1 AND 2) AND 1
-1 OR (1 AND 2)
-1 OR 2
-1 OR 1 OR 1
-1 AND 1 AND 1
The string should not contain 'AND' and 'OR'.
For example - 1 OR 2 AND 3 is invalid.
-It should be (1 OR 2) AND 3 or 1 or (2 AND 3).
I tried the following Regex. It works for most of the conditions but it is failing to check the above condition.
/^(\s*\(\d+\s(AND|OR)\s\d+\)|\s*\d+)((\s*(AND|OR)\s*)(\(\d+\s(AND|OR)\s\d+\)|\s*\d+))*$/
Can anyone please help me to sort out the above problem.
Hi,
What's the recommended way to cover off unit testing of generic classes/methods?
For example (referring to my example code below). Would it be a case of have 2 or 3 times the tests to cover testing the methods with a few different types of TKey, TNode classes? Or is just one class enough?
public class TopologyBase<TKey, TNode, TRelationship>
where TNode : NodeBase<TKey>, new()
where TRelationship : RelationshipBase<TKey>, new()
{
// Properties
public Dictionary<TKey, NodeBase<TKey>> Nodes { get; private set; }
public List<RelationshipBase<TKey>> Relationships { get; private set; }
// Constructors
protected TopologyBase()
{
Nodes = new Dictionary<TKey, NodeBase<TKey>>();
Relationships = new List<RelationshipBase<TKey>>();
}
// Methods
public TNode CreateNode(TKey key)
{
var node = new TNode {Key = key};
Nodes.Add(node.Key, node);
return node;
}
public void CreateRelationship(NodeBase<TKey> parent, NodeBase<TKey> child) {
.
.
.
Hi!
This question follows this: handling to onchange event of AutoCompleteTextField in wicket
I'm trying to use the AutoCompleteTextField with a custom class as the generic type, and to add an AjaxFormComponentUpdatingBehavior. What I mean is I want to have a
AutoCompleteTextField<SomeClass> myAutoComplete = ...;
and after that add a AjaxFormComponentUpdatingBehavior:
myAutoComplete.add(new AjaxFormComponentUpdatingBehavior("onchange") {
@Override
protected void onUpdate(AjaxRequestTarget target) {
System.out.println( "Value: "+getValue() );
}
});
The problem is that for some reason, adding that behavior makes the form try to set the model object with a String (even though the AutoCompleteTextField has a generic type of SomeClass), causing a ClassCastException when the onchange event fires.
Is there a way to use AutoCompleteTextField without it being AutoCompleteTextField<String>? I couldn't find any example. Thanks for your time!
and thanks to the user biziclop for his help in this matter.
Can someone explain to me why these comparisons work they way the do. I had a bug in one of my scripts that took me a little bit to work through. I was using read-host and typing a number. It was storing it as a string.
Write-Host "(`'2`' -gt 9 ) = " ('2' -gt 9 )
Write-Host "(2 -gt 9 ) = " (2 -gt 9 )
Write-Host "(`'2`' -gt 10 ) = " ('2' -gt 10 )
If you are comparing a string to an Int does it use the Ascii value? If so why does the first one show $false, it should be $true.
Then how is it when you chage it to an int of 10 it because $true.
I would like to know what are the open source and commerical tools for window Service Testing. Like memeory usage and code leakes etc ..
C# 2.0 - Window Service.
Hi,
this is something I know I should embrass in my coding projects but, due to lack of knowledge and my legendary lazyness, I do not do.
In fact, when I do them, I feel like overloaded and I finally give up.
What I am looking for is a good book/tutorial on how to really write good tests -i.e useful and covering a large spectrum of the code -.
Regards
This is for UNIX shell programming. It have to be supported by multiple UNIX platforms including Solaris, Linux, and AIX.
I have this scenario -- I am to read from a text file a string that may or may not contain an environment variable that may or may not be defined. For example:
<foo.bar> This error code was found: $(error_code)
I have the following code:
statement=$(sed -n $1'p' $messagefile)
echo $echo_flag $statement
$1 = line number supplied to this particular function/script.
$messagefile = filename of log file.
$echo_flag = "-e" in Linux, otherwise, empty.
$(error_code) = 42.
Instead of getting this when running:
<foo.bar> This error code was found: 42
I still get this:
<foo.bar> This error code was found: $(error_code)
How exactly do I tell the shell script that the value of statement should be evaluated further beyond what sed have done?
Suppose I have a list of #defines in a header file for an external library. These #defines represent error codes returned from functions. I want to write a conversion function that can take as an input an error code and return as an output a string literal representing the actual #define name.
As an example, if I have
#define NO_ERROR 0
#define ONE_KIND_OF_ERROR 1
#define ANOTHER_KIND_OF_ERROR 2
I would like a function to be able to called like
int errorCode = doSomeLibraryFunction();
if (errorCode)
writeToLog(convertToString(errorCode));
And have convertToString() be able to auto-convert that error code without being a giant switch-case looking like
const char* convertToString(int errorCode)
{
switch (errorCode)
{
case NO_ERROR:
return "NO_ERROR";
case ONE_KIND_OF_ERROR:
return "ONE_KIND_OF_ERROR";
...
...
...
I have a feeling that if this is possible, it would be possible using templates and metaprogramming, but that would only work the error codes were actually a type and not a bunch of processor macros.
Thanks
Hi
This is ongoing issue to something I posted yesterday.
I have a .net object that I want to use in Excel. I have an existing VBA script that i need to alter to call this the object from. I have then converted the object to a TLB. I've not really touched on this area before so any help will be appreciated.
I have created an interface
[Guid("0F700B48-E0CA-446b-B87E-555BCC317D74"),InterfaceType(ComInterfaceType.InterfaceIsDual)]
[ComVisible(true)]
public interface IOfficeCOMInterface
{
[DispId(1)]
void ResetOrder();
[DispId(2)]
void SetDeliveryAddress(string PostalName, string AddressLine1, string AddressLine2, string AddressLine3, string AddressLine4, string PostCode, string CountryCode, string TelephoneNo, string FaxNo, string EmailAddress);
}
I have also created an class that inherits that object.
[ClassInterface(ClassInterfaceType.None), ProgId("NAMESPACE.OfficeCOMInterface"), Guid("9D9723F9-8CF1-4834-BE69-C3FEAAAAB530"), ComVisible(true)]
public class OfficeCOMInterface : IOfficeCOMInterface, IDisposable
{
public void ResetSOPOrder()
{
}
public void SetDeliveryAddress(string PostalName, string AddressLine1, string AddressLine2, string AddressLine3, string AddressLine4, string PostCode, string CountryCode, string TelephoneNo, string FaxNo, string EmailAddress)
{
try
{
SalesOrder.AmendDeliveryAddress(PostalName, AddressLine1, AddressLine2, AddressLine3, AddressLine4, PostCode);
MessageBox.Show("Delivery address set");
}
catch (Exception ex)
{
throw ex;
}
}
}
I can't access the object methods apart from dispose, I guess IDisposable is working fine. Is there anything I need to my Interface?
I'm dealing with a file with a linked list of lines with each node looking like this:
struct TextLine{
//The actual text
string text;
//The line number of the document
int line_num;
//A pointer to the next line
TextLine * next;
};
and I'm writing a function that adds spaces at the beginning of the lines found in the variable text, by calling functions like linelist_ptr->text.insert(0,1,'\t');
The program compiles, but when I run it I get this error:
terminate called after throwing an instance of 'std::out_of_range'
what(): basic_string::at
Aborted
Any ideas?
I want to have a few strings in my c++ app and I want to be able to edit them later in the deployed applications (the compiled exe), Is there a way to make the exe edit itself or it resources so I can update the strings value?
The app checks for updates on start, so I'm thinking about using that to algo send the command when I need to edit the strings (for example the string that contains the url used to check for updates).
I don't want to use anything external to the exe, I could simply use the registry but I prefer to keep everything inside the exe.
I am using visual studio 2010 c++ (or any other version of ms visual c++).
Is there any good framework for comparing whole objects?
now i do
assertEquals("[email protected]", obj.email);
assertEquals("5", obj.shop);
if bad email is returned i never get to know if it had the right shop, i would like to get a list of incorrect fields.
Hi all
I have a .net class library 2.0 with an app.config with a connectionString section.
I have 01 Method that this class library exposes " string GetConnectionString(string name)
However even though the app.config in this class library has 3 connstrings it does not read this config.exe.How can I make it read the app.config that resides withing this dll?
Again,
Usually you will have a web or windows app with a config and it will all work.
Mine is a special case I need to read the connectionstring within this class library.
How can I do it?
thanks a lot
I have a PHP array with some predefined values:
$aArray = array(
0 => 'value0',
1 => 'value1'
);
I need to create a function where the string input will always return the same, valid, array key so that when I call:
GiveMeAKey('http://www.google.com'); // May return 0 or 1
I receive always the same key (I don't care which one) from the array. Obvisously I can't store the relationship in a database and the string passed to the GiveMeAKey method can be any URL.
I wonder if there is a way of doing that ?
I need an algorithm that return all possible combination of all characters in one string.
I've tried:
$langd = strlen($input);
for($i = 0;$i < $langd; $i++){
$tempStrang = NULL;
$tempStrang .= substr($input, $i, 1);
for($j = $i+1, $k=0; $k < $langd; $k++, $j++){
if($j > $langd) $j = 0;
$tempStrang .= substr($input, $j, 1);
}
$myarray[] = $tempStrang;
}
But that only returns the same amount combination as the length of the string.
Say the $input is = "hey", the result would be: hey, hye, eyh, ehy, yhe, yeh.
In my application, I am trying to pass a serializable object through an intent to another activity. The intent is not entirely created by me, it is created and passed through a search suggestion.
In the content provider for the search suggestion, the object is created and placed in the SUGGEST_COLUMN_INTENT_EXTRA_DATA column of the MatrixCursor. However, when in the receiving activity I call getIntent().getSerializableExtra(SearchManager.EXTRA_DATA_KEY), the returned object is of type String and I cannot cast it into the original object class.
I tried making a parcelable wrapper for my object that calls out.writeSerializable(...) and use that instead but the same thing happened.
The string that is returned is like a generic Object toString(), i.e. com.foo.yak.MyAwesomeClass@4350058, so I'm assuming that toString() is being called somewhere where I have no control.
Hopefully I'm just missing something simple. Thanks for the help!
HOSTNAME=$1
#missing files will be created by chk_dir
for i in `cat filesordirectorieslist_of_remoteserver`
do
isdir=remsh $HOSTNAME "if [ -d $i ]; then echo dir; else echo file; fi"
if [ $isdir -eq "dir" ]
then
remsh $HOSTNAME "ls -d $i | cpio -o" | cpio -id
else
remsh $HOSTNAME "ls | cpio -o" | cpio -id
fi
done
i need simple solution for checking remote file is directory or file ?
thanks
how to convert the html tags to the msg bodg in mail function.
i.e i have
Company Name: BPL Industry Type:
i have got the string as
datatable dt=new datatable();
string msg= dt.rows[i]["Message"].tostring();
i need to convert this html tags to the exact message;
if (boolcheck)
{
msg.Body = ????????? wat to use over here.... how to remove the html tags and get the exact message
}
pls help??????????/
Currently me and my friend are developing a website, for what we will call 'projects' we just have a basic auto increment id in the database used to navigate to projects such as
oururl.com/viewproject?id=1
but we started thinking, if we have alot of posted projects thats going to be a LONG url. So we need to somehow randomly generate a alphanumerical string about 6 characters long. We want the chance of the string being duplicated being extremely low and of course we will query the database before assigning an identifier. Thanks for anyhelp, means alot!