private static bool AllowRegisterType(Type type) { var typeFlags = AssemblyUtilities.GetAssemblyTypeFlag(type.Assembly); if ((typeFlags & AssemblyTypeFlags.UnityEditorTypes) == AssemblyTypeFlags.UnityEditorTypes) { return(false); } if ((typeFlags & AssemblyTypeFlags.UserEditorTypes) == AssemblyTypeFlags.UserEditorTypes) { return(false); } if (type.IsGenericType) { foreach (var parameter in type.GetGenericArguments()) { if (!AllowRegisterType(parameter)) { return(false); } } } return(true); }
public AboutBox(Form parent, IFormController _controller) : base(_controller) { InitializeComponent(); // Need to tell the utility class that this is the assembly var util = new AssemblyUtilities(Assembly.GetExecutingAssembly()); // Set the form values this.Text = $"About {util.AssemblyTitle}"; this.labelProductVersion.Text = $"V{util.AssemblyVersion}"; this.labelCopyright.Text = util.AssemblyCopyright; //this.labelDescription.Text = util.AssemblyDescription; this.textBoxDescription.Text = util.AssemblyDescription; this.textBoxThirdpartyComponents.Text = _thirdpartyDescription; // Initialize the sourcecode link label this.linkLabelSource.Text = _sourceLink; //this.linkLabelSource.Links.Add(0, _sourceLink.Length, _sourceLink); //this.linkLabelSource.LinkClicked += (o, i) => //{ // linkLabelSource.LinkVisited = true; // System.Diagnostics.Process.Start(_sourceLink); //}; // Initialize the thirdparty link label this.linkLabelThirdparty.Text = _thirdpartyLink; //this.linkLabelThirdparty.Links.Add(0, _thirdpartyLink.Length, _thirdpartyLink); //this.linkLabelThirdparty.LinkClicked += (o, i) => //{ // linkLabelThirdparty.LinkVisited = true; // System.Diagnostics.Process.Start(_thirdpartyLink); //}; //SetTheme(((MainFormController)Controller).UserSettings.ActiveTheme); }
private static Type GetUnityTypeWithName(string name) { if (UnityTypes == null) { UnityTypes = new Dictionary <string, Type>(); foreach (var type in AssemblyUtilities.GetTypes(AssemblyTypeFlags.UnityTypes | AssemblyTypeFlags.UnityEditorTypes) .Where(n => typeof(UnityEngine.Object).IsAssignableFrom(n))) { if (UnityTypes.ContainsKey(type.Name)) { UnityTypes[type.Name] = null; } else { UnityTypes[type.Name] = type; } } } Type result; UnityTypes.TryGetValue(name, out result); return(result); }
public void AssemblyUtilities_LoadFromName() { AssemblyName name = typeof(System.Xml.XmlNode).Assembly.GetName(); Assembly a = AssemblyUtilities.LoadAssembly(name, null); Assert.IsNotNull(a, "Failed to load assembly by name"); }
public void AssemblyUtilities_Bad_Name_Logs() { string logString = null; string expectedErrorMessage = null; string fileName = this.GetType().Assembly.Location + "x"; AssemblyName asmName = null; try { asmName = AssemblyName.GetAssemblyName(fileName); Assembly.Load(asmName); } catch (Exception ex) { expectedErrorMessage = string.Format(CultureInfo.CurrentCulture, Resources.BusinessLogicClass_Failed_Load, fileName, ex.Message); } Assembly a = AssemblyUtilities.LoadAssembly(fileName, (s) => logString = s); Assert.IsNull(a, "Should have failed to load assembly by name"); Assert.IsNotNull(logString, "logger was not called"); Assert.AreEqual(expectedErrorMessage, logString, "unexpected error message"); // Verify a null logger does not throw a = AssemblyUtilities.LoadAssembly(fileName, null); Assert.IsNull(a, "Should have failed to load assembly by name"); }
static AnimationCurveDrawer() { MethodInfo mi = null; var type = AssemblyUtilities.GetTypeByCachedFullName("UnityEditorInternal.AnimationCurvePreviewCache"); if (type != null) { var method = type.GetMethod("ClearCache", Flags.StaticAnyVisibility); var pars = method.GetParameters(); if (pars != null && pars.Length == 0) { mi = method; } } if (mi != null) { clearCache = EmitUtilities.CreateStaticMethodCaller(mi); } #if SIRENIX_INTERNAL else { Debug.LogError("AnimationCurve fix no longer works, has Unity fixed it?"); } #endif }
private void SetTitle() { var util = new AssemblyUtilities(Assembly.GetExecutingAssembly()); string title = $"{util.AssemblyTitle} V{util.AssemblyVersion}"; this.Text = title; }
// customize registration to give a nice name to the cloud provider we represent private static OnDemandLocalFileSystemRegistration GetRegistration() { var reg = new OnDemandLocalFileSystemRegistration(); reg.ProviderName = AssemblyUtilities.GetDescription(); return(reg); }
static CultureInfoCache() { ValidCultureNames = new HashSet <string>(StringComparer.OrdinalIgnoreCase); #if !FEATURE_CULTUREINFO_GETCULTURES if (!AssemblyUtilities.CultureInfoHasGetCultures()) { ValidCultureNames = HardcodedCultureNames; return; } #endif foreach (CultureInfo cultureName in AssemblyUtilities.GetAllCultures()) { ValidCultureNames.Add(cultureName.Name); } // https://docs.microsoft.com/en-gb/windows/desktop/Intl/using-pseudo-locales-for-localization-testing // These pseudo-locales are available in versions of Windows from Vista and later. // However, from Windows 10, version 1803, they are not returned when enumerating the // installed cultures, even if the registry keys are set. Therefore, add them to the list manually. var pseudoLocales = new[] { "qps-ploc", "qps-ploca", "qps-plocm", "qps-Latn-x-sh" }; foreach (string pseudoLocale in pseudoLocales) { ValidCultureNames.Add(pseudoLocale); } }
/// <summary> /// Loads all the named assemblies into a cache of known assemblies /// </summary> private void LoadAssemblies() { _assemblies = new List <Assembly>(); var loadedAssemblies = new Dictionary <string, Assembly>(); //_assemblyFileNames.Reverse(); foreach (string file in _assemblyFileNames) { // Pass 1 -- load all the assemblies we have been given. No referenced assemblies yet. if (file.EndsWith("mscorlib.dll") || file.EndsWith("System.Runtime.dll")) { continue; } var assembly = AssemblyUtilities.ReflectionOnlyLoadFrom(file, _logger); if (assembly != null) { _assemblies.Add(assembly); // Keep track of loaded assemblies for next step loadedAssemblies[assembly.FullName] = assembly; } } // Pass 2 -- recursively load all reference assemblies from the assemblies we loaded. foreach (var assembly in _assemblies) { AssemblyUtilities.ReflectionOnlyLoadReferences(assembly, _assemblySearchPaths, loadedAssemblies, /*recursive*/ true, _logger); } }
public void IdentifyMissingDependencies_OnlyNetstandardMissing() { var results = AssemblyUtilities.IdentifyMissingDependencies(_testFixture.Alpha.Path, new[] { _testFixture.Alpha.Path, _testFixture.Gamma.Path, _testFixture.Delta1.Path }); Assert.Equal(expected: 1, actual: results.Length); Assert.Equal(expected: "netstandard", actual: results[0].Name); }
//[InitializeOnLoadMethod] public static void RemoveObsoleteGeneratedOdinEditorsDLL_InitializeOnLoadMethod() { EditorApplication.delayCall += () => { EditorApplication.delayCall += () => { #if SIRENIX_INTERNAL if (AssemblyUtilities.GetTypeByCachedFullName("Sirenix.Internal.SirenixProduct") != null) { return; } #endif if (EditorPrefs.HasKey("PREVENT_SIRENIX_FILE_GENERATION")) { return; } var generatedOdinEditorsFolder = "Assets/" + SirenixAssetPaths.SirenixAssembliesPath + "Editor"; var generatedOdinEditorsDLL = generatedOdinEditorsFolder + "/GeneratedOdinEditors.dll"; if (File.Exists(generatedOdinEditorsDLL)) { AssetDatabase.DeleteAsset(generatedOdinEditorsDLL); if (File.Exists(generatedOdinEditorsDLL + ".mdb")) { AssetDatabase.DeleteAsset(generatedOdinEditorsDLL + ".mdb"); } AssetDatabase.Refresh(); } }; }; }
public ObjectProperties(object obj, bool readOnly, Action action) { if (obj == null) { throw new ArgumentNullException(nameof(obj)); } DataContext = obj; InitializeComponent(); if (action != null) { Loaded += (sender, e) => OnLoaded(action); } Title = obj + " Properties"; if (obj != null) { var roa = AssemblyUtilities.GetAttribute <ReadOnlyAttribute>(obj.GetType()); PGrid.IsReadOnly = roa != null && roa.IsReadOnly; } if (readOnly) { PGrid.IsReadOnly = true; } PGrid.SelectedObject = obj; if (PGrid.IsReadOnly) { Cancel.Content = "Close"; OK.Visibility = Visibility.Hidden; } }
public PDFOCRController(bool autoRun, string[] args) : base( new PassportPDFDesktopAppInformation( PdfOCRGlobals.PRODUCT_NAME, PdfOCRGlobals.PASSPORT_PDF_APP_ID, PdfOCRGlobals.SOURCE_CODE_LINK, AssemblyUtilities.GetVersion(), Icon.ExtractAssociatedIcon(Assembly.GetExecutingAssembly().Location), Properties.Resources.logo_pdfocrcloud, PdfOCRGlobals.INPUT_FILE_TYPE, PdfOCRGlobals.GetApplicationConfigurationFilePath(), autoRun, args)) { }
private static bool CheckCore( string baseDirectory, IEnumerable <CommandLineAnalyzerReference> analyzerReferences, IAnalyzerAssemblyLoader loader, ICompilerServerLogger?logger, [NotNullWhen(false)] out List <string>?errorMessages) { errorMessages = null; var resolvedPaths = new List <string>(); foreach (var analyzerReference in analyzerReferences) { string?resolvedPath = FileUtilities.ResolveRelativePath(analyzerReference.FilePath, basePath: null, baseDirectory: baseDirectory, searchPaths: SpecializedCollections.EmptyEnumerable <string>(), fileExists: File.Exists); if (resolvedPath != null) { resolvedPath = FileUtilities.TryNormalizeAbsolutePath(resolvedPath); if (resolvedPath != null) { resolvedPaths.Add(resolvedPath); } } // Don't worry about paths we can't resolve. The compiler will report an error for that later. } // Register analyzers and their dependencies upfront, // so that assembly references can be resolved: foreach (var resolvedPath in resolvedPaths) { loader.AddDependencyLocation(resolvedPath); } // Load all analyzer assemblies: var loadedAssemblies = new List <Assembly>(); foreach (var resolvedPath in resolvedPaths) { loadedAssemblies.Add(loader.LoadFromPath(resolvedPath)); } // Third, check that the MVIDs of the files on disk match the MVIDs of the loaded assemblies. for (int i = 0; i < resolvedPaths.Count; i++) { var resolvedPath = resolvedPaths[i]; var loadedAssembly = loadedAssemblies[i]; var resolvedPathMvid = AssemblyUtilities.ReadMvid(resolvedPath); var loadedAssemblyMvid = loadedAssembly.ManifestModule.ModuleVersionId; if (resolvedPathMvid != loadedAssemblyMvid) { var message = $"analyzer assembly '{resolvedPath}' has MVID '{resolvedPathMvid}' but loaded assembly '{loadedAssembly.FullName}' has MVID '{loadedAssemblyMvid}'"; errorMessages ??= new List <string>(); errorMessages.Add(message); } } return(errorMessages == null); }
public void GetAssemblyTitleForAssemblyWithNoAttributes() { var assembly = Substitute.For <ICustomAttributeProvider>(); var title = AssemblyUtilities.GetAssemblyTitle(assembly, "MyAssembly"); title.Should().NotBeNullOrWhiteSpace(); title.Should().Be("MyAssembly"); }
public void ReadMVid() { var assembly = Assembly.Load(File.ReadAllBytes(_testFixture.Alpha.Path)); var result = AssemblyUtilities.ReadMvid(_testFixture.Alpha.Path); Assert.Equal(expected: assembly.ManifestModule.ModuleVersionId, actual: result); }
public static void Register(IServiceCollection services) { services.AddAutoMapper(AssemblyUtilities.GetAssemblies()); var serviceProvider = services.BuildServiceProvider(); Mapper = serviceProvider.GetService <IMapper>(); }
internal static void OpenEditorInOdinDropDown(UnityEngine.Object obj, Rect btnRect) { var odinEditorWindow = AssemblyUtilities.GetTypeByCachedFullName("Sirenix.OdinInspector.Editor.OdinEditorWindow"); odinEditorWindow.GetMethods(Flags.StaticPublic) .First(x => x.Name == "InspectObjectInDropDown" && x.GetParameters().Last().ParameterType == typeof(float)) .Invoke(null, new object[] { obj, btnRect, 400 }); }
/// <summary> /// Binds a name to type. /// </summary> /// <param name="typeName">The name of the type to bind.</param> /// <param name="debugContext">The debug context to log to.</param> /// <returns> /// The type that the name has been bound to, or null if the type could not be resolved. /// </returns> /// <exception cref="System.ArgumentNullException">The typeName argument is null.</exception> public override Type BindToType(string typeName, DebugContext debugContext = null) { if (typeName == null) { throw new ArgumentNullException("typeName"); } Type result; lock (TYPEMAP_LOCK) { if (typeMap.TryGetValue(typeName, out result) == false) { // Looks for custom defined type name lookups defined with the BindTypeNameToTypeAttribute. customTypeNameToTypeBindings.TryGetValue(typeName, out result); // Do more fancy stuff. // Final fallback to classic .NET type string format if (result == null) { result = Type.GetType(typeName); } if (result == null) { result = AssemblyUtilities.GetTypeByCachedFullName(typeName); } // TODO: Type lookup error handling; use an out bool or a "Try" pattern? string typeStr, assemblyStr; ParseName(typeName, out typeStr, out assemblyStr); if (result == null && assemblyStr != null && assemblyNameLookUp.ContainsKey(assemblyStr)) { var assembly = assemblyNameLookUp[assemblyStr]; result = assembly.GetType(typeStr); } if (result == null) { result = AssemblyUtilities.GetTypeByCachedFullName(typeStr); } if (result == null && debugContext != null) { debugContext.LogWarning("Failed deserialization type lookup for type name '" + typeName + "'."); } // We allow null values on purpose so we don't have to keep re-performing invalid name lookups typeMap.Add(typeName, result); } } return(result); }
public void FindAssemblySet_SingleAssembly() { var directory = Temp.CreateDirectory(); var alphaDll = directory.CopyFile(_testFixture.Alpha.Path); var results = AssemblyUtilities.FindAssemblySet(alphaDll.Path); AssertEx.SetEqual(new[] { alphaDll.Path }, results); }
private void DrawOdinInspector() { EnsureInitialized(); if (this.Tree == null) { base.OnInspectorGUI(); return; } else if (this.Tree.RootPropertyCount == 0) { var assemblyTypeFlag = AssemblyUtilities.GetAssemblyTypeFlag(this.target.GetType().Assembly); if (assemblyTypeFlag == AssemblyTypeFlags.UnityTypes || assemblyTypeFlag == AssemblyTypeFlags.UnityEditorTypes) { this.MockUnityGenericInspector(); return; } } #if PREFAB_DEBUG this.PrefabModificationsDebug(); #endif if (Event.current.type == EventType.Layout) { this.tree.DrawMonoScriptObjectField = !ForceHideMonoScriptInEditor && this.tree.UnitySerializedObject != null && this.tree.TargetType != null && GeneralDrawerConfig.Instance.ShowMonoScriptInEditor && !this.tree.TargetType.IsDefined(typeof(HideMonoScriptAttribute), true); } this.DrawTree(); //NetworkBehaviour networkBehaviour = this.target as NetworkBehaviour; //if (networkBehaviour != null && !networkBehaviour.GetType().IsDefined(typeof(HideNetworkBehaviourFieldsAttribute), true)) //{ // EditorGUILayout.LabelField(networkChannelLabel, GUIHelper.TempContent(networkBehaviour.GetNetworkChannel().ToString())); // EditorGUILayout.LabelField(networkSendIntervalLabel, GUIHelper.TempContent(networkBehaviour.GetNetworkSendInterval().ToString())); //} if (UnityNetworkingUtility.NetworkBehaviourType != null && UnityNetworkingUtility.NetworkBehaviourType.IsAssignableFrom(this.target.GetType())) { if (this.target.GetType().IsDefined <HideNetworkBehaviourFieldsAttribute>(true) == false) { EditorGUILayout.LabelField(networkChannelLabel, GUIHelper.TempContent(UnityNetworkingUtility.GetNetworkChannel(this.target as MonoBehaviour).ToString())); EditorGUILayout.LabelField(networkSendIntervalLabel, GUIHelper.TempContent(UnityNetworkingUtility.GetNetworkingInterval(this.target as MonoBehaviour).ToString())); } } this.RepaintWarmup(); this.RepaintIfRequested(); GUIHelper.CurrentWindow.wantsMouseMove = true; }
public void FindSatelliteAssemblies_None() { var directory = Temp.CreateDirectory(); var assemblyFile = directory.CreateFile("FakeAssembly.dll"); var results = AssemblyUtilities.FindSatelliteAssemblies(assemblyFile.Path); Assert.Equal(expected: 0, actual: results.Length); }
public void GetAssemblyTitleForAssemblyWithOnlyCompany() { var assembly = Substitute.For <ICustomAttributeProvider>(); assembly.GetCustomAttributes(typeof(AssemblyCompanyAttribute), true).Returns(new object[] { new AssemblyCompanyAttribute("MyCompany") }); var title = AssemblyUtilities.GetAssemblyTitle(assembly, "MyAssembly"); title.Should().Be("MyCompany MyAssembly"); }
public void FindSatelliteAssemblies_None() { var directory = Temp.CreateDirectory(); var assemblyFile = directory.CreateFile("FakeAssembly.dll"); var results = AssemblyUtilities.FindSatelliteAssemblies(assemblyFile.Path); Assert.Empty(results); }
/// <summary> /// If the given type is defined in a system assembly, returns the type directly, otherwise <c>null</c>. /// </summary> /// <param name="type">The type whose equivalent we need.</param> /// <returns>If the type lives in a system assembly, the input type, else <c>null</c>.</returns> private static Type EquivalentMsCorlibType(Type type) { if (AssemblyUtilities.IsAssemblyMsCorlib(type.Assembly.GetName())) { // For now, only a core set of predefined system types are assumed to be supported return(TypeUtility.IsPredefinedType(type) ? type : null); } return(null); }
public void GetAssemblyIdentity() { var directory = Temp.CreateDirectory(); var alphaDll = directory.CreateFile("Alpha.dll").WriteAllBytes(TestResources.AssemblyLoadTests.Alpha); var result = AssemblyUtilities.GetAssemblyIdentity(alphaDll.Path); Assert.Equal(expected: "Alpha", actual: result.Name); }
static AttributeExampleUtilities() { AttributeRegisterMap = AssemblyUtilities.GetAllAssemblies() .SelectMany(a => a.GetCustomAttributes(typeof(OdinRegisterAttributeAttribute), true)) .Cast <OdinRegisterAttributeAttribute>() .ToDictionary(x => x.AttributeType); AttributeTypes = AttributeRegisterMap.Keys.ToArray(); AttributeIconMap = new Dictionary <Type, Texture>(); }
protected override void BuildSelectionTree(OdinMenuTree tree) { var scriptableObjectTypes = AssemblyUtilities.GetTypes(AssemblyTypeFlags.CustomTypes) .Where(x => x.IsClass && !x.IsAbstract && x.InheritsFrom(typeof(T))); tree.Selection.SupportsMultiSelect = false; tree.Config.DrawSearchToolbar = true; tree.AddRange(scriptableObjectTypes, x => x.GetNiceName()) .AddThumbnailIcons(); }
public AboutBox() { InitializeComponent(); Icon = Program.AppIcon; Text = "About " + AssemblyUtilities.GetDescription(); labelProductName.Text = AssemblyUtilities.GetDescription(); labelVersion.Text = "Version " + AssemblyUtilities.GetInformationalVersion(); labelCopyright.Text = AssemblyUtilities.GetCopyright(); labelCompanyName.Text = AssemblyUtilities.GetCompany(); }