Enum's can be used more efficiently and economically to describe constant values.
I tend to forget this syntax so here it is:
Example from Chess class. Elegantly describing chess piece using Flags in enum.
[Flags]
public enum PieceE : byte {
/// <summary>No piece</summary>
None = 0,
/// <summary>Pawn</summary>
Pawn = 1,
/// <summary>Knight</summary>
Knight = 2,
/// <summary>Bishop</summary>
Bishop = 3,
/// <summary>Rook</summary>
Rook = 4,
/// <summary>Queen</summary>
Queen = 5,
/// <summary>King</summary>
King = 6,
/// <summary>Mask to find the piece</summary>
PieceMask = 7,
/// <summary>Piece is black</summary>
Black = 8,
/// <summary>White piece</summary>
White = 0,
}
Explicit setting of type and value for Enum
public enum MoveTypeE : byte {
/// <summary>Normal move</summary>
Normal = 0,
/// <summary>Pawn which is promoted to a queen</summary>
PawnPromotionToQueen = 1,
/// <summary>Castling</summary>
Castle = 2,
/// <summary>Prise en passant</summary>
EnPassant = 3,
/// <summary>Pawn which is promoted to a rook</summary>
PawnPromotionToRook = 4,
/// <summary>Pawn which is promoted to a bishop</summary>
PawnPromotionToBishop = 5,
/// <summary>Pawn which is promoted to a knight</summary>
PawnPromotionToKnight = 6,
/// <summary>Pawn which is promoted to a pawn</summary>
PawnPromotionToPawn = 7,
/// <summary>Piece type mask</summary>
MoveTypeMask = 15,
/// <summary>The move eat a piece</summary>
PieceEaten = 16,
/// <summary>Move coming from book opening</summary>
MoveFromBook = 32
}
Mar 11, 2013
Feb 21, 2013
Feb 14, 2013
OData - Data query protocol standard
International effort to standardize way data is queried / accessed in web apps.
http://www.odata.org/introduction
Here is another one - free open database WEB API accessible:
http://data.worldbank.org/developers
used here:
http://code.msdn.microsoft.com/Introduction-to-HttpClient-4a2d9cee
http://www.odata.org/introduction
Here is another one - free open database WEB API accessible:
http://data.worldbank.org/developers
used here:
http://code.msdn.microsoft.com/Introduction-to-HttpClient-4a2d9cee
Feb 6, 2013
UI Mockup tools
I never can't remember where to find them when you quickly need one.
So here it is.
If you only once had short deadline to deliver UI app mockup then you could use some of these.
http://www.c-sharpcorner.com/blogs/6483/top-tools-for-mockups-and-wireframes.aspx
Free online colaboration tool:
https://trello.com/
So here it is.
If you only once had short deadline to deliver UI app mockup then you could use some of these.
http://www.c-sharpcorner.com/blogs/6483/top-tools-for-mockups-and-wireframes.aspx
Free online colaboration tool:
https://trello.com/
Feb 5, 2013
Representing proper T-SQL string of .NET float & double types
You build a dynamic T-SQL statement in C#.
There is .NET double variable.
You need correct culture independent version of your double variable.
In many European cultures decimal separator is comma and not dot.
So when you pick double value from app.GUI defined by client culture it will be:
1,01
If you inject this in T-SQL statement it is of course invalid.
To workaround this use InvariantCulture.
var result = 1E-1;
string MysqlDoubleString = Convert.ToString(result, System.Globalization.CultureInfo.InvariantCulture);
Please note that above scenario of building dynamic T-SQL is very risky and unsecure since it is prone to SQL injection attacks.
Always use classic ADO.NET SQLParameter class instead.
There is .NET double variable.
You need correct culture independent version of your double variable.
In many European cultures decimal separator is comma and not dot.
So when you pick double value from app.GUI defined by client culture it will be:
1,01
If you inject this in T-SQL statement it is of course invalid.
To workaround this use InvariantCulture.
var result = 1E-1;
string MysqlDoubleString = Convert.ToString(result, System.Globalization.CultureInfo.InvariantCulture);
Please note that above scenario of building dynamic T-SQL is very risky and unsecure since it is prone to SQL injection attacks.
Always use classic ADO.NET SQLParameter class instead.
Jan 29, 2013
Proper referencing Master page props from custom control
Proper referencing Master page props from custom control
ASPX Page has Master page declared.
In Master page there is property IsHistory.
Page has custom control.
Custom control has to get access to IsHistory prop of Master.
Possible solutions:
- Create interface that describes GetIsHistory and implement it on MasterPage. Then from custom control cast Page.Master to interface and obtain prop value
- Alternatively and more object approached:
MasterPage.Init
IsHistory = true;
Page.aspx
<%@ MasterType TypeName="SiteMaster" %>
protected void Page_Init(object sender, EventArgs e)
{
uc1.IsHistory = Master.IsHistory;
}
CustomControl.ascx
public bool IsHistory { get; set; }
<h2><%:IsHistory.ToString()%></h2>
Jan 10, 2013
JQuery / JavaScript code test with markup
When developing Javascript / JQuery code in early phase it tends to be tricky to easily and quickly do some testing.
For experienced in Javascript it is enough FireBug-like plugins in modern browser but in complex projects it can be cumbersome.
Hence some online solutions exist.
http://jsfiddle.net/
http://jsbin.com/
They are quite self-explanatory in purpose.
I can't see how to use them in context of existing complex ASP.NET web forms pages in my website.
Just a quick refresher for a few tricks when using browser developer kits for JQuery testing.
1. Firebug
Open website. Open Firebug window (F12). Select Script tab.
You need to define some breakpoint in your markup inside some JQuery code.
I'm not sure sometimes you need to reload your website (Ctrl+F5) in order to make breakpoint active.
Do action on your website to make Firebug "fire" your new breakpoint.
At this moment you are ready to test your JQuery expression in Console tab of Firebug.
2. Visual Studio + Internet Explorer
From VS 2010 its possible to debug Javascript code.
There is only one catch. Make sure when you first start IE browser session to delete all your History and cookie.
This way you make sure that browser loads latest version of your JS file.
If not you will see in VS your JS file with [dynamic] suffix. This is NOT OK!
It means that VS found cached version of your JS file and is using it to debug.
For experienced in Javascript it is enough FireBug-like plugins in modern browser but in complex projects it can be cumbersome.
Hence some online solutions exist.
http://jsfiddle.net/
http://jsbin.com/
They are quite self-explanatory in purpose.
I can't see how to use them in context of existing complex ASP.NET web forms pages in my website.
Just a quick refresher for a few tricks when using browser developer kits for JQuery testing.
1. Firebug
Open website. Open Firebug window (F12). Select Script tab.
You need to define some breakpoint in your markup inside some JQuery code.
I'm not sure sometimes you need to reload your website (Ctrl+F5) in order to make breakpoint active.
Do action on your website to make Firebug "fire" your new breakpoint.
At this moment you are ready to test your JQuery expression in Console tab of Firebug.
2. Visual Studio + Internet Explorer
From VS 2010 its possible to debug Javascript code.
There is only one catch. Make sure when you first start IE browser session to delete all your History and cookie.
This way you make sure that browser loads latest version of your JS file.
If not you will see in VS your JS file with [dynamic] suffix. This is NOT OK!
It means that VS found cached version of your JS file and is using it to debug.
Subscribe to:
Posts (Atom)