re-usability of buttons and verification screens question
Posted: Mon Jun 18, 2018 2:12 pm
Hello All!
I am new to C# and having trouble "finding" the tags allocated to my object.
I want to be able dynamically without hardcoding the tag name to be able to pass it on to (a pop up screen or anything else)
So when i select a Tag in the tag security section(see attached picture) i can use in in the script as sender. Tag or something similar. this is probable not a "stock supported" feature.
here is where i am at after fighting with this for some time now:
i have added this to the Tags class(gets a tag from passing it the name - works fine):
now on a button click script action i do something like:
i cant find a way to track the assigned tag name or even direct reference to the tag in the button/sender variables.
Please help? is there an easier way to do this?
All i need is a Sender.Tag type reference back to the UI chosen tag to allow me to requse the code and button without making a million instances of the same thing in my projects..
[/color]
I am new to C# and having trouble "finding" the tags allocated to my object.
I want to be able dynamically without hardcoding the tag name to be able to pass it on to (a pop up screen or anything else)
So when i select a Tag in the tag security section(see attached picture) i can use in in the script as sender. Tag or something similar. this is probable not a "stock supported" feature.
here is where i am at after fighting with this for some time now:
i have added this to the Tags class(gets a tag from passing it the name - works fine):
Code: Select all
public static T StringToTag<T>(string tagName) where T : class
{
Type type = typeof(T);
FieldInfo[] props = Globals.Tags.GetType().GetFields();
foreach (FieldInfo prop in props) {
if (prop.FieldType.Equals(type)) {
if (prop.Name.Equals(tagName, StringComparison.CurrentCultureIgnoreCase)) {
return (T)prop.GetValue(Globals.Tags);
}
}
}
return null;
}
now on a button click script action i do something like:
Code: Select all
void Button_Click(System.Object sender, System.EventArgs e)
{
var TagName = "TestTag2";
GlobalDataItem tag = Tags.StringToTag<GlobalDataItem>(TagName);
LightweightTag tag2 = Tags.StringToTag<LightweightTag>(TagName);
MessageBox.Show( tag2.ToString());
}
Please help? is there an easier way to do this?
All i need is a Sender.Tag type reference back to the UI chosen tag to allow me to requse the code and button without making a million instances of the same thing in my projects..
[/color]