Posts

Adding an Obsolete Attribute to Class Methods in C#

As a developer we normally maintain our own framework, our own abstraction of things, be it database wrappers, our own implementations of persistence managers, in some cases we figure out a better way or new way of doing things so we decide to include it in the framework, how do we now tell other developers to use this instead of the old one? The answer is the Obsolete Attribute. 1 2 3 4 5 6 7 8 9 [Obsolete("ExpandoObject.CreateObject is deprecated, please use NameValueCollection.CreateObject instead.", true)] public static void CreateObject ( this ExpandoObject that, NameValueCollection querystring) { querystring.AllKeys.ToList().ForEach(x => { if (!that.ToDictionary(y => y.Key).ContainsKey(x)) ((IDictionary< string , object >)that)[x] = querystring[x]; }); } We simply add this attribute on top of the method or class and specify our message. BTW, the Boolean parameter if set to True, will throw and exceptio...

My First Android App Published in Google Play

Image
I decided to retool myself in Java Android Development few months back, here's the first product for a local company here in Manila. I will discuss in details the technical stuff involved in the project, a soon as I free myself up from some urgent task.

Serializing JSON string to ExpandoObject

In some case you want to create and Object from JSON, a great way of doing this to deserialize this JSON to an ExpandoObject. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 /// <summary> /// Convert Json String to an Expando Object /// </summary> /// <param name="that">Json string to convert</param> /// <returns>Expando Object</returns> public static ExpandoObject ToExpando ( this string that) { ExpandoObject result; try { result = JsonConvert.DeserializeObject<ExpandoObject>(that, new ExpandoObjectConverter()); } catch (Exception e) { throw e; } return result; } Here we use JsonConvert.DeserializeObject, you need to add reference to NewtonSoft.Json see below. 1 2 3 using Newtonsoft.Json ; using Newtonsoft.Json.Converters ; using Newtonsoft.Json.Linq ;

ProgrammerBase

Every programmer should inherit from ProgrammerBase :) 1 2 3 4 abstract class ProgrammerBase : ILearn, ICode, IConquer { ... }

Inserting Results from a Stored Procedure Call to a Table

This is handy, bumped into this and I thought it would be nice to take note and share. What this code illustrate is that you can basically use a stored procedure's result and insert it into a table and do your own query. Now why do we want to do that? Say for example the existing query does something and is being used by different modules and touching it would require us to check/test those modules that has a dependency on the  SP. Applying the sample below allows us to just reuse the existing SP and get the resulting data and do our own filters, grouping etc.. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 DECLARE @ Table TABLE ( SPID INT , Status VARCHAR ( MAX ), LOGIN VARCHAR ( MAX ), HostName VARCHAR ( MAX ), BlkBy VARCHAR ( MAX ), DBName VARCHAR ( MAX ), Command VARCHAR ( MAX ), CPUTime INT , DiskIO INT , LastBatch VARCHAR ( MAX ), ProgramName VARCHAR ( MAX ),...

ExecuteScalar<T>

 I came across this while working on a existing code from an ISV. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40   public class SomeDBWrapper : IDisposable { public string ExecuteExecuteScalar_String () { object value = this .ExecuteExecuteScalar(); if ( value == DBNull.Value) return "" ; else return ( string ) value ; } public int ExecuteExecuteScalar_Int () { object value = this .ExecuteExecuteScalar(); if ( value == DBNull.Value) return 0 ; else { return Convert.ToInt32( value ); } } public Int64 ExecuteExecuteScalar_Int64 () { object value = this .ExecuteExecuteScalar(); if ( value == DBNull.Value) return 0 ; else return (Int64) value ; } ...

Automatically Discover and Assign Parameter with Values to a Stored Procedure Call in C#

I'm sure most programmers have run across a situation wherein they have to pass  a lot of parameters to a stored procedure call in C#. Instead of manually typing each parameter in and assigning a value, why not develop a way to automatically discover the parameter, add it to the parameter list of the command object and assign the corresponding value from an entity or model. Here's my implementation using extension method. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 /// <summary> /// Automatically assigns parameters to Command.Parameter Collection from List of parameter names /// </summary> /// <param name="that">Command object being extended</param> /// <param name="model">Expando model</param> /// <param name="conn">sQLConnection used to g...