public static bool IsDerivedFrom(this TypeDefinition td, Type baseClass) { if (!td.IsClass) { return(false); } // are ANY parent classes of baseClass? TypeReference parent = td.BaseType; if (parent == null) { return(false); } if (parent.Is(baseClass)) { return(true); } if (parent.CanBeResolved()) { return(IsDerivedFrom(parent.Resolve(), baseClass)); } return(false); }
public static void GetParents(this TypeDefinition type, IList <TypeDefinition> parentsList, Predicate <TypeDefinition> predicate = null) { parentsList.Clear(); // Go until we hit a null base type. TypeReference baseType = type.BaseType; while (baseType != null) { // Stop if it basically doesn't exist. if (!baseType.CanBeResolved()) { break; } // Check if it's a valid type and doesn't implement IGetComponent. TypeDefinition resolved = baseType.Resolve(); if (predicate != null) { if (predicate(resolved)) { parentsList.Add(resolved); } } else { parentsList.Add(resolved); } // Go to the next base type. baseType = resolved.BaseType; } }
// https://github.com/vis2k/Mirror/blob/master/Assets/Mirror/Editor/Weaver/Extensions.cs#L23 public static bool IsSubclassOf(this TypeDefinition td, Type type) { if (!td.IsClass) { return(false); } TypeReference parent = td.BaseType; if (parent == null) { return(false); } if (parent.Is(type)) { return(true); } if (parent.CanBeResolved()) { return(IsSubclassOf(parent.Resolve(), type)); } return(false); }
public static bool TryResolve(this TypeReference td, out TypeDefinition type) { if (td.CanBeResolved()) { type = td.Resolve(); return(true); } type = null; return(false); }
private void GenerateReadersWriters(TypeReference parameterType, SequencePoint sequencePoint) { if (!parameterType.IsGenericParameter && parameterType.CanBeResolved()) { TypeDefinition typeDefinition = parameterType.Resolve(); if (typeDefinition.IsClass && !typeDefinition.IsValueType) { MethodDefinition constructor = typeDefinition.GetMethod(".ctor"); bool hasAccess = constructor.IsPublic || constructor.IsAssembly && typeDefinition.Module == module; if (!hasAccess) { return; } } writers.GetWriteFunc(parameterType, sequencePoint); readers.GetReadFunc(parameterType, sequencePoint); } }
private static void GenerateReadersWriters(ModuleDefinition module, TypeReference parameterType) { if (!parameterType.IsGenericParameter && parameterType.CanBeResolved()) { TypeDefinition typeDefinition = parameterType.Resolve(); if (typeDefinition.IsClass && !typeDefinition.IsValueType) { MethodDefinition constructor = typeDefinition.GetMethod(".ctor"); bool hasAccess = constructor.IsPublic || constructor.IsAssembly && typeDefinition.Module == module; if (!hasAccess) { return; } } parameterType = module.ImportReference(parameterType); Writers.GetWriteFunc(parameterType); Readers.GetReadFunc(parameterType); } }