Available Placeholders in Visual Studio 2010/2012 - visual-studio-2010

In Visual Studio we can use pre defined place holders in many places,
as an examples,
if we are creating post build event some place holders are available to get project informations.
if we are looking at the class template, there are some place holders to take project specific things
using System;
using System.Collections.Generic;
$if$ ($targetframeworkversion$ >= 3.5)using System.Linq;
$endif$using System.Text;
$if$ ($targetframeworkversion$ >= 4.5)using System.Threading.Tasks;
$endif$
namespace $rootnamespace$
{
class $safeitemrootname$
{
}
}
May be this place holders are different from place to place ( post/pre build event commands, class template etc.. )
Is there a source where I can find all the list of available place holders?

Related

What happened to Xamarin.Forms.Markup with XF 5.0?

My code is here:
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using FFImageLoading.Svg.Forms;
using Xamarin.Forms;
using Xamarin.Forms.Markup;
namespace Templates
{
public partial class ABC : Grid
{
public ABC()
{
var SVG = new SvgCachedImage()
{
HorizontalOptions = LayoutOptions.FillAndExpand,
VerticalOptions = LayoutOptions.FillAndExpand,
}
.Bind(SvgCachedImage.SourceProperty, nameof(IconSource), source: this);
In 4.8 I was able to do this:
.Bind(SvgCachedImage.SourceProperty, nameof(IconSource), source: this);
But now in 5.0 pre 4 it's telling me that Xamarin.Forms.Markup no longer exists and .Bind no longer works.
Does anyone know if there's a solution for this in 5.0?
Lately c# Markup for Xamarin.Forms has been moved to Xamarin.CommunityToolkit.Markup package, thus you need to:
Install that package in your project.
Reference that package in your class using using Xamarin.CommunityToolkit.Markup (also remove the old using Xamarin.Forms.Markup;)
if you read the release notes you'll see
"Remove markup extensions" (#12730)
and the linked Github issue says
Markup extensions are being moved to the Xamarin Community Toolkit

Visual 2017 Form Designer Failing On "Can't Find Class Error" - However, The Class Exists

I am adding some more control to a win form I created that runs from a .dll
The project loaded fine, after I made some changes to the form in the form visual designer, compiled and then tried to open the form... I was fronted with this error screen.
It is complaining because it can't find the NoButtonsTabControl class.
The NoTabControl.cs class:
namespace TFG_Tools {
// Extend TabControl Class to provide a multi layer canvas with hidden tabs or buttons
public class NoButtonsTabControl : TabControl {
public NoButtonsTabControl() {
Appearance = TabAppearance.FlatButtons;
ItemSize = new Size(0, 1);
//SizeMode = TabSizeMode.Fixed;
}
protected override void WndProc(ref Message m) {
// Hide tabs by trapping the TCM_ADJUSTRECT message
if (m.Msg == 0x1328) m.Result = (IntPtr)1;
else base.WndProc(ref m);
}
}// end NoButtonsTabControl class
}
The start of the main form class looks like this...
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Text.RegularExpressions;
using ENSED;
using System.Globalization;
using Win32;
using WindowsEnv;
namespace TFG_Tools {
public partial class TradePanelForm : Form {
//loaded as master
private bool isMaster = false;
public void SetAsMaster() { isMaster = true; }
...
Why has this suddenly just happened now, so frustrating. I am only intermediate with c# and visual studio. I only used it for this project to create the winform.
How do I tell the designer where this class is, so this error stops appearing?
The funny thing is, it worked fine before, with this arrangement! And if I compile the code, it works, and all the form elements are there.
It's just the designer which is dying atm.
P.S I also moved this project over from Virtual Studio 2015
Thank you.
My solution to this was weird.
close down all open windows in your project
Select the "any cpu" profile
go build->clean solution
Then build->rebuild solution
Re open your form designer
This worked for me, and hopefully will clear this mess up each time it pops up.
I have 2 profiles, a 32bit and 64bit profile so I can compile the dll to both.
Something must break in the designer when I switch to these profiles to build the project.
Hopefully this saves time for others.

How to get Visual Studio to use the default namespace when creating a new class?

When I create a new class in a sub folder in my project, by default it uses DefaultNameSpace.SubFolder.
Anyway to make it just use the default namespace defined at the project level?
You would have to create a new template for Class. You can use the existing template and just remove the extra "fluff" on the namespace.
See this answer: How do I edit the Visual Studio templates for new C# class/interface?
The specific file to modify for your version of Visual Studio is:
C:\Program Files (x86)\Microsoft Visual Studio
14.0\Common7\IDE\ItemTemplates\CSharp\Code\1033\Class\Class.cs
You may want to make a copy of that structure and give your template a different name so you don't end up breaking the default template if you ever want to go back to it.
Edit
Looking at the tokens now, I don't see one specifically for the Default Namespace, $safeprojectname$ is probably as close as you get get using tokens, or just hard code it for your specific template. This is what the template would look like:
using System;
using System.Collections.Generic;
$if$ ($targetframeworkversion$ >= 3.5)using System.Linq;
$endif$using System.Text;
$if$ ($targetframeworkversion$ >= 4.5)using System.Threading.Tasks;
$endif$
namespace $safeprojectname$
{
class $safeitemrootname$
{
}
}
You can find the predefined tokens here: https://msdn.microsoft.com/en-us/library/eehb4faa.aspx

Does Visual Web Part support ObjectDataSource in designer?

I'm trying to upgrade some Sharepoint 2007 webparts to SP2010 using the web part projects built into Visual Studio 2010. Namely, I'm using Visual Web Part to migrate our existing controls, which make extensive use of ObjectDataSource. However, when adding an ODS to the control in the Visual Web Part project, it will not pick up objects in referenced class library projects. I was able to duplicate the problem from a clean setup as follows:
Create a new Visual Web Part
Add a new class library to the solution.
Class code is as follows:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace WebPartODS
{
[System.ComponentModel.DataObject(true)]
public class TestUser
{
[System.ComponentModel.DataObjectMethod(System.ComponentModel.DataObjectMethodType.Select,false)]
public List<int> TestMethod()
{
return new List<int>();
}
}
}
Add the class library project as a reference in the Web Part project
In the VisualWebPart ascx file, add a objectdatasource in the Source view:
<asp:ObjectDataSource ID="TestOD" runat="server"></asp:ObjectDataSource>
Switch to Design view, bring up the "Configure data source" wizard. On the drop down, the class from the library project will not appear.
Is there a step that I am missing here, or is there an issue with trying to do it this way?
Ok, i got it to work. Here is where i got my answer: MSDN Forumn
I originally had a separate class for my business layer. I removed it and put my code in the ascx.cs file. Then I added the following line of code to my page load method.
ObjectDataSource1.TypeName = this.GetType().AssemblyQualifiedName;
I also removed the TypeName from the ascx page.

Automate refactor import/using directives, using ReSharper and Visual Studio 2010

I want to automate the Visual Studio 2010 / Resharper 5 auto inserting import directives to put my internal namespaces into the namespace sphere. Like this:
using System;
using System.Collections.Generic;
using System.Linq;
using StructureMap;
using MyProject.Core; // <--- Move inside.
using MyProject.Core.Common; // <--- Move inside.
namespace MyProject.DependencyResolution
{
using Core;
using Core.Common; // <--- My internal namespaces to be here!
public class DependencyRegistrar
{
...........
}
}
Currently, I'm doing it manually, the problem is that with every refactoring the using directives going up, to the beginning of the page.
In R# 5.0:
ReSharper->Tools->Cleanup Code. Or simply press Ctrl+E, Ctrl+C.
Then use profile that has "Optimize 'using' directives" turned on.
I think readability is better served if the statements are either (all) outside the namespace declaration, or (all) inside of it.
Among the using statements, sorting them with the project statements last (as per your example code) is then preferred.
Resharper follows both the above conventions, so I would recommend sticking to those :)
There is no option to achieve that. So probably the best action go with is a convention that you can achieve easily.

Resources