Class Names in Xamarin to Objective C binding - xamarin.ios

We are binding a library from Objective C to C#. We want to use different names in our classes in C#.
Do the class in C# and the objective C class must have the same name?
I know that using the MonoTouch.Foundation.ExportAttribute in the methods in C# we can specify different names for the methods and properties... however, I haven't found how to do the same for classes.
Thanks.

Yes, you can specify your own type name byt specifying a Name property to the [BaseType] attribute. E.g.
[BaseType (typeof (NSObject), Name="NSURL")]
public interface NSUrl {
}
That, real life, example allows you to use NSUrl in C# instead of the Objective-C NSURL type name. You can see many more examples, like the one above, in github.

Related

Private *new* method, or 'Shadow', but Private

It appears clear from Hejlsberg, et. al. 2011 4th Ed. C# Programming Languages that you can make a 'new' function the same name as an existing class member. I can somewhat see why this might be useful , in some kind of versioning conflict scenario,
But what I don't get is why you would ever want to make the 'new' function or the 'shadow' function; private
There are few differences between those.
1. Shadowing is bad programming practice according to OOPs concepts.
2. In shadowing signature could be different.
3. In Shadowing both Derived class methods and Base Class methods are available for use.
In C#, a method in a derived class can have the same name as a method in the base class. You can specify how the methods interact by using the new and override keywords. The override modifier extends the base class method, and the new modifier hides it.

How to really define what a "helper" is?

How can we really say "Here it is, the class I just developed is a helper!"
Would the class have some special criteria? I have a class in Java that exporta my JTables into CVS Files. Is it a helper? I also use a class to validate my forms. Is it a helper?
I hear this term often, but I realize that I don't really know what is it.
I don't think there is a 'textbook' definition of what a helper is, but I think most people would define a helper Class as one that makes no sense on its own - in other words, a Class whose whole purpose of existence it to 'help' make some operation on another class easier to do.
For example, if you create a class that follows the 'Adapter' pattern (i.e. it wraps an object of type 'foo' and lets it be used where normally you can only use type 'bar',) I think that adapter class could loosely be called a 'helper' class as well.
A helper class is a class that is used only by another class to complete a function. Thus, the helper has no right or need to be public, and is only created as being private.
For example, Private Class B helps public class A complete a set of tasks, A is calling on B and is of no use on its own.
For example (just a quick write-up, not tested)
private int newInt(String str)
{
test = Integer.parseInt(str);
return test;
}
and it could be called by:
public int transformation(String str)
{
return newInt(str);
}
This of course would be a class of its own, which would have to be called in your main class.
From some of the quick research I did, and my own personal experience when dealing with helper classes (.Net and Java), a helper class, is a class that provides functionality that is not actually relevant to the code one is developing, but rather provides some boilerplate work, such as casting, converting datatypes, or performing some common mathematical functions, for instance.
Such code can be generally reused in other projects, to further facilitate work being done.
Not everything helps should be a helper, a class wouldn't even exist if it didn't 'help' something. Usually helper classes offer shortcuts, like sql helpers. I think they should be something spesific and contain a group of relevant shortcut functions.
I think a "helper" class is a class which has been created only to support another classes on their functions.
There are a lot of cases where you need to create a "helper" class to put on it some methods that they do some functions. Some examples would be a class that have methods to calculate holidays on a year or transform some fields or formats in another.
Another example could be when you have to develop an app that it has a progress bar. You can create a "helper" class only for manage the progress bar (setting texts, calculating times, providing estimations...).
If you divide your app on layers (GUI, Business, DAO, etc.), it's interesting to have some "helper" or "utility" class (or classes) to do some tasks that you need to do but that they don't belong to GUI, business or DAO (Data Access Objects) layers explicitly. In this case, you could have an utility class for each layer and put inside the auxiliary methods that you need.

How to access certain EStructuralFeatures of an EMF Model?

I know that there are ways to access an EAttribute of an Eclipse EMF model by its featureID or by its name via different indirect approaches. For that I found the following: Eclipse EMF: How to get access EAttribute by name?
But what if I don't know the name of the attribute I want to get? Let's say, based on the design, the model has some fixed attributes by the developer, along with the features that can be set dynamically by the user.
So, for the time being I use the getEAllStructuralFeatures() and use indexes via get() to reach to the by-the-user-created attributes, since I know that the list I get will have the fixed attributes of the model as its first elements beginning with the index 0. But I find this solution unclear and inefficient. Also in some cases, that I want to work, not suitable.
E.g: IEMFEditProperty prop = EMFEditProperties.list(editingDomain, EMFMODELPackage.Literals.EMFMODEL.getEAllStructuralFeatures().get(X));
Do you know a solution or a workaround for this problem? As far as I can see, there are no direct methods to get such dynamically created features of the model.
Every help will be appreciated.
I have been working on a similar case recently where I first tried to define an EStructuralFeature to access exactly the setting/attribute of the object that I needed.
But if you look at how things work internally in ECore, you will find out, that there is no way this will ever work, since the indices are bound to the object identity of the EStructuralFeature objects created at runtime for the specific context (i.e. EClass instance).
My approach was then to either inspect the features proposed by EClass.getEAllStructuralFeatures or to iterate over the features and inspect the object returned by EObject.eGet for this very feature (where EClass eClass = eObject.eClass()).
Example: In a UML profile I have defined a UML Stereotype called "Bean" with a property called FactoryEntity. The property shall reference a UML Class with the Stereotype "Entity" that is closest to this very bean and for which a static factory method will be generated.
In the model I would then have one UML Class typed as Bean and one as Entity.
And for the Class typed as "Bean" I would then set a value for the attribute/property factoryEntity defined in the profile.
The question was then how the property value would be accessible in ECore. I ended up iterating the List of available EStructuralFeature of the EClass of the EObject and checking the type of the object returned by eGet.
final EObject eObject = (EObject) holdingClass.getValue(stereotype, stereoTypePropertyName);
final EList<EStructuralFeature> allEStructFeats = eObject.eClass().getEAllStructuralFeatures();
for(EStructuralFeature esf : allEStructFeats)
{
final Object o = eobject.eGet(esf);
if(o instanceof org.eclipse.uml2.uml.Class)
{
return (org.eclipse.uml2.uml.Class) o;
}
}
Maybe that is not the most elegant way to access structural features but it is the only one I thought was robust enough to last.
Please let me know if you have any suggestions on how to improve this.

xceed Propertygrid - how to use a property collection

I try to use the great propertygrid from exceed.wpftoolkit but I have to problems based on the application I have to create.
First I didn't know at compile time the number of properties the grid has to show. So I couldn't use a simple class with properties/attributes and annotations as datacontext or source for the grid, I need a list or dictionary in which I place a number of grid properties at runtime.
I google for several hours and try to find an example in the sample folders of the toolkit sources but nothing has help me.
Second problem or apply is to replace the usage of annotations in the property class. I need to create the properties at runtime and place the propertyeditor and annotation settings at runtime to the property.
Could anybody help me with some simple examples or good places to look for. I believe the propertygrid is very powerful and could do this.
You need to create a class that implements the ICustomTypeDescriptor interface to provide all the PropertyDescriptor instances that represent your dynamic properties.
After that you can set an instance of the class that implements the ICustomTypeDescriptor interfaces as SelectedObject to the PropertyGrid.
You can find an example here.

How can I make JAXB-generated classes participate in a Visitor pattern?

Hey folks, hopefully a nice easy one here.
I'm generating classes with JAXB from a schema, and I'd like to be able to process them with a Visitor pattern.
To do that, I think I need every JAXB-generated class to implement the interface I've defined, and add a very simple method to them, so a simple example would be:
Default class:
public class MyClass {
private String name;
public void get/setName() {...}
}
Desired class:
public class MyClass implements MyVisitorNode {
private String name;
public void get/setName() {...}
public void accept(MyVisitorVisitor visitor) {
visitor.visit(this);
}
}
Is this possible, and if it is, what are the options? (Change the schema, runtime bytecode manipulation, manipulate the JAXBContext somehow...)
Ideally, without relying on vendor-specific extensions.
Thanks!
The xjc compiler for JAXB has a plugin interface that allows developers to create plugins that modify the generated code. My personal favorite is the fluent-api but there are others to add toString, equals, hashCode, etc.
I created a plugin using this technology to implement the visitor pattern and made it available as a google code project. It may not be exactly what you're looking for but it might be a good place to start to review the code and tests if you need to modify it to suit your needs.
http://code.google.com/p/jaxb-visitor/
The JAX-B generated classes are standard Java classes that you can customize in any way you desire, e.g., extend interface, add additional methods, etc..). The annotations on the class and attributes are the driving factor for the marshalling and unmarshalling process.
With that said, there are somethings you need to take into account if you customize the JAXB generated classes. As stated at the top of each class "Any modifications to this file will be lost upon recompilation of the source schema". In short, if you customize the class, you will need to manually make code changes to support any schema updates. If you do regenerated the classes, your custom code will be removed and you will have to start all over.

Resources