예제 #1
0
        /// <summary>Gets the correct <see cref="IExtractResource"/> action implementation for the provided string instance</summary>
        /// <param name="instance">String instance to refactor</param>
        /// <returns>an <see cref="IExtractResourceAction"/> implementation. null if no suitable action is found.</returns>
        public static IExtractResourceAction GetExtractResourceActionObject(BaseHardCodedString instance)
        {
            if (actionObjectCache.ContainsKey(instance.Parent))
            {
                return(actionObjectCache[instance.Parent]);
            }
            if (availableActionObjectList == null)
            {
                availableActionObjectList = new List <IExtractResourceAction>();
                Assembly currentAssembly = Assembly.GetExecutingAssembly();
                Type[]   types           = currentAssembly.GetTypes();
                foreach (Type type in types)
                {
                    if (!type.IsAbstract && (typeof(IExtractResourceAction)).IsAssignableFrom(type))
                    {
                        try {
                            IExtractResourceAction currentAction = System.Activator.CreateInstance(type) as IExtractResourceAction;
                            if (currentAction != null)
                            {
                                availableActionObjectList.Add(currentAction);
                            }
                        } catch (TargetInvocationException e) {
                            System.Diagnostics.Trace.TraceError(e.ToString());
                        } catch (ArgumentException e) {
                            System.Diagnostics.Trace.TraceError(e.ToString());
                        } catch (MissingMethodException e) {
                            System.Diagnostics.Trace.TraceError(e.ToString());
                        }
                    }
                }
            }
            IExtractResourceAction action = null;

            foreach (IExtractResourceAction currentAction in availableActionObjectList)
            {
                if (!currentAction.QuerySupportForProject(instance.Parent))
                {
                    continue;
                }
                if (action == null || currentAction.Priority > action.Priority)
                {
                    action = currentAction;
                }
            }
            if (action != null)
            {
                if (actionObjectCache.Count > 30)
                {
                    actionObjectCache.Clear();
                }
                actionObjectCache.Add(instance.Parent, action);
            }
            return(action);
        }
 /// <summary>
 /// Creates a new instance to refactor provided string instance
 /// </summary>
 /// <param name="stringInstance">String instance to refactor</param>
 public ExtractToResourceActionSite(BaseHardCodedString stringInstance)
 {
     this.stringInstance = stringInstance;
     actionObject = GetExtractResourceActionObject(this.StringToExtract);
 }
예제 #3
0
 /// <summary>Creates a new instance to refactor provided string instance</summary>
 /// <param name="stringInstance">String instance to refactor</param>
 public ExtractToResourceActionSite(BaseHardCodedString stringInstance)
 {
     this.stringInstance = stringInstance;
     actionObject        = GetExtractResourceActionObject(this.StringToExtract);
 }