Skip to content

Instantly share code, notes, and snippets.

View SamerX's full-sized avatar
🎯
Focusing

Samer Aburabie SamerX

🎯
Focusing
View GitHub Profile
@SamerX
SamerX / gist:0db02174db7e9dc6c02e60d8767543e9
Created February 12, 2020 11:25
AngularValidationUsage
<input type="text"[(ngModel)]="FullName" name="FullName" [NotNull]="Enter note text" [NotNullCondition]="CustomerIsAbove18" />
@SamerX
SamerX / gist:4067abeba25580921253c8afedc89bf8
Last active February 12, 2020 11:21
AngularConditionalValidation
import { Directive, Input, TemplateRef, NgModule, EventEmitter, Output } from '@angular/core';
import { NG_VALIDATORS, Validator, AbstractControl, ValidatorFn } from '@angular/forms';
//Description: This validator acts almost the same way as required validator, the difference is this validator validates the ngModel
//and is helpful for custom controls like ng-select where the required validator fails.
@Directive({
selector: '[NotNull]',
providers: [{ provide: NG_VALIDATORS, useExisting: NotNullValidatorDirective, multi: true }]
})
export class NotNullValidatorDirective implements Validator {
constructor() {
@SamerX
SamerX / NHibernate GetMappingSteps
Created November 20, 2019 08:42
NHibernate GetMappingSteps
public override IEnumerable<IAutomappingStep> GetMappingSteps(AutoMapper mapper, FluentNHibernate.Conventions.IConventionFinder conventionFinder)
{
//SamerA: Replace the original HasManyToManyStep with the Customized HasManyToManyStep to allow Unidirectional ManyToMany
//Mapping when the other side has no reference for the current side.
//NOTE: an alternative to the below code is to redefine all steps with the CustomHasManyToManyStep here, the only preference is use
//the already created steps instead of creating new ones along with the old ones.
//Get all defined steps
var steps = base.GetMappingSteps(mapper, conventionFinder).ToList();
var index = steps.FindIndex(x => x.GetType() == typeof(HasManyToManyStep));
steps.RemoveAt(index);
@SamerX
SamerX / NHibernate CustomHasManyToManyStep
Last active November 20, 2019 08:37
NHibernate CustomHasManyToManyStep
public class CustomHasManyToManyStep : IAutomappingStep
{
private readonly IAutomappingConfiguration cfg;
public CustomHasManyToManyStep(IAutomappingConfiguration cfg)
{
this.cfg = cfg;
}
public bool ShouldMap(Member member)
{
var type = member.PropertyType;