How to add auto document for method & class & field in C# with ReSharper 5? - resharper

Visual Tomato AssistX provides a menu to automatically add method/class documents for the C++ functions.
Does ReSharper provide similar functions that I can use to add document for method/class?

I don't think Resharper does this for methods but if you want to insert file headers have a look at this post. If you want to add a method comment you can just place your cursor on an empty line above one of your method and insert 3 slashes which will insert a comment block for you to fill out.
public ActionResult Index(int page)
{
return View();
}
with /// inserted:
/// <summary>
///
/// </summary>
/// <param name="page"></param>
/// <returns></returns>
public ActionResult Index(int page)
{
return View();
}

I'm using GhostDoc for that.

Related

Which NetTopologySuite Index is optimal for include and exclude rectangle search

I have a following problem: huge number of points and huge number of queries which need to provide as fast as possible any point that is inside include rectangle (red) and outside exclude rectangle (green). As number of points is huge and rectangles can be of various sizes it would be best to use some spatial index, but as far as I see all Query functions in NetTopologySuite.Index return lists with all results, where I need any single result and so queries are too expensive when big rectangle with many points comes.
Did I miss some spatial index which will solve my problem? Or some nice trick to solve it fast? I could use visitors but they are evaluated for every node, I could use Exception to break out when element found, but that looks ugly.
You can query the indices using a custom IItemVisitor{T} that would exclude items intersecting the green rectangle. Sth along these lines:
/// <summary>
/// Item visitor that specifically excludes a predefined area.
/// </summary>
/// <typeparam name="T">The type of the items to visit</typeparam>
public class ExcludingItemVisitor<T> : IItemVisitor<T> where T:Geometry
{
private readonly Envelope _exclude;
private readonly List<T> _items = new List<T>();
/// <summary>
/// Initialize with <paramref name="exclude"/>
/// </summary>
/// <param name="exclude"></param>
public ExcludingItemVisitor(Envelope exclude)
{
_exclude = exclude;
}
/// <inheritdoc cref="IItemVisitor{T}.VisitItem"/>>
public void VisitItem(T item)
{
// If we have no intersection with _exclude, add it.
if (!_exclude.Intersects(item.EnvelopeInternal))
_items.Add(item);
}
/// <summary>
/// Get a value indicating the gathered items
/// </summary>
public IList<T> Items => _items;
}

how to pass value from one WaterfallDialog to another WaterfallDialog in ComponentDialog

bot framework v4
I have two WaterfallDialogs in ComponentDialog.
I could store value like below in WaterfallDialogs
step.values[currenctCategory] = result;
but when i prompt another second WaterfallDialog from the first WaterfallDialog
, i could not get the step.values[currenctCategory] in second WaterfallDialog
You need to use the State to store the intermediate values that you will need in any of the parent or child dialogs. In version 4 you can do that using the BotAccessors something on below lines
public static string CounterStateName { get; } = $"{nameof(BotAccessors)}.CounterState";
/// <summary>
/// Gets or sets the <see cref="IStatePropertyAccessor{T}"/> for CounterState.
/// </summary>
/// <value>
/// The accessor stores the turn count for the conversation.
/// </value>
public IStatePropertyAccessor<CounterState> CounterState { get; set; }

Register custom class in Kentico 9

I have created a custom gateway class and I need to register this in admin module.
I have added this line in cs file but it throws a namespace error
[assembly: RegisterCustomClass("CustomGateway", typeof(CustomGateway))]
Also in admin -> modules-> e-commerce -> classes tab it says I cannot add or delete class in installed module.
How should I register my customgateway class ?
Make sure you add a using statement for the CMS namespace in the .cs file.
using CMS;
Furthermore, if your CustomGateway class is in a custom namespace (let's call it MyCompany), you will need to add a using statement for that namespace, as well.
using CMS;
using MyCompany;
Regarding the "Classes" tab - the e-commerce classes have nothing to do with registering a custom payment gateway.
As long as you have registered it with the RegisterCustomClass attribute, it will be fine.
You can then proceed with setting it up in the "Store configuration" application.
The full docs regarding custom payment gateways can be found here.
You can't register custom payment gateway class in the module in the Admin UI, you can only do it by placing .cs file in your module folder. That will allow to easly export gateway class within your module.
This is how I've done in 8.2. Example below is for in E-Commerce module. Try it:
public partial class CMSModuleLoader
{
#region "Macro methods loader attribute"
/// <summary>
/// Module registration
/// </summary>
private class CustomGatewayLoaderAttribute : CMSLoaderAttribute
{
/// <summary>
/// Constructor
/// </summary>
public CustomGatewayLoaderAttribute()
{
// Require E-commerce module to load properly
RequiredModules = new string[] { ModuleName.ECOMMERCE };
}
/// <summary>
/// Initializes the module
/// </summary>
public override void Init()
{
// This line provides the ability to register the classes via web.config cms.extensibility section from App_Code
ClassHelper.OnGetCustomClass += GetCustomClass;
}
/// <summary>
/// Gets the custom class object based on the given class name. This handler is called when the assembly name is App_Code.
/// </summary>
private static void GetCustomClass(object sender, ClassEventArgs e)
{
if (e.Object == null)
{
// Provide your custom classes
switch (e.ClassName.ToLower())
{
// Define the class CustomGatewayProvider inheriting the CMSPaymentGatewayProvider and you can customize the provider
case "customgatewayprovider":
e.Object = new CustomGatewayProvider();
break;
}
}
}
}
#endregion
}

How to have a configuration based queue name for web job processing?

I have a webjob app to process a ServiceBus queue, which runs fine, with the following method:
public static void ProcessQueueMessage([ServiceBusTrigger("myQueueName")] BrokeredMessage message, TextWriter log)
However, I would like to be able to change the queue name without recompiling, according for example to a configuration appsetting, can it be done?
Yes, you can do this. You can implement your own INameResolver and set it on JobHostConfiguration.NameResolver. Then, you can use a queue name like %myqueue% in our ServiceBusTrigger attribute - the runtime will call your INameResolver to resolve that %myqeuue% variable - you can use whatever custom code you want to resolve the name. You could read it from app settings, etc.
I've found an implementation of the INameResolver using configuration setting from the azure-webjobs-sdk-samples.
/// <summary>
/// Resolves %name% variables in attribute values from the config file.
/// </summary>
public class ConfigNameResolver : INameResolver
{
/// <summary>
/// Resolve a %name% to a value from the confi file. Resolution is not recursive.
/// </summary>
/// <param name="name">The name to resolve (without the %... %)</param>
/// <returns>
/// The value to which the name resolves, if the name is supported; otherwise throw an <see cref="InvalidOperationException"/>.
/// </returns>
/// <exception cref="InvalidOperationException"><paramref name="name"/>has not been found in the config file or its value is empty.</exception>
public string Resolve(string name)
{
var resolvedName = CloudConfigurationManager.GetSetting(name);
if (string.IsNullOrWhiteSpace(resolvedName))
{
throw new InvalidOperationException("Cannot resolve " + name);
}
return resolvedName;
}
}

DataAnnotation in Universal App

I have used Data Annotations in my project, but in the universal app, it shows an error for there is no namespace for DataAnnotations.
Is "using System.ComponentModel.DataAnnotations" supported in Unversal App ?
Doesn't look like it. According to their roadmap You'll have to scroll down to the bottom table to see that it's available for every platform but the phone. :(
yes, it is support in Windows Universal app, sample code:
using System;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Reflection;
namespace SystematixIndia.Universal.Extensions
{
/// <summary>
/// Provides extensions for the <see cref="Enum" /> class.
/// </summary>
public static class EnumExtensions
{
/// <summary>
/// Gets the display name attribute as a string
/// </summary>
/// <param name="en">The enum.</param>
/// <returns>The display name attribute as a string</returns>
public static string ToDisplayNameAttribute(this Enum en)
{
return en.GetType().GetMember(en.ToString()).First().GetCustomAttribute<DisplayAttribute>().GetName();
}
}
}

Resources