Skip to content
Merged
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
26 changes: 26 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
root = true

[*]
charset = utf-8

[*.cs]
# spacing rules
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
indent_style = space
indent_size = 4

# formatting rules
dotnet_style_qualification_for_field = false:error
dotnet_style_qualification_for_property = false:error
dotnet_style_qualification_for_method = false:error
dotnet_style_qualification_for_event = false:error
dotnet_style_predefined_type_for_locals_parameters_members = true:error
dotnet_style_predefined_type_for_member_access = true:error
dotnet_style_require_accessibility_modifiers = always:error
csharp_style_var_when_type_is_apparent = true:error
csharp_prefer_braces = true:error
csharp_using_directive_placement = outside_namespace:error
Comment on lines +14 to +24

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

setting verbosity levels to "error" gives us --fix-style error ability, which basically means dotnet-format would fix them for us automatically as it did here in this PR.


# naming rules
156 changes: 128 additions & 28 deletions com.unity.multiplayer.mlapi/Editor/CodeGen/CodeGenHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ public static uint Hash(this MethodDefinition methodDefinition)

public static bool IsSubclassOf(this TypeDefinition typeDefinition, string ClassTypeFullName)
{
if (!typeDefinition.IsClass) return false;
if (!typeDefinition.IsClass)
{
return false;
}

var baseTypeRef = typeDefinition.BaseType;
while (baseTypeRef != null)
Expand All @@ -78,7 +81,10 @@ public static bool IsSubclassOf(this TypeDefinition typeDefinition, string Class

public static bool HasInterface(this TypeReference typeReference, string InterfaceTypeFullName)
{
if (typeReference.IsArray) return false;
if (typeReference.IsArray)
{
return false;
}

try
{
Expand All @@ -97,45 +103,139 @@ public static bool IsSerializable(this TypeReference typeReference)
var typeSystem = typeReference.Module.TypeSystem;

// C# primitives
if (typeReference == typeSystem.Boolean) return true;
if (typeReference == typeSystem.Char) return true;
if (typeReference == typeSystem.SByte) return true;
if (typeReference == typeSystem.Byte) return true;
if (typeReference == typeSystem.Int16) return true;
if (typeReference == typeSystem.UInt16) return true;
if (typeReference == typeSystem.Int32) return true;
if (typeReference == typeSystem.UInt32) return true;
if (typeReference == typeSystem.Int64) return true;
if (typeReference == typeSystem.UInt64) return true;
if (typeReference == typeSystem.Single) return true;
if (typeReference == typeSystem.Double) return true;
if (typeReference == typeSystem.String) return true;
if (typeReference == typeSystem.Boolean)
{
return true;
}

if (typeReference == typeSystem.Char)
{
return true;
}

if (typeReference == typeSystem.SByte)
{
return true;
}

if (typeReference == typeSystem.Byte)
{
return true;
}

if (typeReference == typeSystem.Int16)
{
return true;
}

if (typeReference == typeSystem.UInt16)
{
return true;
}

if (typeReference == typeSystem.Int32)
{
return true;
}

if (typeReference == typeSystem.UInt32)
{
return true;
}

if (typeReference == typeSystem.Int64)
{
return true;
}

if (typeReference == typeSystem.UInt64)
{
return true;
}

if (typeReference == typeSystem.Single)
{
return true;
}

if (typeReference == typeSystem.Double)
{
return true;
}

if (typeReference == typeSystem.String)
{
return true;
}

// Unity primitives
if (typeReference.FullName == UnityColor_FullName) return true;
if (typeReference.FullName == UnityColor32_FullName) return true;
if (typeReference.FullName == UnityVector2_FullName) return true;
if (typeReference.FullName == UnityVector3_FullName) return true;
if (typeReference.FullName == UnityVector4_FullName) return true;
if (typeReference.FullName == UnityQuaternion_FullName) return true;
if (typeReference.FullName == UnityRay_FullName) return true;
if (typeReference.FullName == UnityRay2D_FullName) return true;
if (typeReference.FullName == UnityColor_FullName)
{
return true;
}

if (typeReference.FullName == UnityColor32_FullName)
{
return true;
}

if (typeReference.FullName == UnityVector2_FullName)
{
return true;
}

if (typeReference.FullName == UnityVector3_FullName)
{
return true;
}

if (typeReference.FullName == UnityVector4_FullName)
{
return true;
}

if (typeReference.FullName == UnityQuaternion_FullName)
{
return true;
}

if (typeReference.FullName == UnityRay_FullName)
{
return true;
}

if (typeReference.FullName == UnityRay2D_FullName)
{
return true;
}

// Enum
if (typeReference.GetEnumAsInt() != null) return true;
if (typeReference.GetEnumAsInt() != null)
{
return true;
}

// INetworkSerializable
if (typeReference.HasInterface(INetworkSerializable_FullName)) return true;
if (typeReference.HasInterface(INetworkSerializable_FullName))
{
return true;
}

// Static array
if (typeReference.IsArray) return typeReference.GetElementType().IsSerializable();
if (typeReference.IsArray)
{
return typeReference.GetElementType().IsSerializable();
}

return false;
}

public static TypeReference GetEnumAsInt(this TypeReference typeReference)
{
if (typeReference.IsArray) return null;
if (typeReference.IsArray)
{
return null;
}

try
{
Expand Down Expand Up @@ -193,4 +293,4 @@ public static AssemblyDefinition AssemblyDefinitionFor(ICompiledAssembly compile
return assemblyDefinition;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ public InMemoryAssembly InMemoryAssembly
}
}
}
#endif
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ public abstract class ILPostProcessor
public abstract ILPostProcessor GetInstance();
}
}
#endif
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,10 @@ void WriteAssembly(InMemoryAssembly inMemoryAssembly, string outputPath, string
foreach (var i in s_ILPostProcessors)
{
var result = i.Process(targetCompiledAssembly);
if (result == null) continue;
if (result == null)
{
continue;
}

if (result.Diagnostics.Count > 0)
{
Expand Down
Loading