NHibernate Entity code conversion from #C to VB.Net
Posted
by
CoderRoller
on Stack Overflow
See other posts from Stack Overflow
or by CoderRoller
Published on 2011-01-12T16:44:40Z
Indexed on
2011/01/12
16:53 UTC
Read the original article
Hit count: 165
Hello and thanks for your help in advance.
I am starting on the NHibernate world and i am experimenting with the NHibernate CookBook recipes, i am trying to set a base entity class for my entities and this is the C# code for this. I would like to know whats the VB.NET version so i can implement it in my sample project.
This is the C# code:
public abstract class Entity<TId>
{
public virtual TId Id { get; protected set; }
public override bool Equals(object obj)
{
return Equals(obj as Entity<TId>);
}
private static bool IsTransient(Entity<TId> obj)
{
return obj != null &&
Equals(obj.Id, default(TId));
}
private Type GetUnproxiedType()
{
return GetType();
}
public virtual bool Equals(Entity<TId> other)
{
if (other == null)
return false;
if (ReferenceEquals(this, other))
return true;
if (!IsTransient(this) && !IsTransient(other) && Equals(Id, other.Id))
{
var otherType = other.GetUnproxiedType();
var thisType = GetUnproxiedType();
return thisType.IsAssignableFrom(otherType) ||
otherType.IsAssignableFrom(thisType);
}
return false;
}
public override int GetHashCode()
{
if (Equals(Id, default(TId)))
return base.GetHashCode();
return Id.GetHashCode();
}
}
I tried using an online converter but puts a Nothing reference in place of default(TId) that doesn't seem right to me that's why I request for help:
Private Shared Function IsTransient(obj As Entity(Of TId)) As Boolean
Return obj IsNot Nothing AndAlso Equals(obj.Id, Nothing)
End Function
I Would appreciate the insight you may give me on the subject.
© Stack Overflow or respective owner