示例#1
0
        // The MixinConfiguration is passed to Execute in order to be able to call PrepareOutputDirectory before analyzing the configuration (and potentially
        // locking old generated files).
        public void Execute(MixinConfiguration configuration)
        {
            ArgumentUtility.CheckNotNull("configuration", configuration);

            using (StopwatchScope.CreateScope(s_log, LogLevel.Info, "Time needed to mix and save all types: {elapsed}."))
            {
                _errors.Clear();
                _processedTypes.Clear();
                _finishedTypes.Clear();
                _generatedFiles = new string[0].AsReadOnly();

                s_log.InfoFormat("The base directory is '{0}'.", AppDomain.CurrentDomain.BaseDirectory);

                var pipeline = MixerPipelineFactory.CreatePipeline(AssemblyOutputDirectory);

                var mixedTypes = MixedTypeFinder.FindMixedTypes(configuration).ToArray();

                s_log.Info("Generating types...");
                using (configuration.EnterScope())
                {
                    foreach (var mixedType in mixedTypes)
                    {
                        Generate(mixedType, pipeline);
                    }
                }

                s_log.Info("Saving assemblies...");
                Save(pipeline);
            }

            s_log.InfoFormat("Successfully generated concrete types for {0} target classes.", _finishedTypes.Count);
        }
        public AttributeConstruction(ICustomAttributeData customAttributeData)
        {
            var constructorInfo = customAttributeData.Constructor;

            _constructorInfo      = constructorInfo;
            _constructorArguments = customAttributeData.ConstructorArguments;
            _namedArguments       = customAttributeData.NamedArguments;
        }
示例#3
0
        private ClassContext(Type type, MixinContextCollection mixins, ReadOnlyCollectionDecorator <Type> composedInterfaces)
        {
            _type               = type;
            _mixins             = mixins;
            _composedInterfaces = composedInterfaces;

            _cachedHashCode = CalculateHashCode(this);
        }
示例#4
0
        private void Save(IPipeline pipeline)
        {
            _generatedFiles = pipeline.CodeManager.FlushCodeToDisk().AsReadOnly();

            foreach (var generatedFile in _generatedFiles)
            {
                s_log.InfoFormat("Generated assembly file '{0}'.", generatedFile);
            }
        }
示例#5
0
        public SecurableClassDefinitionData(
            [CanBeNull] string baseClass,
            [CanBeNull] IDomainObjectHandle <StatelessAccessControlList> statelessAccessControlList,
            IEnumerable <StatefulAccessControlListData> statefulAccessControlLists)
        {
            ArgumentUtility.CheckNotNull("statefulAccessControlLists", statefulAccessControlLists);

            _baseClass = baseClass;
            _statelessAccessControlList = statelessAccessControlList;
            _statefulAccessControlLists = statefulAccessControlLists.ToArray().AsReadOnly();
        }
        public TypeConstruction(Type aspectType)
        {
            ArgumentUtility.CheckNotNull("aspectType", aspectType);
            //Assertion.IsTrue (typeof (IAspect).IsAssignableFrom (aspectType) || typeof (AspectAttributeBase).IsAssignableFrom (aspectType));

            _constructorInfo = aspectType.GetConstructor(Type.EmptyTypes);
            if (_constructorInfo == null)
            {
                throw new ArgumentException(aspectType.Name + " must provide a default constructor.");
            }

            _constructorArguments = new object[0].ToList().AsReadOnly();
            _namedArguments       = new ReadOnlyCollectionDecorator <ICustomAttributeNamedArgument> (new ICustomAttributeNamedArgument[0]);
        }
        public static ICustomAttributeData GetCustomAttributeData(Type declaringType = null, ICustomAttributeNamedArgument[] namedArguments = null)
        {
            var constructorInfo      = GetConstructorInfo(declaringType: declaringType);
            var constructorArguments = new object[0].ToList().AsReadOnly();
            var namedArguments2      = new ReadOnlyCollectionDecorator <ICustomAttributeNamedArgument> (namedArguments ?? new ICustomAttributeNamedArgument[0]);

            var stub = MockRepository.GenerateStub <ICustomAttributeData>();

            stub.Stub(x => x.Constructor).Return(constructorInfo);
            stub.Stub(x => x.ConstructorArguments).Return(constructorArguments);
            stub.Stub(x => x.NamedArguments).Return(namedArguments2);

            return(stub);
        }
示例#8
0
        public StatefulAccessControlListData([NotNull] IDomainObjectHandle <StatefulAccessControlList> handle, [NotNull] IEnumerable <State> states)
        {
            ArgumentUtility.CheckNotNull("handle", handle);
            ArgumentUtility.CheckNotNull("states", states);

            var stateArray = states.ToArray().AsReadOnly();

            if (stateArray.Select(s => s.PropertyHandle).Distinct().Count() != stateArray.Count)
            {
                throw new ArgumentException("Multiple state values found for a single state property.", "states");
            }

            _handle = handle;
            _states = stateArray;
        }
示例#9
0
        public static IAspectConstruction GetConstruction(
            ConstructorInfo constructor = null,
            ReadOnlyCollection <object> constructorArguments = null,
            ReadOnlyCollectionDecorator <ICustomAttributeNamedArgument> namedArguments = null)
        {
            constructor          = constructor ?? GetConstructorInfo();
            constructorArguments = constructorArguments ?? new object[0].ToList().AsReadOnly();
            namedArguments       = namedArguments ?? new ReadOnlyCollectionDecorator <ICustomAttributeNamedArgument> (new ICustomAttributeNamedArgument[0]);

            var stub = MockRepository.GenerateStub <IAspectConstruction>();

            stub.Stub(x => x.ConstructorInfo).Return(constructor);
            stub.Stub(x => x.ConstructorArguments).Return(constructorArguments);
            stub.Stub(x => x.NamedArguments).Return(namedArguments);

            return(stub);
        }
示例#10
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MixinContext"/> class.
        /// </summary>
        /// <param name="mixinKind">The kind of relationship the configured mixin has with its target class.</param>
        /// <param name="mixinType">The mixin type represented by this <see cref="MixinContext"/>.</param>
        /// <param name="introducedMemberVisibility">The default visbility of introduced members.</param>
        /// <param name="explicitDependencies">The explicit dependencies of the mixin.</param>
        /// <param name="origin">
        /// A description of where the <see cref="MixinContext"/> originates from. Note that <paramref name="origin"/> is not considered when comparing
        /// <see cref="MixinContext"/> objects for equality.
        /// </param>
        public MixinContext(
            MixinKind mixinKind,
            Type mixinType,
            MemberVisibility introducedMemberVisibility,
            IEnumerable <Type> explicitDependencies,
            MixinContextOrigin origin)
        {
            ArgumentUtility.CheckNotNull("mixinType", mixinType);
            ArgumentUtility.CheckNotNull("explicitDependencies", explicitDependencies);
            ArgumentUtility.CheckNotNull("origin", origin);

            _mixinType = mixinType;
            _mixinKind = mixinKind;
            _introducedMemberVisibility = introducedMemberVisibility;
            _explicitDependencies       = new HashSet <Type> (explicitDependencies).AsReadOnly();
            _origin = origin;

            _cachedHashCode = EqualityUtility.GetRotatedHashCode(
                _mixinKind,
                _mixinType,
                EqualityUtility.GetXorHashCode(ExplicitDependencies),
                IntroducedMemberVisibility);
        }
示例#11
0
        public void AddOverridden(HashSet <MethodInfo> overridden)
        {
            ArgumentUtility.CheckNotNull("overridden", overridden);

            _overridden = overridden.AsReadOnly();
        }
示例#12
0
        public void AddOverriders(HashSet <MethodInfo> overriders)
        {
            ArgumentUtility.CheckNotNull("overriders", overriders);

            _overriders = overriders.AsReadOnly();
        }
示例#13
0
        public void AsReadOnly()
        {
            ReadOnlyCollectionDecorator <int> decorator = _collection.AsReadOnly();

            Assert.That(decorator, Is.EqualTo(_collection));
        }
示例#14
0
 public void SetUp()
 {
     _collection = new ReadOnlyCollectionDecorator <string> (new List <string>(new[] { "test1", "test2" }));
 }