Ejemplo n.º 1
0
        private BindingScope CreateScope(ScopeAttribute scopeAttr)
        {
            if (scopeAttr.Tag == null && scopeAttr.Feature == null && scopeAttr.Scenario == null)
            {
                return(null);
            }

            return(new BindingScope(scopeAttr.Tag, scopeAttr.Feature, scopeAttr.Scenario));
        }
Ejemplo n.º 2
0
        static MenuHelper()
        {
            /*
             * Create one instance of guiControllerCommand for each existing public command.
             * This instance is later used in every context menu (instances of commands are shared
             * among the existing menus)
             */
            foreach (List <CommandDescriptor> scopeCommands in PublicCommandsHelper.publicCommandsByScope.Values)
            {
                foreach (CommandDescriptor commandDescriptor in scopeCommands)
                {
                    guiControllerCommand guiC       = new guiControllerCommand();
                    CommandDescriptor    descriptor = commandDescriptor;
                    guiC.ControllerCommandFactoryMethod =
                        delegate
                    {
                        return(CommandSerializer.CreateCommandObject(descriptor.CommandType));
                    };
                    guiC.ControllerCommandType        = commandDescriptor.CommandType;
                    guiC.ControllerCommandDescription = commandDescriptor.CommandDescription;
                    guiCommandsForControllerCommands[commandDescriptor.CommandType] = guiC;
                }
            }

            foreach (Type t in typeof(guiScopeCommand).Assembly.GetTypes())
            {
                if (t.IsSubclassOf(typeof(guiScopeCommand)))
                {
                    ScopeAttribute a = (ScopeAttribute)t.GetCustomAttributes(typeof(ScopeAttribute), true).FirstOrDefault();
                    if (a != null)
                    {
                        #if SILVERLIGHT
                        foreach (ScopeAttribute.EScope scope in EnumHelper.GetValues(typeof(ScopeAttribute.EScope)))
                        #else
                        foreach (ScopeAttribute.EScope scope in Enum.GetValues(typeof(ScopeAttribute.EScope)))
                        #endif
                        {
                            if (scope == ScopeAttribute.EScope.None)
                            {
                                continue;
                            }
                            if (a.Scope.HasFlag(scope))
                            {
                                localCommandsByScope.CreateSubCollectionIfNeeded(scope);
                                localCommandsByScope[scope].Add((guiScopeCommand)t.GetConstructor(Type.EmptyTypes).Invoke(null));
                            }
                        }
                        if (a.Scope == ScopeAttribute.EScope.None)
                        {
                            localCommandsByScope.CreateSubCollectionIfNeeded(a.Scope);
                            localCommandsByScope[a.Scope].Add((guiScopeCommand)t.GetConstructor(Type.EmptyTypes).Invoke(null));
                        }
                    }
                }
            }
        }
        protected override string ResolveScope(Type type, MethodInfo methodInfo, ScopeAttribute scopeAttr)
        {
            var scope = base.ResolveScope(type, methodInfo, scopeAttr);

            var genericTypeArguments = methodInfo.DeclaringType.GenericTypeArguments;

            if (genericTypeArguments.Length > 0)
            {
                scope += ":generic";
                foreach (var gType in genericTypeArguments)
                {
                    var typeName = gType.Name;
                    var dataAttr = gType.GetTypeInfo().GetCustomAttribute <DataAttribute>(true);
                    if (dataAttr != null)
                    {
                        typeName = $"typeId:{dataAttr.TypeId}";
                    }

                    scope += ":" + typeName;
                }
            }

            return(scope);
        }
        ApplyScope <TLimit, TActivatorData, TRegistrationStyle>(
            this IRegistrationBuilder <TLimit, TActivatorData, TRegistrationStyle> builder, ScopeAttribute attr)
        {
            var scope = attr?.Scope ?? default(Scope);

            switch (scope)
            {
            case Scope.PerDependency:
                return(builder.InstancePerDependency());

            case Scope.Singleton:
                return(builder.SingleInstance());

            case Scope.PerLifetimeScope:
                return(builder.InstancePerLifetimeScope());

            default:
                throw Assertion.Fail();
            }
        }
Ejemplo n.º 5
0
        private BindingScope CreateScope(ScopeAttribute scopeAttr)
        {
            if (scopeAttr.Tag == null && scopeAttr.Feature == null && scopeAttr.Scenario == null)
                return null;

            return new BindingScope(scopeAttr.Tag, scopeAttr.Feature, scopeAttr.Scenario);
        }
        public void KeyAttribute_Should_Set_Name(string testData)
        {
            var attribute = new ScopeAttribute(testData);

            Assert.Equal(testData, attribute.Name);
        }