Skip to content

Commit 708b15f

Browse files
authored
Merge pull request #5 from quabug/readable-name
makes option name of derived type more readable.
2 parents e9ba862 + a139c8c commit 708b15f

File tree

4 files changed

+16
-6
lines changed

4 files changed

+16
-6
lines changed

Assets/Sample/MyMonoBehavior.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@
33

44
public interface IMyInterface<T> {}
55
public class MyIntObject : IMyInterface<int> {}
6+
public class MyGenericObject<T> : IMyInterface<T> {}
67
public struct StructWillNotShow : IMyInterface<int> {}
78
public class MyMonoBehavior : MonoBehaviour
89
{
910
[GenericSerializeReference]
1011
public IMyInterface<int> Value { get; set; }
11-
12-
[GenericSerializeReference("_serialized")]
13-
public IMyInterface<int> Foo { get; set; }
14-
private int __Foo;
12+
//
13+
// [GenericSerializeReference("_serialized")]
14+
// public IMyInterface<int> Foo { get; set; }
15+
// private int __Foo;
1516
}

Packages/generic-serialize-reference/Editor/Extensions.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Linq;
4+
using System.Text.RegularExpressions;
45
using Mono.Cecil;
56
using Mono.Cecil.Cil;
67
using Mono.Cecil.Rocks;
@@ -25,6 +26,14 @@ public static int FindLastIndexOf<T>(this IList<T> list, Predicate<T> predicate)
2526
}
2627
}
2728

29+
internal static class ReflectionExtension
30+
{
31+
public static string ToReadableName(this Type type)
32+
{
33+
return type.IsGenericType ? Regex.Replace(type.ToString(), @"(\w+)`\d+\[(.*)\]", "$1<$2>") : type.ToString();
34+
}
35+
}
36+
2837
internal static class CecilExtension
2938
{
3039
public static TypeDefinition ToTypeDefinition<T>(this ModuleDefinition module) =>

Packages/generic-serialize-reference/Editor/GenericSerializeReferenceFieldAttributeDrawer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ private void AddItemToContextMenu(Type type, GenericMenu genericMenuContext, Ser
128128
{
129129
// it must have a BaseType
130130
var assemblyName = type.BaseType.Assembly.ToString().Split('(', ',')[0];
131-
var entryName = type.BaseType + " ( " + assemblyName + " )";
131+
var entryName = type.BaseType.ToReadableName() + " ( " + assemblyName + " )";
132132
genericMenuContext.AddItem(new GUIContent(entryName), false, AssignNewInstanceCommand, new GenericMenuParameterForAssignInstanceCommand(type, property));
133133
}
134134

Packages/generic-serialize-reference/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "com.quabug.generic-serialize-reference",
33
"description": "Automatically alter generic field of SerializeReference into its non-generic form",
4-
"version": "1.1.0",
4+
"version": "1.1.1",
55
"unity": "2020.2",
66
"displayName": "GenericSerializeReference",
77
"samples": [

0 commit comments

Comments
 (0)