public static string NameType(Type t) { if (TypeNameMap.TryGetValue(t, out var name)) { return(name); } if (t.IsArray) { return($"[{NameType(t.GetElementType()!)}]"); } if (t.IsConstructedGenericType) { return ($"{NameType(t.GetGenericTypeDefinition())}<{string.Join(", ", t.GenericTypeArguments.Select(NameType))}>"); } if (t.IsGenericType) { var n = t.Name; int cutFrom = n.IndexOf('`'); if (cutFrom > 0) { return(n.Substring(0, cutFrom)); } } return(t.Name); }
/// <summary> /// Add a generic argument to the end of the list. /// </summary> public void AddGenericArgument(NetTypeReference argument, TypeNameMap typeNameMap) { if (argument.IsVoid()) { argument = typeNameMap.Object; } genericArguments.Add(argument); }
protected BlockFactory() { //StringBuilder s = new StringBuilder(); //double time = Timer.ms; Assembly[] assemblies = Reflector.GetLoadedAssemblies(); ReadOnlyCollection <SerAttr> types = Reflector.FindTypesWithAttribute <BlockSerializationAttribute>(assemblies); foreach (SerAttr t in types) { //s.AppendLine(t.TypeInfo.Name + " " + t.AttrInfo.Name); TypeNameMap.Add(t.AttrInfo.Name, t.TypeInfo); } //s.AppendLine("Elapsed time: " + (Timer.ms - time).ToString()); //System.Windows.Forms.MessageBox.Show(s.ToString()); }
/// <summary> /// Is the given method an override? /// </summary> private static bool IsOverride(MethodDefinition javaMethod, MethodAttributes attributes, TypeNameMap typeNameMap, out bool isNewSlot) { isNewSlot = false; if (javaMethod.IsOverride()) { return(true); } if (!typeNameMap.HasImportMappings) { return(false); } var superClass = javaMethod.DeclaringClass.SuperClass; if (superClass == null) { return(false); } // If there are bridge methods calling this method we assume to override in the bridge is an override. var bridge = javaMethod.DeclaringClass.Methods.FirstOrDefault(x => IsBridgeFor(x, javaMethod)); if (bridge != null) { bool tmp; if (IsOverride(bridge, attributes, typeNameMap, out tmp)) { return(true); } } // Check typemap var superClassName = superClass.ClassName; string netName; string baseDescriptor; string baseSignature; MethodAttributes methodAttributes; if (!typeNameMap.IsImportedVirtualMethod(superClassName, javaMethod.Name, javaMethod.Descriptor, out methodAttributes, out netName, out baseDescriptor, out baseSignature)) { return(false); } if ((methodAttributes & MethodAttributes.MemberAccessMask) != (attributes & MethodAttributes.MemberAccessMask)) { isNewSlot = true; } return(true); }