how to generate header of function with visual - visual-studio-2010

Do you know if there is a way to generate comment with hotkey in visual ?
Here is an exemple :
When I press "ctrl + h" (for exemple) I would like the following lines are generated :
/*
* Creation: 2012-07-24 by user
* Modification: 2012-07-25 by user
*/
Int myFunction()
{
}
Thanks !

If you have Generate XML documentation file ticked under the project options (this is not an IDE or solution option, but a project one) then you can type /// directly above a function.
This will create the following example comment, which you can fill in the details between the XML tags...
/// <summary>
///
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public Lookup FindById(int id)
{
The information you put in between the tags will then be used by Visual Studio to populate intelisense information when using the function in other parts of your code. It can also be used with properties, enum, etc.
It's not exactly what you're asking for (including usernames, dates, etc), but I believe it could be an option for you.
(Note, this is also available for VB.NET, and uses ''' instead)

Related

Create files and folder, that are always shared with the user

Using Google Drive API and Spreadsheet Api from c#.
How can I add folders and files (speedsheets) to a folder and make sure that they are always shared and visible to the human user?
I know about Google.Apis.Drive.Permission, but it has a daily quota, and send out an email, it does not seem like the right solution.
I would prefer to just be able to work inside a folder, and then all stuff should always be visible to both the API and the human user.
Any tips:)
You would use the Google drive api to create a file and then add permissions on that file to share it with a user. This is how you do it and there really isnt a better way to do it. In order for a user to access it you must grant them permissions on it.
/// <summary>
/// Creates a permission for a file or Team Drive.
/// Documentation https://developers.google.com/drive/v3/reference/permissions/create
/// Generation Note: This does not always build corectly. Google needs to standardise things I need to figuer out which ones are wrong.
/// </summary>
/// <param name="service">Authenticated Drive service.</param>
/// <param name="fileId">The ID of the file or Team Drive.</param>
/// <param name="body">A valid Drive v3 body.</param>
/// <param name="optional">Optional paramaters.</param>
/// <returns>PermissionResponse</returns>
public static Permission Create(DriveService service, string fileId, Permission body, PermissionsCreateOptionalParms optional = null)
{
try
{
// Initial validation.
if (service == null)
throw new ArgumentNullException("service");
if (body == null)
throw new ArgumentNullException("body");
if (fileId == null)
throw new ArgumentNullException(fileId);
// Building the initial request.
var request = service.Permissions.Create(body, fileId);
// Applying optional parameters to the request.
request = (PermissionsResource.CreateRequest)SampleHelpers.ApplyOptionalParms(request, optional);
// Requesting data.
return request.Execute();
}
catch (Exception ex)
{
throw new Exception("Request Permissions.Create failed.", ex);
}
}
Code ripped from my sample project PermissionsSample.cs
If you are having an issue with the quota then you can try to go to google developer console and have your quota increased. Note: Quota is based upon the number of request not the type of request you are making.
Thanks for info about permissions with example!
I found out that if you just manually create a folder that is shared read/write with the google-drive-API-email-address, and then make sure everything is going on within this folder it behaves as wanted and all files are visible to both human and computer.
Best regards Anders

Shared Preferences in Xamarin.forms

I have tried to save login value as true if user has logged in once by using
Application.Current.Properties["isLoggedIn"] = "true";
but its not working. If i remove my app from background it again shows the login page but if user is logged in it should show the next page.
When using 'Application Properties Dictionary' you have to keep in mind few things:
According to the official documentation: 'The Properties dictionary is saved to the device automatically'. However, if you want to ensure persistence you have to explicitly call SavePropertiesAsync().
The Properties dictionary can only serialize primitive types for storage. Attempting to store other types such as List can fail silently.
Read the official documentation carefully and pay attention to details. Here is a code example:
private async Task SaveApplicationProperty<T>(string key, T value)
{
Xamarin.Forms.Application.Current.Properties[key] = value;
await Xamarin.Forms.Application.Current.SavePropertiesAsync();
}
private T LoadApplicationProperty<T>(string key)
{
return (T) Xamarin.Forms.Application.Current.Properties[key];
}
// To save your property
await SaveApplicationProperty("isLoggedIn", true);
// To load your property
bool isLoggedIn = LoadApplicationProperty<bool>("isLoggedIn");
Base on your needs you may consider Local Database or Settings Plugin instead. However for saving just a few primitive values Application Properties approach should be good enough.
Xamarin Forms now includes Xamarin Forms Essentials and contains the Preferences component that you need. Check out the official website and try it.
https://learn.microsoft.com/en-us/xamarin/essentials/preferences?tabs=ios
This is an example of how to manage preferences with Essentials.
To save a value for a given key in preferences:
Preferences.Set("my_key", "my_value");
To retrieve a value from preferences or a default if not set:
var myValue = Preferences.Get("my_key", "default_value");
To remove the key from preferences:
Preferences.Remove("my_key");
To remove all preferences:
Preferences.Clear();
Supported Data Types:
bool
double
int
float
long
string
DateTime
First we set the key and value using below code
Xamarin.Essentials.Preferences.Set("UserId", content.userId);
We can get the above value in any page of project using below code
Xamarin.Essentials.Preferences.Get("UserId", "");

Is it normal for NPoco/PetaPoco Fetch() to get all data and then filter client side?

I've noticed a huge difference in how NPoco (or PetaPoco) works depending on which function you call when you are using LINQ.
For instance compare Fetch() which Query() which both appear to do the same thing:
A: Fetch<EntryImage>().Where(t => t.EntryType == type && t.EntryID == entryID);
B: Query<EntryImage>().Where(t => t.EntryType == type && t.EntryID == entryID);
A returns every row in the table (10,000+) and then filters client side.
B returns just the one row I'm expecting.
I find this behavior is quite dangerous - it would be very easy to write very badly performing code without really evening noticing. Is this expected behavior? If this is normal behavior, is there any way to get a list of methods which work this way, so I can avoid using them where possible?
This is expected behavior for NPoco.
As per source:
Fetch returns a list.
/// <summary>
/// Fetch all objects of type T from the database using the conventions or configuration on the type T.
/// Caution: This will retrieve ALL objects in the table
/// </summary>
List<T> Fetch<T>();
Query returns IQueryProviderWithIncludes (similar to IQueryable)
/// <summary>
/// Entry point for LINQ queries
/// </summary>
IQueryProviderWithIncludes<T> Query<T>();
If you are using PetaPoco (*), neither of the initial code samples are great - but the issue is not Fetch vs Query.
In both instances, the SQL being submitted to the server is basically "SELECT * FROM EntryImage" (run a sql trace and confirm that if you aren't sure).
Fetch vs Query doesn't alter the SQL being sent to the server - it just alters how that data is served up client side (i.e. as a List or a deferred execution IEnumerable via yield).
To do what you want, check out PetaPoco's documentation :
var sql=PetaPoco.Sql.Builder()
.Select("*")
.From("articles")
.Where("date_created < #0", DateTime.UtcNow) // fluent Where clause
.OrderBy("date_created DESC");
(*) If you are using NPoco, see above for the answer.

How to suppress stylecop/fxcop/visual studio code analysis for auto generated file?

I have C# code generated from ANTLR. How do I tell stylecop/fxcop/visual studio code analysis to ignore this file in checking?
For FxCop, the definitive method is to decorate your code with a [GeneratedCode] attribute and disable the option to check generated code. The details differ between VS and/or FxCop versions; see this blog post for correct usage of the attributes.
StyleCop ignores that attribute, but you have a few other options:
Name your file "Whatever.Designer.cs" and set that option in your StyleCop.settings file.
Include an XML header on the file that includes <auto-generated /> somewhere in it.
In addition, the most recent versions of both tools appear to ignore code that is inside a region that includes the phrase "generated code" in its name. For example, in your Windows Forms *.Designer.cs files you will see this:
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent ( )
{
// stuff here
}
#endregion
Code Analysis and StyleCop with both ignore the code within that region, but will still run against the remainder of this file. (If you have the "Ignore designer files" option set, of course, StyleCop will ignore the entire file because it ends in .Designer.cs.)
It is very frustrating that the two tools cannot seem to agree on how to ignore code (almost as frustrating as the amount of auto-generated code that doesn't bother to exclude itself properly -- looking at you here, EF.) The problem, is that Code Analysis checks your compiled code (which has attribute metadata but no comments), while StyleCop checks your source code (where the scope of metadata attributes are harder to track, though it would still be possible).
In my templates I tend to use a mixture of options: I include a StyleCop-aware header with the <auto-generated> tag in it, and then decorate each code element with [GeneratedCode], and it seems to catch everything. (Possibly goes without saying that my autogenerated code also tries really hard not to violate the rules in the first place :) )
The other method might be using #headers.
#lexer::header {
#pragma warning disable 1591
}
#parser::header {
#pragma warning disable 1591
}
Well, i noticed that the ANTLR generated files are 'partially', so i just created a second file, added the same class also as 'partially' without the class having any field or method, but added the following attribute to the class:
[GeneratedCodeAttribute("ANTLR", "3.0.0.0")]
Then i checked this file in, into TFS source control. Like this, the class has the generated code attribute set and CodeAnalysis/FxCop will ignore the entire class. But you will have to configure CodeAnalysis, to not check auto generated code (appropriate checkbox set to checked).

wp7 - application.current as app Value can not be null

I put some properties in the App.xaml.cs file which I am using to store data and populate textboxes as I navigate through my application:
public String appRXName { set; get; }
public String appRXNumber { set; get; }
Originally I had a pivot control that called different pages to gather data, but then I moved that pivot control item off to its own page that still calls other pages to collect data. Now when I run the application I get an error.
Basically it was working when I had it inside the original Pivot control. Once I moved it to a separate page (pivot page calles it) then I started to get this error:
System.ArgumentNullException was unhandled Message=Value can not be null. Parameter name: Text
No matter what page I hit always the second item in the list displays the error.
txtRxNotes.Text = (Application.Current as App).appDosageNotes;
txtQuantity.Text = (Application.Current as App).appQuantity.ToString();
I found something online about a RootVisual but I'm not sure if that is what I looking at or not. Does anyone have any ideas?
The ArgumentNullException is being thrown because the value that you are trying to set for the Text property is null, which you cannot do; the Text property is not a nullable type.
Without knowing how and when these application-level properties are being set it's difficult to provide a good explanation of why the behavior is different since your refactor, but you could either:
Put a null check in the code that accesses these application-level properties.
Initialise the application-level properties to string.Empty in the application constructor.

Resources