/// <summary>
        /// Creates an additional <see cref="MutableType"/> representing an public interface.
        /// </summary>
        /// <param name="context">A type assembly context.</param>
        /// <param name="additionalTypeID">The ID of the type.</param>
        /// <param name="name">The interface name.</param>
        /// <param name="namespace">The namespace of the interface.</param>
        /// <returns>A new mutable type representing an interface.</returns>
        public static MutableType CreateInterface(
            [NotNull] this ITypeAssemblyContext context,
            [NotNull] object additionalTypeID,
            [NotNull] string name,
            [CanBeNull] string @namespace)
        {
            ArgumentUtility.CheckNotNull("context", context);
            ArgumentUtility.CheckNotNull("additionalTypeID", additionalTypeID);
            ArgumentUtility.CheckNotNullOrEmpty("name", name);

            var attributes = TypeAttributes.Public | TypeAttributes.Interface | TypeAttributes.Abstract;

            return(context.CreateAdditionalType(additionalTypeID, name, @namespace, attributes, baseType: null));
        }
示例#2
0
        private ConcreteMixinType GenerateConcreteMixinType(ITypeAssemblyContext context, ConcreteMixinTypeIdentifier concreteMixinTypeIdentifier)
        {
            var mixinProxyType = context.CreateAddtionalProxyType(concreteMixinTypeIdentifier, concreteMixinTypeIdentifier.MixinType);

            var generator = new MixinTypeGenerator(concreteMixinTypeIdentifier, mixinProxyType, new AttributeGenerator(), context.ParticipantConfigurationID);

            generator.AddInterfaces();
            generator.AddFields();
            generator.AddTypeInitializer();
            generator.ImplementGetObjectData();

            generator.AddMixinTypeAttribute();
            generator.AddDebuggerAttributes();

            var overrideInterface = generator.GenerateOverrides();
            var methodWrappers    = generator.GenerateMethodWrappers();

            return(new ConcreteMixinType(
                       concreteMixinTypeIdentifier, mixinProxyType, overrideInterface.Type, overrideInterface.InterfaceMethodsByOverriddenMethods, methodWrappers));
        }
示例#3
0
        public ConcreteMixinType GetOrGenerateConcreteMixinType(ITypeAssemblyContext context, ConcreteMixinTypeIdentifier concreteMixinTypeIdentifier)
        {
            ArgumentUtility.CheckNotNull("context", context);
            ArgumentUtility.CheckNotNull("concreteMixinTypeIdentifier", concreteMixinTypeIdentifier);

            var concreteMixinTypeCache = GetOrCreateConcreteMixinTypeCache(context.ParticipantState);

            ConcreteMixinType concreteMixinType;

            if (!concreteMixinTypeCache.TryGetValue(concreteMixinTypeIdentifier, out concreteMixinType))
            {
                concreteMixinType = GenerateConcreteMixinType(context, concreteMixinTypeIdentifier);

                context.GenerationCompleted += generatedTypeContext =>
                {
                    var completedConcreteMixinType = concreteMixinType.SubstituteMutableReflectionObjects(generatedTypeContext);
                    concreteMixinTypeCache.Add(concreteMixinTypeIdentifier, completedConcreteMixinType);
                };
            }

            return(concreteMixinType);
        }