Saturday, January 29, 2011

Dynamic casting in c#

var typesSubset = new[] { typeof(decimal), typeof(Int32), typeof(Int64) };

Type someDynamicType = typeof (int);

int someDynamicValue = 777;

if (typesSubset.Any(t => t == someDynamicType))


    object result = Expression.Lambda<Func<object>>(


                               Expression.Constant(someDynamicType), Expression.Constant(someDynamicValue)),

                           typeof (object))).Compile()();


    Console.WriteLine(result); // 777


Pass xml to stored procedure

In C#:

    1 // create XML string

    2 var dataToPass = new StringBuilder("<RowsOfNumbers>");

    3 dataToPass.AppendFormat("<id>{0}</id>", 1);

    4 dataToPass.AppendFormat("<id>{0}</id>", 2);

    5 dataToPass.AppendFormat("<id>{0}</id>", 3);

    6 dataToPass.Append("</RowsOfNumbers>");


    8 // call SP

    9 myDB.ExecuteStoredProcedure("GetXmlData", new object[] { dataToPass.ToString() });


CREATE PROCEDURE [dbo].[GetXmlData]    (@dataIdsXml XML)


    DECLARE @dataIdsTable TABLE (ID int)


    INSERT INTO @dataIdsTable (ID) SELECT ParamValues.ID.value('.','VARCHAR(20)')

    FROM @dataIdsXml.nodes('/RowsOfNumbers/id') as ParamValues(ID)


    SELECT [ID] FROM @dataIdsTable WHERE [ID]=1


Friday, January 28, 2011

Workforce turnover around me (LinkedIn stats)

Following to LinkedIn data 57 out of my 382 contacts changed jobs in 2010.
This is 15%. Probably actual rate is a bit higher since in some cases this info may be not updated in LinkedIn.

Subset of TED lectures on health

(with bits of practical information) – drink coffee, no strikes/box, no avian flue, low pressure, 3 grams of omega-three a day - current crisis and future bionic technology – well once I used nice utility (still downloadable) – Aire Freshner

Just interesting:

Fallen giant

Few photo subsets from this blog:

“Heroic deeds live in eternity” – are they?