示例#1
0
        private GeneratedTypesContext GenerateTypes(AssembledTypeID typeID, ProxyTypeAssemblyContext context, IMutableTypeBatchCodeGenerator codeGenerator)
        {
            // Add [AssembledType] attribute.
            var attribute = new CustomAttributeDeclaration(s_assembledTypeAttributeCtor, new object[0]);

            context.ProxyType.AddCustomAttribute(attribute);

            // Add '__typeID' and initialization code.
            _assembledTypeIdentifierProvider.AddTypeID(context.ProxyType, typeID);

            // Enable complex serialization.
            _complexSerializationEnabler.MakeSerializable(context.ProxyType, _participantConfigurationID, _assembledTypeIdentifierProvider, typeID);

            var mutableTypes = context.AdditionalTypes.Values.Concat(new[] { context.ProxyType });

            return(GenerateTypesWithDiagnostics(codeGenerator, mutableTypes, context.RequestedType.Name));
        }
示例#2
0
        public TypeAssemblyResult AssembleType(AssembledTypeID typeID, IParticipantState participantState, IMutableTypeBatchCodeGenerator codeGenerator)
        {
            ArgumentUtility.CheckNotNull("typeID", typeID);
            ArgumentUtility.CheckNotNull("participantState", participantState);
            ArgumentUtility.CheckNotNull("codeGenerator", codeGenerator);

            var requestedType = typeID.RequestedType;

            CheckRequestedType(requestedType);

            if (ShortCircuitTypeAssembly(requestedType))
            {
                return(new TypeAssemblyResult(requestedType));
            }

            var typeModificationTracker = _mutableTypeFactory.CreateProxy(requestedType, ProxyKind.AssembledType);
            var context = new ProxyTypeAssemblyContext(
                _mutableTypeFactory, _participantConfigurationID, participantState, requestedType, typeModificationTracker.Type);

            foreach (var participant in _participants)
            {
                var idPart = _assembledTypeIdentifierProvider.GetPart(typeID, participant);
                participant.Participate(idPart, context);
            }

            if (!typeModificationTracker.IsModified())
            {
                return(new TypeAssemblyResult(requestedType));
            }

            var generatedTypesContext = GenerateTypes(typeID, context, codeGenerator);

            context.OnGenerationCompleted(generatedTypesContext);

            return(new TypeAssemblyResult(
                       generatedTypesContext.GetGeneratedType(context.ProxyType),
                       context.AdditionalTypes.ToDictionary(kvp => kvp.Key, kvp => generatedTypesContext.GetGeneratedType(kvp.Value))));
        }