How to set the string value to RepoItemInfo object?
Posted: Wed Feb 19, 2014 3:50 pm
I want to write a user code method which takes a string value as argument and stores it into RepoItemInfo object and then gets the absolutepath of the appropriate repository item. But I couldnt convert the string to RepoItemInfo object directly. It throws the below error.
Cannot implicitly convert type 'string' to 'Ranorex.Core.Repository.RepoItemInfo' (CS0029)
This is the code I use.
public void convertString_RepoItemInfo(string argument1)
{
Ranorex.Unknown Elem = null;
RxPath repoPath = null;
RepoItemInfo item = null;
string element_Str = "";
item = argument1; //convert string to RepoItemInfo - This is where error is thrown
repoPath = item.AbsolutePath; //Gets Reposiotyr Item's absolute path
element_Str = repoPath.ToResolvedString(); //converts the repository Item's absolute path to string
Report.Info("Path is " + element_Str);
if(Host.Local.TryFindSingle(element_Str, out Elem))
{
Elem.MoveTo(3000);
Elem.Click(3000);
}
else
Report.Info("User", "Element is not found");
}
Since RepoItemInfo is read only object I could not perform this. I tried using reflection as below,
typeof(RepoItemInfo).GetField("Name", BindingFlags.Instance|BindingFlags.NonPublic).SetValue(item, argument1);
This does not throws any erro. But the string value is not set in the item object. Please suggest on How to fix this issue.
Note: Passing string value will be available as repository item in the associated Repository. Eg: Passing string value will be somethins like this. "repo.rootItem.Item1Info"
Cannot implicitly convert type 'string' to 'Ranorex.Core.Repository.RepoItemInfo' (CS0029)
This is the code I use.
public void convertString_RepoItemInfo(string argument1)
{
Ranorex.Unknown Elem = null;
RxPath repoPath = null;
RepoItemInfo item = null;
string element_Str = "";
item = argument1; //convert string to RepoItemInfo - This is where error is thrown
repoPath = item.AbsolutePath; //Gets Reposiotyr Item's absolute path
element_Str = repoPath.ToResolvedString(); //converts the repository Item's absolute path to string
Report.Info("Path is " + element_Str);
if(Host.Local.TryFindSingle(element_Str, out Elem))
{
Elem.MoveTo(3000);
Elem.Click(3000);
}
else
Report.Info("User", "Element is not found");
}
Since RepoItemInfo is read only object I could not perform this. I tried using reflection as below,
typeof(RepoItemInfo).GetField("Name", BindingFlags.Instance|BindingFlags.NonPublic).SetValue(item, argument1);
This does not throws any erro. But the string value is not set in the item object. Please suggest on How to fix this issue.
Note: Passing string value will be available as repository item in the associated Repository. Eg: Passing string value will be somethins like this. "repo.rootItem.Item1Info"