/// <summary> /// Writes down the C# feature. /// </summary> /// <param name="writer">The stream on which to write.</param> /// <param name="featureTextType">The write mode.</param> /// <param name="exportStatus">The feature export status.</param> /// <param name="isLocal">True if the feature is local to the class.</param> /// <param name="isFirstFeature">True if the feature is the first in a list.</param> /// <param name="isMultiline">True if there is a separating line above.</param> public override void WriteCSharp(ICSharpWriter writer, CSharpFeatureTextTypes featureTextType, CSharpExports exportStatus, bool isLocal, ref bool isFirstFeature, ref bool isMultiline) { if (!WriteDown) { return; } writer.WriteDocumentation(Source); bool ClassHasSingleConstructor = isLocal && Owner.ClassConstructorType == CSharpConstructorTypes.OneConstructor; string NameString; if (ClassHasSingleConstructor) { NameString = Owner.BasicClassName2CSharpClassName(writer, CSharpTypeFormats.Normal, CSharpNamespaceFormats.None); } else { NameString = CSharpNames.ToCSharpIdentifier(Name); } foreach (ICSharpCommandOverload Overload in OverloadList) { Overload.WriteCSharp(writer, featureTextType, IsOverride, NameString, exportStatus, ClassHasSingleConstructor, ref isFirstFeature, ref isMultiline); } }
private void WriteCSharpImplementation(ICSharpWriter writer, CSharpExports exportStatus, ref bool isFirstFeature, ref bool isMultiline) { bool IsEvent = false; if (Type is ICSharpClassType AsClassType) { ICSharpClass Class = AsClassType.Class; if (Class.InheritFromDotNetEvent) { IsEvent = true; } } writer.WriteDocumentation(Source); CSharpAssertion.WriteContract(writer, new List <ICSharpAssertion>(), EnsureList, CSharpContractLocations.Other, false, ref isFirstFeature, ref isMultiline); string TypeString = Type.Type2CSharpString(writer, CSharpTypeFormats.AsInterface, CSharpNamespaceFormats.None); string AttributeString = CSharpNames.ToCSharpIdentifier(Name); string ExportString = CSharpNames.ComposedExportStatus(false, false, true, exportStatus); if (IsEvent) { writer.WriteIndentedLine($"{ExportString} event {TypeString} {AttributeString};"); } else if (Type.GetSingletonString(writer, CSharpTypeFormats.Normal, CSharpNamespaceFormats.None, out string SingletonString)) { writer.WriteIndentedLine($"{ExportString} {TypeString} {AttributeString} {{ get {{ return {SingletonString}; }} }}"); } else if (EnsureList.Count > 0) { writer.WriteIndentedLine($"{ExportString} {TypeString} {AttributeString} {{ get; private set; }}"); writer.WriteIndentedLine($"protected void Set_{AttributeString}({TypeString} value)"); writer.WriteIndentedLine("{"); writer.IncreaseIndent(); writer.WriteIndentedLine($"{AttributeString} = value;"); writer.WriteEmptyLine(); foreach (ICSharpAssertion Assertion in EnsureList) { Assertion.WriteCSharp(writer); } writer.DecreaseIndent(); writer.WriteIndentedLine("}"); } else { writer.WriteIndentedLine($"{ExportString} {TypeString} {AttributeString} {{ get; protected set; }}"); } }
private void WriteCSharpImplementation(ICSharpWriter writer, CSharpExports exportStatus, bool isLocal, ref bool isFirstFeature, ref bool isMultiline) { writer.WriteDocumentation(Source); string TypeString = Type.Type2CSharpString(writer, CSharpTypeFormats.AsInterface, CSharpNamespaceFormats.None); string AttributeString = CSharpNames.ToCSharpIdentifier(Name); ICSharpExpressionAsConstant ExpressionAsConstant = ConstantExpression as ICSharpExpressionAsConstant; Debug.Assert(ExpressionAsConstant != null); string ValueString; if (ExpressionAsConstant.IsDirectConstant) { ICSharpExpressionContext SourceExpressionContext = new CSharpExpressionContext(); ConstantExpression.WriteCSharp(writer, SourceExpressionContext, -1); ValueString = SourceExpressionContext.ReturnValue; Debug.Assert(ValueString != null); } else { ICSharpComputableExpression CompilableExpression = ConstantExpression as ICSharpComputableExpression; Debug.Assert(CompilableExpression != null); CompilableExpression.Compute(writer); ValueString = CompilableExpression.ComputedValue; Debug.Assert(ValueString != null); writer.WriteIndentedLine($"// {ValueString} = {ConstantExpression.Source.ExpressionToString}"); } string ExportStatusText = CSharpNames.ComposedExportStatus(false, false, true, exportStatus); bool IsReadOnlyObject; if (Type is ICSharpClassType AsClassType) { Guid ClassGuid = AsClassType.Source.BaseClass.ClassGuid; IsReadOnlyObject = ClassGuid != LanguageClasses.Number.Guid && ClassGuid != LanguageClasses.Boolean.Guid && ClassGuid != LanguageClasses.String.Guid && ClassGuid != LanguageClasses.Character.Guid; } else { IsReadOnlyObject = true; } string ConstString = IsReadOnlyObject ? "static readonly" : "const"; writer.WriteIndentedLine($"{ExportStatusText} {ConstString} {TypeString} {AttributeString} = {ValueString};"); }
/// <summary> /// Writes down the C# feature. /// </summary> /// <param name="writer">The stream on which to write.</param> /// <param name="featureTextType">The write mode.</param> /// <param name="exportStatus">The feature export status.</param> /// <param name="isLocal">True if the feature is local to the class.</param> /// <param name="isFirstFeature">True if the feature is the first in a list.</param> /// <param name="isMultiline">True if there is a separating line above.</param> public override void WriteCSharp(ICSharpWriter writer, CSharpFeatureTextTypes featureTextType, CSharpExports exportStatus, bool isLocal, ref bool isFirstFeature, ref bool isMultiline) { if (!WriteDown) { return; } writer.WriteDocumentation(Source); string NameString = CSharpNames.ToCSharpIdentifier(Name); foreach (ICSharpCommandOverload Overload in OverloadList) { Overload.WriteCSharp(writer, featureTextType, IsOverride, NameString, exportStatus, false, ref isFirstFeature, ref isMultiline); } }
private void WriteCSharpImplementation(ICSharpWriter writer, CSharpFeatureTextTypes featureTextType, CSharpExports exportStatus, bool isLocal, ref bool isFirstFeature, ref bool isMultiline) { writer.WriteDocumentation(Source); string ResultType = EntityType.Type2CSharpString(writer, CSharpTypeFormats.AsInterface, CSharpNamespaceFormats.None); string PropertyName = CSharpNames.ToCSharpIdentifier(Name); bool IsHandled = false; if (IsForcedReadWrite) { WriteCSharpForcedReadWriteProperty(writer, IsOverride, exportStatus, PropertyName, ResultType, ref isFirstFeature, ref isMultiline); IsHandled = true; } else { switch (Source.PropertyKind) { case BaseNode.UtilityType.ReadOnly: WriteCSharpReadOnlyProperty(writer, IsOverride, exportStatus, PropertyName, ResultType, ref isFirstFeature, ref isMultiline); IsHandled = true; break; case BaseNode.UtilityType.WriteOnly: WriteCSharpWriteOnlyProperty(writer, IsOverride, exportStatus, PropertyName, ResultType, ref isFirstFeature, ref isMultiline); IsHandled = true; break; case BaseNode.UtilityType.ReadWrite: WriteCSharpReadWriteProperty(writer, IsOverride, exportStatus, PropertyName, ResultType, ref isFirstFeature, ref isMultiline); IsHandled = true; break; } } Debug.Assert(IsHandled); if (HasSideBySideAttribute && !Instance.InheritBySideAttribute) { writer.WriteIndentedLine($"protected {ResultType} _{PropertyName};"); isMultiline = true; } }
private void WriteCSharpImplementation(ICSharpWriter writer, CSharpExports exportStatus, bool isLocal, ref bool isFirstFeature, ref bool isMultiline) { writer.WriteDocumentation(Source); string ResultType = EntityType.Type2CSharpString(writer, CSharpTypeFormats.AsInterface, CSharpNamespaceFormats.None); CSharpArgument.BuildParameterList(writer, IndexParameterList, out string ParameterEntityList, out string ParameterNameList); string Accessors; if (!IsForcedReadWrite && SetterBody == null) { Accessors = "{ get; }"; } else if (!IsForcedReadWrite && GetterBody == null) { Accessors = "{ set; }"; } else { Accessors = "{ get; set; }"; } bool IsDeferred = false; if (GetterBody != null) { if (GetterBody is ICSharpDeferredBody) { IsDeferred = true; } else { IsDeferred = false; } } else if (SetterBody != null) { if (SetterBody is ICSharpDeferredBody) { IsDeferred = true; } else { IsDeferred = false; } } if (IsDeferred) { if (GetterBody is ICSharpDeferredBody AsDeferredGetterBody) { CSharpAssertion.WriteContract(writer, AsDeferredGetterBody.RequireList, AsDeferredGetterBody.EnsureList, CSharpContractLocations.Getter, false, ref isFirstFeature, ref isMultiline); isMultiline = false; } if (SetterBody is ICSharpDeferredBody AsDeferredSetterBody) { CSharpAssertion.WriteContract(writer, AsDeferredSetterBody.RequireList, AsDeferredSetterBody.EnsureList, CSharpContractLocations.Setter, false, ref isFirstFeature, ref isMultiline); } string ExportStatusText = CSharpNames.ComposedExportStatus(false, true, false, exportStatus); writer.WriteIndentedLine($"{ExportStatusText} {ResultType} this[{ParameterEntityList}] {Accessors}"); isMultiline = false; } else { string ExportStatusText = CSharpNames.ComposedExportStatus(IsOverride, false, false, exportStatus); writer.WriteIndentedLine($"{ExportStatusText} {ResultType} this[{ParameterEntityList}]"); writer.WriteIndentedLine("{"); writer.IncreaseIndent(); bool IsPrecursor = false; if (GetterBody != null) { if (GetterBody is ICSharpPrecursorBody) { IsPrecursor = true; } else { IsPrecursor = false; } } else if (SetterBody != null) { if (GetterBody is ICSharpPrecursorBody) { IsPrecursor = true; } else { IsPrecursor = false; } } if (IsPrecursor) { if (GetterBody is ICSharpPrecursorBody AsPrecursorGetterBody) { isMultiline = false; CSharpAssertion.WriteContract(writer, AsPrecursorGetterBody.RequireList, AsPrecursorGetterBody.EnsureList, CSharpContractLocations.Other, false, ref isFirstFeature, ref isMultiline); writer.WriteIndentedLine("get"); writer.WriteIndentedLine("{"); writer.IncreaseIndent(); writer.WriteIndentedLine($"return base[{ParameterEntityList}];"); writer.DecreaseIndent(); writer.WriteIndentedLine("}"); } else if (IsForcedReadWrite) { writer.WriteIndentedLine("get { throw new InvalidOperationException(); }"); } if (SetterBody is ICSharpPrecursorBody AsPrecursorSetterBody) { isMultiline = false; CSharpAssertion.WriteContract(writer, AsPrecursorSetterBody.RequireList, AsPrecursorSetterBody.EnsureList, CSharpContractLocations.Other, false, ref isFirstFeature, ref isMultiline); writer.WriteIndentedLine("set"); writer.WriteIndentedLine("{"); writer.IncreaseIndent(); writer.WriteIndentedLine($"base[{ParameterEntityList}] = value;"); writer.DecreaseIndent(); writer.WriteIndentedLine("}"); } else if (IsForcedReadWrite) { writer.WriteIndentedLine("set { throw new InvalidOperationException(); }"); } } else { if (GetterBody != null) { if (GetterBody is ICSharpEffectiveBody AsEffectiveGetterBody) { isMultiline = false; CSharpAssertion.WriteContract(writer, AsEffectiveGetterBody.RequireList, AsEffectiveGetterBody.EnsureList, CSharpContractLocations.Other, false, ref isFirstFeature, ref isMultiline); writer.WriteIndentedLine("get"); AsEffectiveGetterBody.WriteCSharp(writer, CSharpBodyFlags.MandatoryCurlyBrackets | CSharpBodyFlags.HasResult, ResultType, false, new List <string>()); } } else if (IsForcedReadWrite) { writer.WriteIndentedLine("get { throw new InvalidOperationException(); }"); } if (SetterBody != null) { if (SetterBody is ICSharpEffectiveBody AsEffectiveSetterBody) { isMultiline = false; CSharpAssertion.WriteContract(writer, AsEffectiveSetterBody.RequireList, AsEffectiveSetterBody.EnsureList, CSharpContractLocations.Other, false, ref isFirstFeature, ref isMultiline); writer.WriteIndentedLine("set"); AsEffectiveSetterBody.WriteCSharp(writer, CSharpBodyFlags.MandatoryCurlyBrackets | CSharpBodyFlags.HasValue, string.Empty, false, new List <string>()); } } else if (IsForcedReadWrite) { writer.WriteIndentedLine("set { throw new InvalidOperationException(); }"); } } writer.DecreaseIndent(); writer.WriteIndentedLine("}"); isMultiline = true; } }