Is is possible to make helpers private in WebMatrix? - helper

I've created my own data grid helper in WebMatrix. The paging and sorting links are helpers too, but I don't really want to expose those helpers publicly to the rest of the app.
For example:
#helper Pager(IEnumerable<dynamic> gridData,
int totalRows, int currentPage, int rowsPerPage)
{
// Helper code is here.
}
Is there any way to make a helper private? Would that be a bad practice, anyway? I know there are private functions, but helpers are handy from a syntactic standpoint.

Using the #helper syntax means that your helper method will automatically get compiled to a public static method. So the answer to your question is no.

One way is to create a library and reference it in your web.config or .cshtml file.
helpers bascially output the html you need/want, essentially htmlhelpers return an html string. You would have to move all your code out into the library and its separate from your main app.

Related

Android Studio Can I save the javadoc comments to an external file

Is it possible to write javadoc comments in a seperate file.
My usual method for writing comments is like below
/**
*#param name person name
*/
private void testMethod(String name) {
//something to do...
}
Is it possible to move all these embedded comments to a external file(s) that i can reference.It should still show the popup on mouse-over.
No, this is not possible. The main idea behind Javadoc is to keep code and documentation together to increase the likelihood that they stay in sync.

How to avoid constructor to be call twice when a page is define twice in a page

I am creating a winRt app. In which I am having a Home.xaml page which having a another page called Market.xaml. So for snapped mode the same code is repeated.
Now my itemListView (used for snapped) and itemGridView (for full view) both have this page (Market)
<views:Market x:Name="viewMarket"/>
And the constructor of this page is called twice which I not want.
So do I use some flag kind of thing or some better approach is there.
Thanks
So, let's talk about this:
XAML is basically a varying syntax to C#. So, when XAML references a control like your views:Market with <Views:Market />, you are actually putting in something like new Views.Market() in both places. Basically, invoking the class twice. Should the constructor not fire twice, the time-space continuum would split in half. Dogs and cats living together, the whole 9 yards.
But, more fundamental here, what is the purpose of the constructor in C#, or in a XAML class? Is to do expensive things that you would not want to repeat? No. The reason for this is because the completion of the constructor is necessary before the UI thread is released and allowed to render the control. The resulting effect is a UI hang.
Moreover, the C# constructor is a synchronous method. It cannot properly invoke or hold asynchronous operations. This means long-running or expensive tasks that should be invoked immediately, should not be invoked in the constructor because it would also require them to be synchronous and UI-blocking. It is because of these last two points I suspect your constructor is being misused.
The solution is in the XAML framework. The XAML Page pipeline includes the constructor (since it is a C# class and they all have it) but it also includes a Loaded event. In many cases, the hard work necessary to fill page controls is in the Loaded handler. This allows the page to render properly, then starts the long-running action that will ultimately and asynchronously update control content.
In WinRT, the Page pipeline also includes an OnNavigatedTo() virtual method in the base that you can override to the same effect. In the override you can include the hard work of talking to a service, deserializing from a file, or whatever you need to make your UI work. Both the Loaded event and the override can be asynchronous, and neither prevent rendering by freezing the constructor.
But, there's another thing to consider since we're in C# and that the rather common pattern called singleton that allows for us to reference a type in two different contexts but without creating a brand new class. This is accomplished by making the class constructor private, but exposing a public property usually called Instance that returns a single, shared instances in some static place.
That might solve your problem already. Then again, none of that is probably what you need. Assuming you already know all that, the quick answer is you can't prevent a constructor because a constructor is necessary to create a new instantiation of any class, including a XAML view. Instead, whatever you are trying to prevent being double might need to be a combination of the discussions above. An offloaded method, and a static reference to prevent duplicate efforts.
Something like this:
public class Market : UserControl
{
public Market()
{
Loaded += Market_Loaded;
}
static bool AlreadyLoaded = false;
void Market_Loaded(object sender, RoutedEventArgs e)
{
if (AlreadyLoaded)
return;
AlreadyLoaded = true;
// TODO: your work
}
}
But that might not do it for you because the static variable is scoped too large. Instead, you can control if it does the big operation with a dependency property you add to your control. With a boolean dependency property set to false, the second control knows not to do something. With it set to true, the first knows to go ahead. And, so on. This prevents all future use of the view or user control in your app from thinking it should not run because of the static property in the above solution. Then again, that might be perfect.
Best of luck!

Menus in Unity3D, using UnityScript and subclasses

I am trying to set up a generic class that deals with menus within Unity3D.
The following code I intend to attach to an empty game object
import System.Collections.Generic;
#pragma strict
public enum MenuType { loadSceneOnMouseDown, enableGameObject, changeValue };
public class MenuClass extends System.Object
{
public var menuObject : GameObject;
public var menuType : MenuType;
}
public var menuItems = List.<MenuClass>();
This results in the following within the editor:
I want each menu type to have its own parameter, so in this example I want the "loadSceneOnMouseDown" to have another public variable as a string defining the name of the scene to be loaded, once loadSceneOnMouseDown is selected from the enum. Whereas I want the "enableGameObject" Type to have a gameobject as a public var. However I dont want both to appear in both fields. For example I could make it like this:
public class MenuClass extends System.Object
{
public var menuObject : GameObject;
public var menuType : MenuType;
public var sceneName : String
public var targetObject : GameObject
}
But that would make it come under each element of the list. I considered doing a further subclass to resolve this, but then with the line "public var menuItems = List.();" that wouldnt work. (or would it? :D)
Apologies if I have been unclear, trying my best here but Im finding it difficult. Theres probably a very simple solution, or im going about thins entirely the wrong way. Any help with this problem would be very much appreciated!
Thanks!
Unity's serialization doesn't really support polymorphism. A list of type MenuClass can technically contain subclassed objects at runtime, but as far as serializing the list Unity is going to assume they are all objects of the base type.
It's a bit inconvenient, sometimes.
There are a few popular workarounds:
Leave all of the possible fields serialized MenuClass, then write a custom inspector which exposes only the relevant fields while you're working. In simple cases like yours, this is often the quickest solution.
Serialize some basic data fields, then use that data to reconstruct your more elaborate objects at runtime. For example, Unity can't serialize a Dictionary, but it can serialize two lists which you stitch back together. Handy, still simple, has some limits.
Build in some custom serialization library, and go nuts with it. Popular choices include JsonFx, MiniJson, Protobufs, and C#'s built-in XML serialization. Lots of work, but very powerful.
Like I said, in your case I'd recommend starting with the custom inspector, if you think that'll cover your needs.
Aside from code that's in most common tutorials, you could switch based on that control value, then call functions like EditorGUILayout.FloatField(), EditorGUILayout.ObjectField() and their cousins to get data.
Custom editor scripting is often overlooked, but it's one of the most powerful features available to Unity developers.

Swap RootViewController with MVVMCross

I need to implement a login/logout using MVVMCross, iOS only to start. After the user logs in, I want to close the view and make the "real" first view the root controller. For logout, I want to do the same in reverse. Whenever the LoginViewModel is requested, clear the root and replace it.
This Remove ViewController from stack indicates there is a ClearTop parameter, but it looks like it is gone in v3?
I then found this What is the best way to handle GoBack for the different MvvmCross (v3) platforms and I implemented this Presenter:
public override void Close(IMvxViewModel toClose)
{
if (toClose is LoginViewModel)
{
ClearBackStack();
Show(new MvxViewModelRequest() { ViewModelType = typeof(FirstViewModel)});
return;
}
base.Close(toClose);
}
public override void Show(MvxViewModelRequest request)
{
if (request.ViewModelType == typeof (LoginViewModel))
{
ClearBackStack();
}
base.Show(request);
}
Is this the correct way to handle this? Is there an easier mechanism (pre-v3 like)? Should I be overriding ChangePresentation instead?
Also, is there a mechanism to call ShowViewModel from a View? Do I need to resolve the IMvxViewDispatcher or is there a more straight forward method?
Yes, if you want to do custom presentation techniques then the easiest way is to implement your own view presenter.
For an introduction and some links on this, see How can I implement SplitView in another view in MvvmCross?
You are free to write code directly in your views, including navigation logic using resolved IoC objects. However, mvvmCross tries to encourage you to put this logic in the viewmodels - especially so that the 'logic' is more easily shared between platforms.

Sharepoint-customizing usercontrol property in smartpart

If anyone is having idea how to customize properties in a smartpart. I have created usercontrol and i m wrappin it in a smartpart.I want to upload my xml from Document library.
private string feedXML;
[Browsable(true),
Personalizable(true) ]
public string FeedXML
{
get
{ return feedXML; }
set
{ feedXML = value; }
}
and I am using this like
//
feedXML="\customxml.xml";
XPathDocument doc = new XPathDocument(Server.MapPath(feedXML));
but this thing is not working . When I am clicking on modify shared webpart of sharepoint page is not rendering. Any clue where I m getting wrong.
You might want to verify the result of your server.mappath statement. It will be something like C:\Inetpub...
So your code is trying to retrieve a file from the filesystem that really lives in SharePoint because you have uploaded it to a Document Library.
If you want that file you'll have to retrieve it using the SharePoint object model, have a look at the GetFileAsString method.
I agree with Denni..
Seems like Smartpart is only making it more difficult? What advantages does it have?
I make my own webpart containers for ascx controls.. very little work and all the control you need. No problems with trust settings either.
Are you sure this is correct?
feedXML="\customxml.xml";
Perhaps, what you want is:
feedXML="\\customxml.xml"; //escape the back-slash.
or
feedXML="/customxml.xml"; // use the forward-slash.
Anyway, if you just want to wrap your user control inside a Web part, you don't need the SmartPart. You can write your custom Web part yourself quite easily.

Resources