Skip to content

Instantly share code, notes, and snippets.

View kristoferdoman's full-sized avatar

Kristofer Doman kristoferdoman

  • Canada
View GitHub Profile
@kristoferdoman
kristoferdoman / sumObjectPropertyNestedInArray.php
Last active August 26, 2016 18:39
Php: Sum Property of an Object Collection in a Nested Object Array
<?php
$object = new Object();
$count = array_sum(array_map(function($x) {
$count = array_sum(array_map(function($y) { return count($y->propertyOfAnotherObject); }, $x->anotherObjectInsideObject));
return $count;
}, $object));
?>
@kristoferdoman
kristoferdoman / objectToDictionary.vb
Last active August 26, 2016 18:40
VB.Net: Object to Dictionary
Public Function ToDictionary() As Dictionary(Of String, Object)
Dim dictionary As Dictionary(Of String, Object) = New Dictionary(Of String, Object)
For Each property_info As Reflection.PropertyInfo In [GetType].GetProperties()
Try
Console.WriteLine("name: " + property_info.Name + " value: " + property_info.GetValue(Me, Nothing).ToString)
dictionary.Add(property_info.Name, property_info.GetValue(Me, Nothing).ToString)
Catch ex As Exception
dictionary.Add(property_info.Name, ex.Message)
End Try