Ejemplo n.º 1
0
        public MorphIntoRoleResult MorphType(MutationParameters parameters)
        {
            parameters.Validate();
              var roleType = parameters.SourceType;
              if (roleType == null) throw new ArgumentException("parameters must include a SourceType", "parameters");

              _parameters = parameters;

              if (!roleType.IsRole()) {
            throw new InvalidOperationException("Cannot morph class into role");
              }

              Tracer.TraceVerbose("Morph role: {0}", roleType);

              var result = new MorphIntoRoleResult();

              CheckRole(roleType, result);
              if (!result.Success) { return result; }

              PreProcessRole(roleType); // TODO: result?
              if (!result.Success) { return result; }

              var roleStateClass = ExtractRoleStateClass(roleType, result);
              if (!result.Success) { return result; }

              // TODO: Cecil bug! We need to touch the SemanticsAttributes in order for it to remain on the method!
              roleType.Methods.Select(m => m.SemanticsAttributes).ToList();

              var roleCodeClass = ExtractRoleCodeClass(roleType, result);
              if (!result.Success) { return result; }

              MorphRoleIntoInterface(roleType, result);
              if (!result.Success) { return result; }

              result.CodeType = roleCodeClass;
              result.StateType = roleStateClass;

              return result;
        }
Ejemplo n.º 2
0
 private void CheckRole(TypeDefinition roleType, MorphIntoRoleResult result)
 {
     var validator = new RoleConstraintsValidator(roleType);
       var checkResult = validator.Check(_parameters.Context);
       result.AddResult(checkResult);
 }
Ejemplo n.º 3
0
 private void MorphRoleIntoInterface(TypeDefinition roleType, MorphIntoRoleResult result)
 {
     var morpher = new MorphIntoInterfaceMutator();
       var morphIntoInterfaceResult = morpher.Morph(
     new MutationParameters {
       Context = _parameters.Context,
       SourceType = roleType,
     });
       result.AddResult(morphIntoInterfaceResult);
 }
Ejemplo n.º 4
0
 private TypeDefinition ExtractRoleStateClass(TypeDefinition roleType, MorphIntoRoleResult result)
 {
     var stateClassExtractor = new ExtractStateClassMutator();
       var extractStateClassResult = stateClassExtractor.ExtractType(
     new ExtractTypeParameters {
       Context = _parameters.Context,
       SourceType = roleType,
       TargetTypeName = DetermineStateClassName(roleType.Name),
       AddTypeStrategy = AddTypeStrategy.AddAsNested
     });
       result.AddResult(extractStateClassResult);
       return extractStateClassResult.TargetType;
 }