Developer technologies | C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
class sample_class1
{
public static int SquareNumber(int value)
{
var expression = GetSquareExpression();
expression.Compile();
return expression(value);
}
public static Expression<Func<int, int>> GetSquareExpression()
{
return i => i * i;
}
}
class sample_class2
{
[Flags]
enum FortbildungsForm
{
Halbtagsveranstaltung = 1,
Ganztagsveranstaltung = 2,
Seminar = 4, Sonstiges = 8
}
class FortbildungsFormular : IValidatableObject
{
public FortbildungsForm? Form { get; set; }
public string? FormSonstige { get; set; }
public IEnumerable<ValidationResult> Validate(ValidationContext context)
{
if (!Form.HasValue || Form == 0)
yield return new ValidationResult("test1.", new[] { nameof(Form) });
if (Form.HasValue && (Form.Value & FortbildungsForm.Sonstiges) != 0)
yield return new ValidationResult("test2", new[]
{
nameof(FormSonstige)
});
}
}
}
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
Answer accepted by question author
In the project file <Nullable>enable</Nullable>
using System.ComponentModel.DataAnnotations;
namespace C1.Classes;
internal class SampleClass1
{
public static int SquareNumber(int value)
{
Expression<Func<int>> squared = () => value * value;
var expression = squared.Compile();
return expression();
}
}
internal class SampleClass2
{
[Flags]
enum FortbildungsForm
{
Halbtagsveranstaltung = 1,
Ganztagsveranstaltung = 2,
Seminar = 4, Sonstiges = 8
}
class FortbildungsFormular : IValidatableObject
{
public FortbildungsForm? Form { get; set; }
public string? FormSonstige { get; set; }
public IEnumerable<ValidationResult> Validate(ValidationContext context)
{
if (Form is null or 0)
{
yield return new ValidationResult("test1.", new[] { nameof(Form) });
}
if (Form.HasValue && (Form.Value & FortbildungsForm.Sonstiges) != 0)
{
yield return new ValidationResult("test2", new[]
{
nameof(FormSonstige)
});
}
}
}
}