Setting default language - xamarin.ios

I would like to see default button captions in my native language ,
Even I changed iPad's language to another lang. my app still shows English ones...Edit,Done,Save etc.
I also set CFBundleDevelopmentRegion as a User-Defined variable in XCode but not helped !
Can you help ?

You should make these things:
Add your native language to app's supported Localization array of languages;
Make your Application.Main procedure looks like:
static void Main (string[] args)
{
// if you want to use a different Application Delegate class from "AppDelegate"
// you can specify it here.
NSUserDefaults.StandardUserDefaults.SetValueForKey(NSArray.FromStrings("tr"), new NSString("AppleLanguages"));
NSUserDefaults.StandardUserDefaults.Synchronize();
UIApplication.Main (args, null, "AppDelegate");
}
Then, this
turns to this
(I suggested that your language is turkish.)

For monotouch I think it is different,
They hide some langs for reducing the size of IPA.
http://docs.xamarin.com/guides/ios/advanced_topics/localization_and_internationalization

Related

How to differentiate color scheme

I would like to change color scheme Eiffel so that the keyword class in java files will be different color than keyword int? If I change Storage in Eiffel, both keywords change the color.
You need to find out the exact scopes of class and int. The PackageResourceViewer is a great way to open files inside .sublime-package files.
Once installed, launch *ā€¯PackageResourceViewer: Open Resource, open the Java package and look for the syntax files (e.g.Java.sublime-syntax`).
I'm not familiar enough with Java, but it looks to me like class uses the scope meta.class and int uses storage.type.primitive.array. That means, that in your theme you would at least have to change meta or storage. Needless to say that you can be more specific than that.
Using a nice little plugin called ScopeAlways, you can see in the status bar the full scope underlying your cursor (if you have multiple cursors, it just uses the first one). In Sublime Text 2, using the following code:
public class Hello {
public static void main(String[] args) {
System.out.println("Hello World!");
int integer = 13;
}
}
The word class is scoped as storage.modifier.java, whereas int is scoped as storage.type.primitive.array.java (I removed a few unimportant extraneous scopes from each for clarity). So, in your theme, you could have one color for storage.modifier, and another for storage.type, to differentiate between class and int. Be aware, however, that many other keywords will fall under both scopes, so your custom colors won't just highlight those particular words.
Good luck!

Do we need this keyword in .net 4.0 or 4.5

I am currently reviewing code written in c#, visual studio 2012.
In lot of places, the code is written using this key word, for ex:
this.pnlPhoneBasicDtls.Visible = true;
this.SetPhAggStats(oStats);
There are many other places where the controls of the page are referred using this key word.
Can somebody advise do we really need to use this here?
Any consequences of removing this keyword?
Thanks in advance..
No, "this" is optional. It's usually included in code generated by a tool and by people who feel the need to be explicit or who want to differentiate it from an argument to the method.
Its Optional you can use the
Property directly like pnlPhoneBasicDtls.Visible = true;
The this keyword is usually optional.
It's sometimes used to disambiguate fields from arguments if the same name is being used for both, for example:
void Main()
{
var sc = new SomeClass();
sc.SomeMethod(123);
Console.WriteLine(sc.thing);
}
public class SomeClass
{
public int thing;
public void SomeMethod(int thing)
{
this.thing = thing + 1;
}
}
In the example above it does make a difference. Inside SomeMethod, this.thing refers to the field and thing refers to the argument.
(Note that the simpler assignment thing = thing is picked up as a compiler error, since it is a no-op.)
Of course, if you use ReSharper then any unnecessary this. (together with unused using statements, unreachable code, etc.) will be greyed out and you can remove them very quickly. The same is probably true of similar tools like CodeRush.

Static data in Visual Studio extension

I've got a Visual Studio extension, where much of the functionality is written through MEF. So far, my individual functionality is per ITextBuffer, so I have used the Properties member to cache instances.
However, now I have some functionality that needs to be per-project and per-solution. The EnvDTE classes offer a Properties object but I couldn't figure out whether or not they could store my own arbitrary data. I really don't want to make my own data static.
How can I store per-project and per-solution data without having to resort to global variables?
Edit:
I might also mention that since you can't use MEF imports for static data, even if you hide it in something like a Singleton, then using the global variable route is physically impossible. So I really, really need something that is not a global.
Edit:
I'm talking about object references, not persistent values. I don't need to store anything in a solution or project file, only with the object.
I found a way to convince MEF to honour my static imports, so for now, I'm just using some static data.
(Microsoft.VisualStudio.Shell.Package.GetGlobalService(typeof(SComponentModel)) as IComponentModel).DefaultCompositionService.SatisfyImportsOnce(this);
It was posted somewhere else- maybe even on SO- took me a while to find it though. Note that this has no interface required- reflection is used, so it should be valid for any this.
If I understand your question correctly, you can create a stub class that you do the exports from, instead of trying to force your static classes to export.
public class HostClass
{
public static string StaticString
{ get { return "string value"; } }
}
public class HostClassStub
{
[Export("StaticStringValue", typeof(string))]
public string StaticString
{ get { return HostClass.StaticString; } }
}
You may also consider just making your static class un-static, if that's an option for you. Remember, that by default MEF imports are singletons, so it should be just like having a global set of variables for each project that does the import.
I know this doesn't address the VS Extensions aspect of your problem, but I haven't dealt with those. Maybe this'll give you a path to your solution, though.

XNA - Keyboard Input

I just started using XNA Framework 4.0 today, and I was wondering what the easiest way was to get input from the keyboard. I recognize a lot of C++ in C# but the whole Java side of it is alien to me. This coupled with XNA is a little confusing so, please be specific and give examples. Thanks.
If you're comfortable mucking around with the Object Browser in VS, I'd advise looking at Microsoft.Xna.Framework.Input.Keyboard/Keyboardstate. These entries will show you what you have available to you in terms of ready-made functions. Alternatively, you could look on MSDN or follow a tutorial on Creator's Club. I'll post a quick snippet that checks for a specific keystroke.
currentState = Keyboard.GetState();
if(currentState.IsKeyDown(theKey) && previousState.IsKeyUp(theKey))
{
//Do something here
}
previousState = currentState;
theKey is a parameter that is defined outside of the scope of this snippet. You could set theKey to a specific value that you would want to trigger some specific program behavior on pressing (at the commented location in the fragment above). theKey is defined as:
Keys theKey
previousState and currentState are defined as:
private static KeyboardState currentState;
private static KeyboardState previousState;
While perhaps not the prettiest way of doing that, it works and is a fairly straightforward example to build from. Hope that helps.

Possible C# 4.0 compiler error, can others verify?

Since I don't know exactly what part of it alone that triggers the error, I'm not entirely sure how to better label it.
This question is a by-product of the SO question c# code seems to get optimized in an invalid way such that an object value becomes null, which I attempted to help Gary with yesterday evening. He was the one that found out that there was a problem, I've just reduced the problem to a simpler project, and want verification before I go further with it, hence this question here.
I'll post a note on Microsoft Connect if others can verify that they too get this problem, and of course I hope that either Jon, Mads or Eric will take a look at it as well :)
It involves:
3 projects, 2 of which are class libraries, one of which is a console program (this last one isn't needed to reproduce the problem, but just executing this shows the problem, whereas you need to use reflector and look at the compiled code if you don't add it)
Incomplete references and type inference
Generics
The code is available here: code repository.
I'll post a description below of how to make the projects if you rather want to get your hands dirty.
The problem exhibits itself by producing an invalid cast in a method call, before returning a simple generic list, casting it to something strange before returning it. The original code ended up with a cast to a boolean, yes, a boolean. The compiler added a cast from a List<SomeEntityObject> to a boolean, before returning the result, and the method signature said that it would return a List<SomeEntityObject>. This in turn leads to odd problems at runtime, everything from the result of the method call being considered "optimized away" (the original question), or a crash with either BadImageFormatException or InvalidProgramException or one of the similar exceptions.
During my work to reproduce this, I've seen a cast to void[], and the current version of my code now casts to a TypedReference. In one case, Reflector crashes so most likely the code was beyond hope in that case. Your mileage might vary.
Here's what to do to reproduce it:
Note: There is likely that there are more minimal forms that will reproduce the problem, but moving all the code to just one project made it go away. Removing the generics from the classes also makes the problem go away. The code below reproduces the problem each time for me, so I'm leaving it as is.
I apologize for the escaped html characters in the code below, this is Markdown playing a trick on me, if anyone knows how I can rectify it, please let me know, or just edit the question
Create a new Visual Studio 2010 solution containing a console application, for .NET 4.0
Add two new projects, both class libraries, also .NET 4.0 (I'm going to assume they're named ClassLibrary1 and ClassLibrary2)
Adjust all the projects to use the full .NET 4.0 runtime, not just the client profile
Add a reference in the console project to ClassLibrary2
Add a reference in ClassLibrary2 to ClassLibrary 1
Remove the two Class1.cs files that was added by default to the class libraries
In ClassLibrary1, add a reference to System.Runtime.Caching
Add a new file to ClassLibrary1, call it DummyCache.cs, and paste in the following code:
using System;
using System.Collections.Generic;
using System.Runtime.Caching;
namespace ClassLibrary1
{
public class DummyCache<TModel> where TModel : new()
{
public void TriggerMethod<T>()
{
}
// Try commenting this out, note that it is never called!
public void TriggerMethod<T>(T value, CacheItemPolicy policy)
{
}
public CacheItemPolicy GetDefaultCacheItemPolicy()
{
return null;
}
public CacheItemPolicy GetDefaultCacheItemPolicy(IEnumerable<string> dependentKeys, bool createInsertDependency = false)
{
return null;
}
}
}
Add a new file to ClassLibrary2, call it Dummy.cs and paste in the following code:
using System;
using System.Collections.Generic;
using ClassLibrary1;
namespace ClassLibrary2
{
public class Dummy
{
private DummyCache<Dummy> Cache { get; set; }
public void TryCommentingMeOut()
{
Cache.TriggerMethod<Dummy>();
}
public List<Dummy> GetDummies()
{
var policy = Cache.GetDefaultCacheItemPolicy();
return new List<Dummy>();
}
}
}
Paste in the following code in Program.cs in the console project:
using System;
using System.Collections.Generic;
using ClassLibrary2;
namespace ConsoleApplication23
{
class Program
{
static void Main(string[] args)
{
Dummy dummy = new Dummy();
// This will crash with InvalidProgramException
// or BadImageFormatException, or a similar exception
List<Dummy> dummies = dummy.GetDummies();
}
}
}
Build, and ensure there are no compiler errors
Now try running the program. This should crash with one of the more horrible exceptions. I've seen both InvalidProgramException and BadImageFormatException, depending on what the cast ended up as
Look at the generated code of Dummy.GetDummies in Reflector. The source code looks like this:
public List<Dummy> GetDummies()
{
var policy = Cache.GetDefaultCacheItemPolicy();
return new List<Dummy>();
}
however reflector says (for me, it might differ in which cast it chose for you, and in one case Reflector even crashed):
public List<Dummy> GetDummies()
{
List<Dummy> policy = (List<Dummy>)this.Cache.GetDefaultCacheItemPolicy();
TypedReference CS$1$0000 = (TypedReference) new List<Dummy>();
return (List<Dummy>) CS$1$0000;
}
Now, here's a couple of odd things, the above crash/invalid code aside:
Library2, which has Dummy.GetDummies, performs a call to get the default cache policy on the class from Library1. It uses type inference var policy = ..., and the result is an CacheItemPolicy object (null in the code, but type is important).
However, ClassLibrary2 does not have a reference to System.Runtime.Caching, so it should not compile.
And indeed, if you comment out the method in Dummy that is named TryCommentingMeOut, you get:
The type 'System.Runtime.Caching.CacheItemPolicy' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Runtime.Caching, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
Why having this method present makes the compiler happy I don't know, and I don't even know if this is linked to the current problem or not. Perhaps it is a second bug.
There is a similar method in DummyCache, if you restore the method in Dummy, so that the code again compiles, and then comment out the method in DummyCache that has the "Try commenting this out" comment above it, you get the same compiler error
OK, I downloaded your code and can confirm the problem as described.
I have not done any extensive tinkering with this, but when I run & reflector a Release build all seems OK (= null ref exception and clean disassembly).
Reflector (6.10.11) crashed on the Debug builds.
One more experiment: I wondered about the use of CacheItemPolicies so I replaced it with my own MyCacheItemPolicy (in a 3rd classlib) and the same BadImageFormat exception pops up.
The exception mentions : {"Bad binary signature. (Exception from HRESULT: 0x80131192)"}

Resources