mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 02:50:32 +00:00
Weaver ImplementsInterface is now an extension. Easier usage and less magic in Weaver.cs
This commit is contained in:
parent
750f94eab8
commit
1643444a9b
@ -39,5 +39,32 @@ public static bool IsDerivedFrom(this TypeDefinition td, TypeReference baseClass
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static bool ImplementsInterface(this TypeDefinition td, TypeReference baseInterface)
|
||||
{
|
||||
TypeDefinition typedef = td;
|
||||
while (typedef != null)
|
||||
{
|
||||
foreach (InterfaceImplementation iface in typedef.Interfaces)
|
||||
{
|
||||
if (iface.InterfaceType.FullName == baseInterface.FullName)
|
||||
return true;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
TypeReference parent = typedef.BaseType;
|
||||
typedef = parent == null ? null : parent.Resolve();
|
||||
}
|
||||
catch (AssemblyResolutionException)
|
||||
{
|
||||
// this can happen for pluins.
|
||||
//Console.WriteLine("AssemblyResolutionException: "+ ex.ToString());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
@ -17,7 +17,7 @@ public static bool ImplementsSyncObject(TypeReference typeRef)
|
||||
return false;
|
||||
}
|
||||
|
||||
return Weaver.ImplementsInterface(typeRef.Resolve(), Weaver.SyncObjectType);
|
||||
return typeRef.Resolve().ImplementsInterface(Weaver.SyncObjectType);
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
@ -295,7 +295,7 @@ public static void ProcessSyncVars(TypeDefinition td, List<FieldDefinition> sync
|
||||
return;
|
||||
}
|
||||
|
||||
if (Weaver.ImplementsInterface(fd.FieldType.Resolve(), Weaver.SyncObjectType))
|
||||
if (fd.FieldType.Resolve().ImplementsInterface(Weaver.SyncObjectType))
|
||||
{
|
||||
if (fd.IsStatic)
|
||||
{
|
||||
|
@ -1423,34 +1423,6 @@ static bool IsNetworkBehaviour(TypeDefinition td)
|
||||
return td.IsDerivedFrom(NetworkBehaviourType);
|
||||
}
|
||||
|
||||
public static bool ImplementsInterface(TypeDefinition td, TypeReference baseInterface)
|
||||
{
|
||||
TypeDefinition typedef = td;
|
||||
|
||||
while ( typedef != null)
|
||||
{
|
||||
foreach (InterfaceImplementation iface in typedef.Interfaces)
|
||||
{
|
||||
if (iface.InterfaceType.FullName == baseInterface.FullName)
|
||||
return true;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
TypeReference parent = typedef.BaseType;
|
||||
typedef = parent == null ? null : parent.Resolve();
|
||||
}
|
||||
catch (AssemblyResolutionException)
|
||||
{
|
||||
// this can happen for pluins.
|
||||
//Console.WriteLine("AssemblyResolutionException: "+ ex.ToString());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static bool IsValidTypeToGenerate(TypeDefinition variable)
|
||||
{
|
||||
// a valid type is a simple class or struct. so we generate only code for types we dont know, and if they are not inside
|
||||
|
Loading…
Reference in New Issue
Block a user