Welcome Guest ( Login | Register )



All times are UTC - 7 hours [ DST ]



Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: re-usability of buttons and verification screens question
PostPosted: Mon Jun 18, 2018 2:12 pm 

Joined: Tue Jun 05, 2018 12:10 pm
Posts: 5

Offline
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):

Code:
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:
   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());
                }



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..





Attachments:
Untitled.png
Untitled.png [ 322.06 KiB | Viewed 616 times ]
 Profile  
 
 Post subject: Re: re-usability of buttons and verification screens questio
PostPosted: Fri Jun 22, 2018 3:07 pm 

Joined: Tue Jun 05, 2018 12:10 pm
Posts: 5

Offline
After forcing my way...
I was able to get the Tag by "Running through the code with a chainsaw"..

I get the field infos from the sender obj.
Then I either look for data item or dynamic bindings in the sender (depending on obj type)
I then use this data to to comb my way in Globals.Tags info fiends to get my tag...

half a page of code to get the tag associated with the sender without knowing the tag name.

There's got to be a better way !!!! :)

is there? Please :) ?


 Profile  
 
 Post subject: Re: re-usability of buttons and verification screens questio
PostPosted: Fri Sep 07, 2018 6:29 am 

Joined: Tue Sep 04, 2018 1:20 am
Posts: 12

Offline
Keep in mind that C# is a statically typed language, if you found a solution to your problem albeit long or complicated, you should celebrate.


 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 7 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron