Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,16 @@ public override BoundNode VisitThrowExpression(ThrowExpressionSyntax node)
throw new NotSupportedException("UdonSharp does not support throwing exceptions since Udon does not have support for exception throwing at the moment", node);
}

public override BoundNode VisitConstructorDeclaration(ConstructorDeclarationSyntax node)
{
if (node.ExpressionBody is ArrowExpressionClauseSyntax arrowExpressionClause)
{
return VisitArrowExpressionClause(arrowExpressionClause);
}

return VisitBlock(node.Body);
}

public override BoundNode VisitArrowExpressionClause(ArrowExpressionClauseSyntax node)
{
return VisitExpression(node.Expression);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ public override void Bind(BindContext context)
}
else if (declaringSyntax is ConstructorDeclarationSyntax constructorDeclaration)
{
MethodBody = bodyVisitor.Visit(constructorDeclaration.Body);
MethodBody = bodyVisitor.VisitConstructorDeclaration(constructorDeclaration);
}
else
{
Expand Down
42 changes: 24 additions & 18 deletions Packages/com.merlin.UdonSharp/Runtime/UdonSharpRuntimeUtils.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Runtime.CompilerServices;
using System.Security.Cryptography;
using System.Text;
Expand All @@ -11,28 +11,34 @@ namespace Internal
{
public static class UdonSharpInternalUtility
{
public static long GetTypeID(System.Type type)
public static long GetTypeID(Type type)
{
return GetTypeID(type.FullName);
}
public static long GetTypeID(string typeName)

public static long GetTypeID(string fullTypeName)
{
SHA256 typeHash = new SHA256CryptoServiceProvider();
byte[] hash = typeHash.ComputeHash(Encoding.UTF8.GetBytes(typeName));
return BitConverter.ToInt64(hash, 0);
// the documentation recommends against utilizing SHA256CryptoServiceProvider
// but the Create method of the base type instead.

// the 'using' keyword is to make sure the SHA256 object is disposed at the end of scope.
using SHA256 sha = SHA256.Create();

byte[] hash = sha.ComputeHash(Encoding.UTF8.GetBytes(fullTypeName));

return BitConverter.ToInt64(hash);
}

public static string GetTypeName(System.Type type)
public static string GetTypeName(Type type)
{
return type.Name;
}

public static bool IsUserDefinedType<T>()
{
throw new InvalidOperationException("This method can only be called in the Udon runtime");
}

/// <summary>
/// Checks if the type T is a user-defined type with an overridden Equals method.
/// </summary>
Expand All @@ -52,25 +58,25 @@ public static long GetTypeID<T>()
}

// These may be extended in the future to handle the edge cases with type names
public static string GetTypeName(System.Type type)
public static string GetTypeName(Type type)
{
return Internal.UdonSharpInternalUtility.GetTypeID(type);
return Internal.UdonSharpInternalUtility.GetTypeName(type);
}

//public static string GetTypeNamespace(System.Type type)
//{
// return type.Namespace;
//}
/*public static string GetTypeNamespace(Type type)
{
return type.Namespace;
}*/

// Placeholder stubs, won't give valid info unless used in the Udon runtime
public static int GetUdonScriptVersion()
{
return 0;
}

public static System.DateTime GetLastCompileDate()
public static DateTime GetLastCompileDate()
{
return System.DateTime.Now;
return DateTime.Now;
}

public static string GetCompilerVersionString()
Expand Down