Need to find Property name - visual-studio

I have several tables in my application that are displaying lists of objects from classes. I have properties to represent each value in those classes as defined in the following example
...
Public Property Cod() As Int32
Get
Return _codigo
End Get
Set(ByVal Value As Int32)
_codigo = value
End Set
End Property
...
My code hides every column and then, I use the "formatarCol" method to state which columns I want shown represented as the second parameter(which must have the same name as the properties mentioned above) and the name to be displayed for that column as the third parameter.
...
Utilidades.formatarCol(.Columns, "Cod", "Cod")
Utilidades.formatarCol(.Columns, "Estab", "Estabelecimento")
Utilidades.formatarCol(.Columns, "Sel", "Sel.")
...
Everything is working fine but I was trying to rename some of the properties. If I rename said properties I have to go to each table and manually change each string. I can't just use a replace all because different classes may have properties with the same name.
I was hoping that someone had a suggestion on how to get the Property's name instead of manually adding a string so that if I need to rename a Property again I won't have to manually go through every column where it's used and change the string.

You can rename property via refactor:
Right click your property in code -> Refactor -> Rename
It will only rename property for your class and for all occurrences of that property.

To access the name of a property in a class you can use NameOf
Example:
NameOf([Namespace to class].Cod) //returns "Cod"

Related

Set Workshop Filters' default value

When we define a filter in Workshop, the output object set is used to apply users' filter options to another widget.
But it's also mentioned in the documentation that setting this variable is a mean to provide et default value: how does it actually work? I mean, how to shall I do to set this variable (I do not even know how to put a static value) with, for instance, the output of another widget (let's say a multi select table)?
The output of a Filter List widget in Workshop is a filter-type variable. To get an Object Set that reflects this filter, you then create a separate Object Set-type variable and use the configuration option there to choose one or more filter-type variables to apply.
To set the defaults of the filter so that they show up as selections in the Filter List, you can edit the default configuration for the for the output filter variable. First you have to choose the object type to which the filter corresponds and then you'll have access to the various properties of that object type. You can set a static default or you can choose a "typed" Variable (string, number, date, timestamp) and make that the default.
You can then get creative about where those variables are sourced from to wire together dynamic default selections for the Filter List values.

AppleScript: Using "whose" with record values does not work

In my scriptable app, one of the properties is of a named record type, and that record type has been declared in the sdef as well (named "custom record").
I can get the record like this:
get owner of anElement
--> {pool:"test", position:2}
I can also successfully test for it like this:
set target to {pool:"test", position:2}
if owner of anElement = target then
-- found!
But I cannot use it in a whose clause:
get allElements whose owner = target
--> {}
I also cannot use missing value in the test:
get allElements whose owner = missing value
--> error number -1700 from missing value to custom record
Is that expected behavior with AppleScript, i.e. is it unable to handle records in whose clauses?
Or am I doing something wrong? I have so far not implemented any coercion handlers nor special record handlers because nothing has indicated that I'd need them.
Also, please see my related question: Cocoa Scripting: Returning "null" vs. "missing value"
Short answer : It's expected behavior.
The whose clause works only for element reference types (classes which have an object specifier), but not for record types and custom lists.
Even the selection property of the Finder cannot be filtered by a whose clause.

Core Data KVC example

Sorry to impose, but I would really appreciate it if someone would take a look at this and show me how to get this done:
Core Data works as expected with data associations between the Source list entry(s) and the upper right textField.
So does textField2 (lower right) if you manually type in a string.
I want to append a string in the lower textField, in this case a generic "Hello!" (implemented in the setText method) and have it also maintain it's association with the source list entry.
To summarize: textField2 - manually type in a string, it works as expected. Append the coded string, and it does not maintain it's association with the source list entry.
Here's the sample project.
Thanks again for the help.
Here's how I updated setText: method in MyDocument class:
-(IBAction)setText:(id)sender
{
NSString *newValue = [[output stringValue] stringByAppendingString:#"Hello!"];
[[setText selection] setValue:newValue forKey:#"textField2"];
}
I think your assumptions on value setting direction was wrong. Object does not take a value from the text field. It's the text field that takes value from the object. Hence I create newValue by taking current value of output text field and appending something to it. Then I take [setText selection] object (the one currently selected) and set it's textField2 property to new value. This setValue:forKey method automatically updates the output test field with new value of textField2 property.

How do I swap items in a VB6 collection?

If I have a collection of forms (myForms) and I want to switch the position of two forms in the collection (say items 3 and 4 for example), I would expect that the following code would work:
Dim temp as Form
Set temp = myForms(3)
Set myForms(3) = myForms(4)
Set myForms(4) = temp
But that doesn't work. It fails at the third line with the error "Controls property is read only." If I change the line to:
myForms(3) = myForms(4)
I get a type mismatch error instead.
If myForms is a standard collection:
Dim myForms as New Collection
(which is actually different from the controls collection) and you've added the forms using:
myForms.Add frmOne, myForms.Add frmTwo
etc then (yes) you do need to use the Add and Remove methods because of the way the collection references the added objects.
Otherwise the interpretation is that you actually want to replace one form with another and this is not allowed. You can't say:
Set frmOne = frmTwo
unless these are actually variables of type Form.
Why do you need to switch the order? Are you referencing the item numbers somewhere? Would using a Dictionary to collect the forms and reference them by a key be useful?
PS. The type mismatch is simply because both items are objects and need to be 'Set'.
You can't actually swap around items in the controls collection in VB6. You need to use the Add and Remove functions associated with each. Check out this article:
http://support.microsoft.com/kb/190670
Hope this helps!

Automatically generated predicate row templates for to-many key?

In my Core Data managed object model, I have an entity Foo with a to-many relationship (with a to-many inverse) to entity Baz named baz. Baz has a string property named "tag". When I use [NSPredicateRowEditorTemplate templatesWithAttributeKeyPaths:[NSArray arrayWithObject:#"baz.tag"] inEntityDescription:FooDescription] to create the row editors for an NSPredicateEditor, the result contains (as expected) a row template like
[Popup: baz.tag] [Popup: Contains|is|is not|...] [TextField]
When I select "Contains" from the popup, a query with the predicate works as expected. If I choose any of the other popups (e.g. "is"), I get the following error: "to-many key not allowed here". Can I use [NSPredicateRowEditorTemplate templatesWithAttributeKeyPaths:inEntityDescription:] or do I have to build the row editor manually?
It looks like the automatically generated template (using [NSPredicateRowEditorTemplate templatesWithAttributeKeyPaths:inEntityDescription:]) cannot produce the correct operators. The solution is to create the template manually using [NSPredicateEditorRowTemplate initWithLeftExpressions:rightExpressionAttributeType:modifier:operators:options:]. For the given example:
id template = [[NSPredicateEditorRowTemplate initWithLeftExpressions:[NSArray arrayWithObject:[NSExpression expressionForKeyPath:#"baz.tag"]] rightExpressionAttributeType:NSStringAttributeType modifier:NSAnyPredicateModifier operators:keywordOperators options:0];

Resources