/// <summary> /// Gets the code for interface attribute. /// </summary> /// <returns> /// The code for the interface attribute. /// </returns> public string CreateCodeForInterfaceAttribute() { var eb = new ElementBuilder(); var attributeSection = eb.AddAttributeSection(null); var attribute = eb.AddAttribute(attributeSection, ContractClassAttributeName); var contractClassTypeReference = new TypeReferenceExpression(this.CreateContractClassName()); eb.AddArgument(attribute, new TypeOfExpression(contractClassTypeReference)); return(eb.GenerateCode(this.TextDocument.Language)); }
private string GetSource(string text) { var methodName = CreateMethodName(text); ElementBuilder eb = new ElementBuilder(); var method = eb.AddMethod(CodeRush.Source.ActiveClass, "void", methodName); method.Visibility = MemberVisibility.Public; var testSection = eb.AddAttributeSection(method); eb.AddAttribute(testSection, "Test"); method.AddSupportElement(testSection); eb.AddMethodCall(method, "Assert.Fail", new[] { "\"Not Implemented\"" }); string source = CodeRush.Language.GenerateElement(testSection) + CodeRush.Language.GenerateElement(method); return source; }
} // refactoringProvider_Apply(sender, ea) /// <summary> /// Get new delayed property declaration /// </summary> private string GetNewDelayedPropertyDeclaration(ElementBuilder elementBuilder, Property oldProperty) { string propName = oldProperty.Name; string typeName = oldProperty.GetTypeName(); Property newProperty = elementBuilder.AddProperty(null, typeName, propName); newProperty.Visibility = oldProperty.Visibility; newProperty.IsStatic = oldProperty.IsStatic; newProperty.IsVirtual = oldProperty.IsVirtual; newProperty.IsOverride = oldProperty.IsOverride; newProperty.IsExplicitInterfaceMember = oldProperty.IsExplicitInterfaceMember; AttributeSection attrSection = elementBuilder.AddAttributeSection(newProperty); elementBuilder.AddAttribute(attrSection, "Delayed"); if (oldProperty.HasGetter) { Get getter = elementBuilder.AddGetter(newProperty); ExpressionCollection expressionCollection = new ExpressionCollection(); expressionCollection.Add(new PrimitiveExpression(String.Format("\"{0}\"", propName))); string methodName = String.Format("GetDelayedPropertyValue<{0}>", typeName); elementBuilder.AddReturn(getter, elementBuilder.BuildMethodCall(methodName, expressionCollection, null)); } if (oldProperty.HasSetter) { Set setter = elementBuilder.AddSetter(newProperty); ExpressionCollection expressionCollection = new ExpressionCollection(); expressionCollection.Add(new PrimitiveExpression(String.Format("\"{0}\"", propName))); expressionCollection.Add(new ElementReferenceExpression("value")); string methodName = String.Format("SetDelayedPropertyValue<{0}>", typeName); elementBuilder.AddMethodCall(setter, methodName, expressionCollection, null); } // if return(elementBuilder.GenerateCode()); } // GetNewDelayedPropertyDeclaration(elementBuilder, oldProperty)
} // refactoringProvider_Apply(sender, ea) /// <summary> /// Get new delayed property declaration /// </summary> private string GetNewDelayedPropertyDeclaration(ElementBuilder elementBuilder, Property oldProperty) { string propName = oldProperty.Name; string typeName = oldProperty.GetTypeName(); Property newProperty = elementBuilder.AddProperty(null, typeName, propName); newProperty.Visibility = oldProperty.Visibility; newProperty.IsStatic = oldProperty.IsStatic; newProperty.IsVirtual = oldProperty.IsVirtual; newProperty.IsOverride = oldProperty.IsOverride; newProperty.IsExplicitInterfaceMember = oldProperty.IsExplicitInterfaceMember; AttributeSection attrSection = elementBuilder.AddAttributeSection(newProperty); elementBuilder.AddAttribute(attrSection, "Delayed"); if (oldProperty.HasGetter) { Get getter = elementBuilder.AddGetter(newProperty); ExpressionCollection expressionCollection = new ExpressionCollection(); expressionCollection.Add(new PrimitiveExpression(String.Format("\"{0}\"", propName))); string methodName = String.Format("GetDelayedPropertyValue<{0}>", typeName); elementBuilder.AddReturn(getter, elementBuilder.BuildMethodCall(methodName, expressionCollection, null)); } if (oldProperty.HasSetter) { Set setter = elementBuilder.AddSetter(newProperty); ExpressionCollection expressionCollection = new ExpressionCollection(); expressionCollection.Add(new PrimitiveExpression(String.Format("\"{0}\"", propName))); expressionCollection.Add(new ElementReferenceExpression("value")); string methodName = String.Format("SetDelayedPropertyValue<{0}>", typeName); elementBuilder.AddMethodCall(setter, methodName, expressionCollection, null); } // if return elementBuilder.GenerateCode(); } // GetNewDelayedPropertyDeclaration(elementBuilder, oldProperty)
/// <summary> /// Gets the code for interface attribute. /// </summary> /// <returns> /// The code for the interface attribute. /// </returns> public string CreateCodeForInterfaceAttribute() { var eb = new ElementBuilder(); var attributeSection = eb.AddAttributeSection(null); var attribute = eb.AddAttribute(attributeSection, ContractClassAttributeName); var contractClassTypeReference = new TypeReferenceExpression(this.CreateContractClassName()); eb.AddArgument(attribute, new TypeOfExpression(contractClassTypeReference)); return eb.GenerateCode(this.TextDocument.Language); }