private IEnumerable <CSharpProperty> GetProperties(ContractDefinition contract) { // Override property CSharpProperty operationsPropertyOverride = new CSharpProperty( "Operations", "OperationImplementationInfoCollection", CSharpAccessModifier.Protected, isOverride: true, hasSetter: false, defaultValue: "OperationsInternal", documentationComment: new CSharpDocumentationComment(null, "<inheritdoc />") ); yield return(operationsPropertyOverride); // Actual property implementation CSharpProperty operationsPropertyimplementation = new CSharpProperty( "OperationsInternal", "OperationImplementationInfoCollection", CSharpAccessModifier.Private, isStatic: true, defaultValue: this.GetOperationsPropertyValue(contract) ); yield return(operationsPropertyimplementation); }
public void NonNullableNumericBigTest() { var csType = Col.NonNullableNumericBig.ToCSharpType(); var property = new CSharpProperty(Col.NonNullableNumericBig, csType); CSharpProperty.IncludeSqlKataAttributes = true; Assert.IsTrue(property.ToString() == "[Key(\"measurement_id\")]" + Environment.NewLine + "public long MeasurementId { get; set; }" + Environment.NewLine); CSharpProperty.IncludeSqlKataAttributes = false; Assert.IsTrue(property.ToString() == "public long MeasurementId { get; set; }" + Environment.NewLine); }
public void NullableNumericBigUnsignedTest() { var csType = Col.NullableNumericBigUnsigned.ToCSharpType(); var property = new CSharpProperty(Col.NullableNumericBigUnsigned, csType); CSharpProperty.IncludeSqlKataAttributes = true; Assert.IsTrue(property.ToString() == "[Column(\"crate_case\")]" + Environment.NewLine + "public ulong? CrateCase { get; set; }" + Environment.NewLine); CSharpProperty.IncludeSqlKataAttributes = false; Assert.IsTrue(property.ToString() == "public ulong? CrateCase { get; set; }" + Environment.NewLine); }
public static CSharpProperty ToCSharpProperty(DataColumn column) { var cSharpProperty = new CSharpProperty(); cSharpProperty.Name = column.ColumnName; cSharpProperty.IsNullable = column.AllowDBNull; cSharpProperty.ClrAccessModifier = ClrAccessModifier.Public; cSharpProperty.DataType = ConvertDataColumnClrTypeNameToString(column); cSharpProperty.DataAnnotationDefinitionBases.AddRange(CreateDataAnnotations(column)); return(cSharpProperty); }
private static CSharpProperty TransformProperty(string className, CSharpProperty cSharpProperty) { var property = cSharpProperty.Copy(); property.Name = property.Name.Replace(".", "_"); if (property.Name.Equals(className)) { property.Name = property.Name + "Property"; } return(property); }
public void RunTestCases(TestCase testCase) { var property = new CSharpProperty() { DataType = testCase.DataType, IsNullable = testCase.IsNullable, Name = testCase.PropertyName }; var text = new CSharpPropertyTextGenerator(property).Generate(); Console.WriteLine(text); text.Trim().Should().Be(testCase.ExpectedOutput); }
private static List <CSharpProperty> ExtractColumnsFromDataReader(IDataReader sqlDataReader) { var columns = new List <CSharpProperty>(); var schemaTable = sqlDataReader.GetSchemaTable(); foreach (DataRow resultSetColumn in schemaTable.Rows) { var property = new CSharpProperty(); property.ClrAccessModifier = ClrAccessModifier.Public; property.DataType = ConvertDataColumnClrTypeNameToString(((Type)resultSetColumn["DataType"]).Name); property.Name = resultSetColumn["ColumnName"].ToString(); property.IsNullable = (bool)resultSetColumn["AllowDBNull"]; property.DataAnnotationDefinitionBases.AddRange(CreateDataAnnotations(resultSetColumn, property.DataType)); columns.Add(property); } return(columns); }
public static CSharpProperty ToCSharpProperty(SqlColumn sqlColumn) { var cSharpProperty = new CSharpProperty(); var propertyName = AutomaticPropertyNameRewrites.GetNameWithRewriting(sqlColumn.Name); cSharpProperty.Name = propertyName; cSharpProperty.ClrAccessModifier = ClrAccessModifier.Public; cSharpProperty.IsNullable = sqlColumn.IsNullable; cSharpProperty.DataType = SqlTypes.IsSystemType(sqlColumn.SqlDataType.TypeName) ? SqlToClrTypeConverter.GetClrTypeName(sqlColumn.SqlDataType.TypeName) : sqlColumn.SqlDataType.TypeName; cSharpProperty.DataAnnotationDefinitionBases.AddRange(DataAnnotationFactory.CreateDataAnnotations(sqlColumn)); return(cSharpProperty); }
/// <summary> /// Initializes a new instance of the <see cref="PropertyGenerator"/> class for the specified <see cref="IndentedStreamWriter"/> /// </summary> /// <param name="property">Property to generate</param> /// <param name="writer"><see cref="IndentedStreamWriter"/> used to write to</param> public PropertyGenerator(CSharpProperty property, IndentedStreamWriter writer) : base(writer) => _property = property;
private static CSharpProperty CreatePropertyFromDwarfAttributeName(string compactAttrName) { if (compactAttrName == "DWATuseUTFeight") { compactAttrName = "DWATuseUTF8"; } var map = MapAttributeCompactNameToType[compactAttrName]; var rawAttrName = map.RawName; var attrType = map.AttributeType; var propertyName = CSharpifyName(map.RawName); var csProperty = new CSharpProperty(propertyName) { Visibility = CSharpVisibility.Public, ReturnType = new CSharpFreeType(map.Kind == AttributeKind.Managed ? attrType : $"{attrType}?"), }; var attrName = CSharpifyName(rawAttrName); switch (map.Kind) { case AttributeKind.Managed: csProperty.GetBody = (writer, element) => writer.WriteLine($"return GetAttributeValue<{attrType}>(DwarfAttributeKind.{attrName});"); csProperty.SetBody = (writer, element) => writer.WriteLine($"SetAttributeValue<{attrType}>(DwarfAttributeKind.{attrName}, value);"); break; case AttributeKind.ValueType: if (map.AttributeType == "DwarfConstant") { csProperty.GetBody = (writer, element) => writer.WriteLine($"return GetAttributeConstantOpt(DwarfAttributeKind.{attrName});"); csProperty.SetBody = (writer, element) => writer.WriteLine($"SetAttributeConstantOpt(DwarfAttributeKind.{attrName}, value);"); } else if (map.AttributeType == "DwarfLocation") { csProperty.GetBody = (writer, element) => writer.WriteLine($"return GetAttributeLocationOpt(DwarfAttributeKind.{attrName});"); csProperty.SetBody = (writer, element) => writer.WriteLine($"SetAttributeLocationOpt(DwarfAttributeKind.{attrName}, value);"); } else { csProperty.GetBody = (writer, element) => writer.WriteLine($"return GetAttributeValueOpt<{attrType}>(DwarfAttributeKind.{attrName});"); csProperty.SetBody = (writer, element) => writer.WriteLine($"SetAttributeValueOpt<{attrType}>(DwarfAttributeKind.{attrName}, value);"); } break; case AttributeKind.Link: csProperty.GetBody = (writer, element) => { writer.WriteLine($"var attr = FindAttributeByKey(DwarfAttributeKind.{attrName});"); writer.WriteLine($"return attr == null ? null : new {attrType}(attr.ValueAsU64, attr.ValueAsObject);"); }; csProperty.SetBody = (writer, element) => { writer.WriteLine($"SetAttributeLinkValue(DwarfAttributeKind.{attrName}, value);"); }; break; default: throw new ArgumentOutOfRangeException(); } return(csProperty); }
public CSharpPropertyTextGenerator(CSharpProperty property, CSharpClassTextGeneratorOptions options) : this(property) { _cSharpClassTextGeneratorOptions = options; }
public CSharpPropertyTextGenerator(CSharpProperty property) { Property = property; }