Skip to content

Instantly share code, notes, and snippets.

View davybrion's full-sized avatar

Davy Brion davybrion

  • That Extra Mile
  • Belgium
View GitHub Profile
@davybrion
davybrion / s1.rb
Created September 15, 2012 14:53
code snippets for "Using Ruby Classes In C# With IronRuby" post, part II
if defined? IronRuby
def add_dotnet_friendly_method_aliases_for(klass)
klass.public_instance_methods.each do |method|
klass.instance_eval do
dotnet_friendly_name = IronRuby::Clr::Name.unmangle(method)
alias_method dotnet_friendly_name, method unless dotnet_friendly_name.nil? # in this case, it's already a dotnet friendly name
end
end
end
@davybrion
davybrion / s1.rb
Created September 15, 2012 14:50
code snippets for "Using Ruby Classes In C# With IronRuby" post
class Customer
attr_reader :name
attr_reader :email
def initialize(name, email)
@name = name
@email = email
end
end
@davybrion
davybrion / s1.rb
Created September 15, 2012 14:44
code snippets for "Using NHibernate To Persist And Query Ruby Objects" post, part III
class ObjectFactory
def self.create_from_nhibernate_hash(hashtable)
entity_name = hashtable[NHibernator::TYPE_KEY_NAME.to_clr_string]
entity = const_get(entity_name.to_sym).new
entity.hydrate_from hashtable
entity
end
def self.create_proxy_from_nhibernate_hash(hashtable, entity_name, id)
proxy = const_get("#{entity_name}Proxy".to_sym).new
@davybrion
davybrion / s1.cs
Created September 15, 2012 14:37
code snippets for "Using NHibernate To Persist And Query Ruby Objects" post, part II
using (var session = sessionFactory.OpenSession())
{
var artistHash = session.CreateCriteria("Artist")
.Add(Restrictions.IdEq(artistId))
.SetFetchMode("albums", FetchMode.Join)
.List()[0];
dynamic artist = ruby.ObjectFactory.create_from_nhibernate_hash(artistHash);
Console.WriteLine("display output from session.CreateCriteria without any lazy loading");
PrintArtistData(artist);
@davybrion
davybrion / s1.xml
Created September 15, 2012 14:33
code snippets for "Using NHibernate To Persist And Query Ruby Objects" post
<class entity-name="Artist">
<id name="id" column="ArtistId" type="int">
<generator class="identity"/>
</id>
<property name="name" length="50" type="string" />
<bag name="albums" cascade="all-delete-orphan" inverse="true" >
<key column="ArtistId"/>
<one-to-many class="Album" />
@davybrion
davybrion / s1.cs
Created September 15, 2012 14:28
code snippets for "Think Twice Before You Map Entities To DTOs" post
public class AuthorizationDto
{
public long Id { get; set; }
public Guid ApplicationId { get; set; }
public string ApplicationName { get; set; }
public Guid? UserGroupId { get; set; }
public string UserGroupName { get; set; }
public Guid? UserId { get; set; }
public string Username { get; set; }
public Guid PermissionId { get; set; }
@davybrion
davybrion / s1.rb
Created September 15, 2012 14:24
code snippets for "Using More Rubyesq Events In Ruby" post
class Something
include EventPublisher
event :some_event
end
@davybrion
davybrion / s1.rb
Created September 15, 2012 14:18
code snippets for "Using C#-style Events In Ruby" post
class Event
attr_reader :name
def initialize(name)
@name = name
@handlers = []
end
def +(eventhandler)
@davybrion
davybrion / s1.cs
Created September 15, 2012 14:08
code snippets for "MVP In Silverlight/WPF: Automated Tests" post
[TestMethod]
public void SettingNameRaisesPropertyChangedEvent()
{
AssertThatPropertyChangesIsTriggeredCorrectly(m => m.Name, "some name");
}
[TestMethod]
public void SettingNameToInvalidValueCausesValidationError()
{
BindingModel.Name = null;
@davybrion
davybrion / s1.cs
Created September 15, 2012 14:04
code snippets for "MVP In Silverlight/WPF: Implementing The Details UserControl" post
public class UserGroupDetailBindingModel : BindingModel<UserGroupDetailBindingModel>
{
private string originalName;
private Guid? originalId;
private UserGroupDto originalSelectedParent;
public ObservableCollection<UserGroupDto> SuitableParentUserGroups { get; private set; }
private UserGroupDto selectedParentUserGroup;