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]