private IClassDeclaration GenerateGenericContractClassDeclaration(string contractClassName) { // This solution was found at CreateDerivedTypeAction.cs from decompiled R# SDK var baseTypeElement = _addContractForAvailability.DeclaredType.GetTypeElement(); Contract.Assert(baseTypeElement != null); string typeDeclaration = baseTypeElement.TypeParameters .AggregateString(",", (builder, parameter) => builder.Append(parameter.ShortName)); typeDeclaration = "<" + typeDeclaration + ">"; var classDeclaration = (IClassDeclaration)_factory.CreateTypeMemberDeclaration( "abstract class $0 " + typeDeclaration + " : $1" + typeDeclaration + " {}", new object[] { contractClassName, baseTypeElement }); var map = new Dictionary <ITypeParameter, IType>(); for (int i = 0; i < baseTypeElement.TypeParameters.Count; i++) { ITypeParameterOfTypeDeclaration declaration3 = classDeclaration.TypeParameters[i]; ITypeParameter key = baseTypeElement.TypeParameters[i]; map.Add(key, TypeFactory.CreateType(declaration3.DeclaredElement)); } ISubstitution substitution = EmptySubstitution.INSTANCE.Extend(map); for (int j = 0; j < baseTypeElement.TypeParameters.Count; j++) { ITypeParameter typeParameter = baseTypeElement.TypeParameters[j]; ITypeParameterOfTypeDeclaration declaration4 = classDeclaration.TypeParameters[j]; ITypeParameterConstraintsClause clause = _factory.CreateTypeParameterConstraintsClause(typeParameter, substitution, declaration4.DeclaredName); if (clause != null) { classDeclaration.AddTypeParameterConstraintsClauseBefore(clause, null); } } return(classDeclaration); }
public void RemoveTypeParameterConstraintsClause(ITypeParameterConstraintsClause param) { _classDeclaration.RemoveTypeParameterConstraintsClause(param); }
public ITypeParameterConstraintsClause AddTypeParameterConstraintsClauseAfter( ITypeParameterConstraintsClause param, ITypeParameterConstraintsClause anchor) { return(_classDeclaration.AddTypeParameterConstraintsClauseAfter(param, anchor)); }