/// <summary> /// This method is called by Inventor when it loads the addin. /// The AddInSiteObject provides access to the Inventor Application object. /// The FirstTime flag indicates if the addin is loaded for the first time. /// </summary> /// <param name="addInSiteObject"></param> /// <param name="firstTime"></param> public void Activate(Inventor.ApplicationAddInSite addInSiteObject, bool firstTime) { try { InventorApplication = addInSiteObject.Application; //retrieve the GUID for this class and assign it to the string member variable //intended to hold it GuidAttribute addInClsid = (GuidAttribute)Attribute.GetCustomAttribute (typeof(StandardAddInServer), typeof(GuidAttribute)); string addInClsidString = "{" + addInClsid.Value + "}"; AddInServerId = addInClsidString; //Set a reference to the user interface manager to determine the interface style UserInterfaceManager userInterfaceManager = InventorApplication.UserInterfaceManager; InterfaceStyleEnum interfaceStyle = userInterfaceManager.InterfaceStyle; RectangleDependencyManager = new RectangleToolsDependencyMapper(); if (interfaceStyle == InterfaceStyleEnum.kRibbonInterface) { if (firstTime == true) { RectangleDependencyManager.InitializeUserInterface(); } } } catch (Exception e) { MessageBox.Show(e.ToString()); } }
private IType GetExternalEnumeratorItemType(IType iteratorType) { Type type = ((ExternalType)iteratorType).ActualType; var attribute = (EnumeratorItemTypeAttribute)Attribute.GetCustomAttribute(type, typeof(EnumeratorItemTypeAttribute)); return(null != attribute?Map(attribute.ItemType) : null); }
IEnumerable <TaskParameter> GetTaskParameters(Type taskType) { return(from property in taskType.GetProperties() let attribute = (TaskAttributeAttribute)Attribute.GetCustomAttribute(property, typeof(TaskAttributeAttribute)) where attribute != null let name = attribute.Name.Replace("-", "") select new TaskParameter { Name = name, Property = property }); }
private IType GetExternalEnumeratorItemType(IType iteratorType) { Type type = ((ExternalType)iteratorType).ActualType; #if DNXCORE50 var attribute = CustomAttributeExtensions.GetCustomAttribute <EnumeratorItemTypeAttribute>(type.GetTypeInfo()); #else var attribute = (EnumeratorItemTypeAttribute)Attribute.GetCustomAttribute(type, typeof(EnumeratorItemTypeAttribute)); #endif return(null != attribute?Map(attribute.ItemType) : null); }
public static string GetDescription(this Type type, Func <Type, string> noDescriptionCallback) { DescriptionAttribute attr = Attribute.GetCustomAttribute(type, typeof(DescriptionAttribute)) as DescriptionAttribute; if (attr == null) { return(noDescriptionCallback(type)); } return(attr.Description); }
protected virtual void InitializeAttributes() { Type nodeType = GetType(); _hasDebugOverride = Attribute.GetCustomAttribute(nodeType, typeof(DebugOverrideAttribute)) != null; _isObsolete = Attribute.GetCustomAttribute(nodeType, typeof(ObsoleteAttribute)) != null; _isExperimental = Attribute.GetCustomAttribute(nodeType, typeof(ExperimentalAttribute)) != null; InputCountAttribute inputCountAttribute = (InputCountAttribute) Attribute.GetCustomAttribute(nodeType, typeof(InputCountAttribute)); _inputCount = inputCountAttribute == null ? 0 : inputCountAttribute.count; InputLabelsAttribute inputAttribute = (InputLabelsAttribute) Attribute.GetCustomAttribute(nodeType, typeof(InputLabelsAttribute)); _inputLabels = inputAttribute == null ? new string[0] : inputAttribute.labels; OutputCountAttribute outputCountAttribute = (OutputCountAttribute) Attribute.GetCustomAttribute(nodeType, typeof(OutputCountAttribute)); _outputCount = outputCountAttribute == null ? 0 : outputCountAttribute.count; OutputLabelsAttribute outputAttribute = (OutputLabelsAttribute) Attribute.GetCustomAttribute(nodeType, typeof(OutputLabelsAttribute)); _outputLabels = outputAttribute == null ? new string[0] : outputAttribute.labels; #if UNITY_EDITOR SkinAttribute skinAttribute = (SkinAttribute) Attribute.GetCustomAttribute(nodeType, typeof(SkinAttribute)); _backgroundSkinId = skinAttribute != null ? skinAttribute.backgroundSkinId : "NodeBodyBg"; _titleSkinId = skinAttribute != null ? skinAttribute.titleSkinId : "NodeTitleBg"; SizeAttribute sizeAttribute = (SizeAttribute) Attribute.GetCustomAttribute(nodeType, typeof(SizeAttribute)); _size = sizeAttribute != null ? new Vector2(sizeAttribute.width, sizeAttribute.height) : Vector2.one; DisableBaseGUIAttribute disableBaseGuiAttribute = (DisableBaseGUIAttribute) Attribute.GetCustomAttribute(nodeType, typeof(DisableBaseGUIAttribute)); _baseGUIEnabled = disableBaseGuiAttribute == null; CategoryAttribute categoryAttribute = (CategoryAttribute) Attribute.GetCustomAttribute(nodeType, typeof(CategoryAttribute)); Category = categoryAttribute.type; //_iconTexture = iconAttribute != null ? IconManager.GetIcon(iconAttribute.iconId) : DashEditorCore.EditorConfig.theme.GetNodeIconByCategory(categoryAttribute.type); // _nodeBackgroundColor = DashEditorCore.EditorConfig.theme.GetNodeBackgroundColorByCategory(categoryAttribute.type); // // _titleBackgroundColor = DashEditorCore.EditorConfig.theme.GetNodeTitleBackgroundColorByCategory(categoryAttribute.type); // // _titleTextColor = DashEditorCore.EditorConfig.theme.GetNodeTitleTextColorByCategory(categoryAttribute.type); #endif _attributesInitialized = true; }
public static void GetAddinClassId(Type t) { var guidAtt = (GuidAttribute)Attribute.GetCustomAttribute(t, typeof(GuidAttribute)); _mClassId = "{" + guidAtt.Value + "}"; }
void MigrateUserSpecifiedPrefKeys() { // If migration already happened then don't do anything if (EditorPrefs.GetBool(k_ProfileMigratedEditorPrefKey, false)) { return; } EditorPrefs.SetBool(k_ProfileMigratedEditorPrefKey, true); // Find shortcut entries that might need to be migrated var allShortcuts = new List <ShortcutEntry>(); directory.GetAllShortcuts(allShortcuts); // Find existing or create migrated profile and make it active so we can amend it var originalActiveProfile = profileManager.activeProfile; var migratedProfile = profileManager.GetProfileById(k_MigratedProfileId); var migratedProfileAlreadyExisted = migratedProfile != null; if (!migratedProfileAlreadyExisted) { migratedProfile = profileManager.CreateProfile(k_MigratedProfileId); } profileManager.activeProfile = migratedProfile; var migratedProfileModified = false; var tempKeyCombinations = new KeyCombination[1]; var methodsWithFormerlyPrefKeyAs = EditorAssemblies.GetAllMethodsWithAttribute <FormerlyPrefKeyAsAttribute>(); foreach (var method in methodsWithFormerlyPrefKeyAs) { var shortcutAttr = Attribute.GetCustomAttribute(method, typeof(ShortcutAttribute), true) as ShortcutAttribute; if (shortcutAttr == null) { continue; } var entry = allShortcuts.Find(e => string.Equals(e.identifier.path, shortcutAttr.identifier)); if (entry == null) { continue; } // Ignore former PrefKey if it is overriden in existing migrated profile if (entry.overridden) { continue; } // Parse default pref key value from FormerlyPrefKeyAs attribute var prefKeyAttr = (FormerlyPrefKeyAsAttribute)Attribute.GetCustomAttribute(method, typeof(FormerlyPrefKeyAsAttribute)); var editorPrefDefaultValue = $"{prefKeyAttr.name};{prefKeyAttr.defaultValue}"; string name; Event keyboardEvent; string shortcut; if (!TryParseUniquePrefKeyString(editorPrefDefaultValue, out name, out keyboardEvent, out shortcut)) { continue; } var prefKeyDefaultKeyCombination = KeyCombination.FromPrefKeyKeyboardEvent(keyboardEvent); // Parse current pref key value (falling back on default pref key value) if (!TryParseUniquePrefKeyString(EditorPrefs.GetString(prefKeyAttr.name, editorPrefDefaultValue), out name, out keyboardEvent, out shortcut)) { continue; } var prefKeyCurrentKeyCombination = KeyCombination.FromPrefKeyKeyboardEvent(keyboardEvent); // Only migrate pref keys that the user actually overwrote if (prefKeyCurrentKeyCombination.Equals(prefKeyDefaultKeyCombination)) { continue; } string invalidBindingMessage; tempKeyCombinations[0] = prefKeyCurrentKeyCombination; if (!bindingValidator.IsBindingValid(tempKeyCombinations, out invalidBindingMessage)) { Debug.LogWarning($"Could not migrate existing binding for shortcut \"{entry.identifier.path}\" with invalid binding.\n{invalidBindingMessage}."); continue; } profileManager.ModifyShortcutEntry(entry.identifier, new List <KeyCombination> { prefKeyCurrentKeyCombination }); migratedProfileModified = true; } // Delete migrated profile if it was created and not modified if (!migratedProfileAlreadyExisted && !migratedProfileModified) { profileManager.DeleteProfile(migratedProfile); } // Restore original active profile unless last loaded profile was null and the migrated profile was created if (originalActiveProfile != null || migratedProfileAlreadyExisted) { profileManager.activeProfile = originalActiveProfile; } }
string GetTaskName(Type taskType) { var nameAttribute = (TaskNameAttribute)Attribute.GetCustomAttribute(taskType, typeof(TaskNameAttribute)); return(nameAttribute != null ? nameAttribute.Name : taskType.Name.ToLowerInvariant()); }
private string GetAddInId() { var id = (GuidAttribute)Attribute.GetCustomAttribute(typeof(MyAddInServer), typeof(GuidAttribute)); return("{" + id.Value + "}"); }