internal static void AddClientProxyAssembly(Assembly assembly) { lock (ScriptTypeMap.s_lock) { if (!ScriptTypeMap.s_loadedAssemblies.ContainsKey(assembly.FullName)) { Type[] types = assembly.GetTypes(); for (int i = 0; i < types.Length; i++) { Type type = types[i]; //Edited for .NET Core //if (type.IsClass) if (type.GetTypeInfo().IsClass) { //Edited for .NET Core //object[] customAttributes = type.GetCustomAttributes(typeof(ScriptTypeAttribute), false); object[] customAttributes = type.GetTypeInfo().GetCustomAttributes <ScriptTypeAttribute>().ToArray(); if (customAttributes.Length > 0) { ScriptTypeAttribute scriptTypeAttribute = (ScriptTypeAttribute)customAttributes[0]; //Edited for .NET Core //if (!string.IsNullOrEmpty(scriptTypeAttribute.ScriptType) && typeof(IFromJson).IsAssignableFrom(type)) if (!string.IsNullOrEmpty(scriptTypeAttribute.ScriptType) && typeof(IFromJson).GetTypeInfo().IsAssignableFrom(type)) { ScriptTypeMap.ScriptTypeInfo value = new ScriptTypeMap.ScriptTypeInfo(type, scriptTypeAttribute.ValueObject); ScriptTypeMap.s_clientProxies[scriptTypeAttribute.ScriptType] = value; if (!string.IsNullOrEmpty(scriptTypeAttribute.TypeAlias)) { ScriptTypeMap.s_clientProxies[scriptTypeAttribute.TypeAlias] = value; } ScriptTypeMap.s_typeToScriptTypeMap[type] = value; } } } } //Edited for .NET Core //object[] customAttributes2 = assembly.GetCustomAttributes(typeof(ClientTypeAssemblyAttribute), false); object[] customAttributes2 = assembly.GetCustomAttributes <ClientTypeAssemblyAttribute>().ToArray(); if (customAttributes2 != null || customAttributes2.Length != 0) { ClientTypeAssemblyAttribute clientTypeAssemblyAttribute = (ClientTypeAssemblyAttribute)customAttributes2[0]; if (clientTypeAssemblyAttribute.ScriptTypeFactory != null) { IScriptTypeFactory scriptTypeFactory = Activator.CreateInstance(clientTypeAssemblyAttribute.ScriptTypeFactory) as IScriptTypeFactory; if (scriptTypeFactory != null) { ScriptTypeMap.s_scriptTypeFactories.Add(scriptTypeFactory); } } } ScriptTypeMap.s_loadedAssemblies[assembly.FullName] = null; } } }
private static string GetServerTypeId(Type type) { //Edited for .NET Core //ScriptTypeAttribute scriptTypeAttribute = (ScriptTypeAttribute)Attribute.GetCustomAttribute(type, typeof(ScriptTypeAttribute)); ScriptTypeAttribute scriptTypeAttribute = type.GetTypeInfo().GetCustomAttribute <ScriptTypeAttribute>(); if (scriptTypeAttribute == null) { return(null); } return(scriptTypeAttribute.ServerTypeId); }
internal static void GetTypeNameOrTypeId(Type type, out string typeName, out string typeId) { typeName = null; typeId = null; //Edited for .NET Core //if (type.IsEnum) if (type.GetTypeInfo().IsEnum) { type = Enum.GetUnderlyingType(type); } if (type.GetTypeInfo().IsPrimitive || type == typeof(string) || type == typeof(decimal) || type == typeof(DateTime)) { typeName = DataConvert.GetTypeName(type); return; } //Edited for .NET Core //ScriptTypeAttribute scriptTypeAttribute = (ScriptTypeAttribute)Attribute.GetCustomAttribute(type, typeof(ScriptTypeAttribute)); ScriptTypeAttribute scriptTypeAttribute = type.GetTypeInfo().GetCustomAttribute <ScriptTypeAttribute>(); if (scriptTypeAttribute != null) { typeId = scriptTypeAttribute.ServerTypeId; } }