public static string Beautify(object obj) { var val = string.Empty; if (obj != null) { TypeSwitch.Do(obj, TypeSwitch.Case <string>(s => val = s), TypeSwitch.Case <DateTime?>(dt => val = string.Format("{0:yyyy-MM-dd HH:mm:ss}", dt)), TypeSwitch.Case <DateTime>(dt => val = string.Format("{0:yyyy-MM-dd HH:mm:ss}", dt)), //TypeSwitch.Case<byte[]>(b => val = BitcoinProtocolHelper.BytesToString(b)), TypeSwitch.Case <decimal?>(d => val = string.Format("{0:0.#############################}", d)), TypeSwitch.Case <decimal>(d => val = string.Format("{0:0.#############################}", d)), TypeSwitch.Case <double?>(d => val = string.Format("{0:0.#############################}", d)), TypeSwitch.Case <double>(d => val = string.Format("{0:0.#############################}", d)), TypeSwitch.Case <float?>(d => val = string.Format("{0:0.#############################}", d)), TypeSwitch.Case <float>(d => val = string.Format("{0:0.#############################}", d)), TypeSwitch.Default(() => val = obj.ToString()) ); } else { val = string.Empty; } return(val); }
private void RegisterMultipleComponentsRegistration(ComponentRegistryDefinition componentRegistryDefinition, ComponentRegistryDefinition.ComponentSetRegistrationDefinition componentSetRegistrationDefinition) { if (componentSetRegistrationDefinition.RegistrationsDefinition == null) { return; } foreach (var registration in componentSetRegistrationDefinition.RegistrationsDefinition) { TypeSwitch.Do(registration, TypeSwitch.Case <ComponentRegistryDefinition.ComponentRegistrationDefinition>(componentRegistration => { componentRegistration.Interface = componentSetRegistrationDefinition.Interface; RegisterMutipleComponentComponentRegistration( componentRegistryDefinition, componentRegistration ); }), TypeSwitch.Case <ComponentRegistryDefinition.ProxyInterfaceRegistrationDefinition>(proxyRegistration => { proxyRegistration.Interface = componentSetRegistrationDefinition.Interface; RegisterMultipleComponentProxyRegistration( componentRegistryDefinition, proxyRegistration ); }), TypeSwitch.Default(() => { throw new NotSupportedException(registration.GetType().FullName); }) ); } }
private void ValidateRequestSettings(IRequestSettings <T> config, IContactRequest typeRequest) { TypeSwitch.Do( config.mailingProvider, TypeSwitch.Case <IIContactRequest>(() => { IContactValidateRequestSettings(config, typeRequest); }), TypeSwitch.Default(() => { })); }
private static void Traverse(IGenericObject genericObject, IApp app) { if (genericObject == null) { return; } // Check if the object is an extensions of a master object. if (genericObject.Properties.ExtendsObject != null) { var masterObject = (IMasterObject)genericObject.Properties.ExtendsObject; TextHelper.WriteLine(4, "MasterObject version " + masterObject.Properties.MasterVersion); } // The information to print for each object depends on the type of the object. The TypeSwitch class can be used // for this purpose. For extensions of master objects, property values will automatically be retrieved from the // master object. TypeSwitch.Do(genericObject, TypeSwitch.Case <Table>(o => TextHelper.Print(o.GetType().Name, o.Properties.HyperCubeDef, o.Title, app)), TypeSwitch.Case <Barchart>(o => TextHelper.Print(o.GetType().Name, o.Properties.HyperCubeDef, o.Title, app)), TypeSwitch.Case <Linechart>(o => TextHelper.Print(o.GetType().Name, o.Properties.HyperCubeDef, o.Title, app)), TypeSwitch.Case <Piechart>(o => TextHelper.Print(o.GetType().Name, o.Properties.HyperCubeDef, o.Title, app)), TypeSwitch.Case <Scatterplot>(o => TextHelper.Print(o.GetType().Name, o.Properties.HyperCubeDef, o.Title, app)), TypeSwitch.Case <Treemap>(o => TextHelper.Print(o.GetType().Name, o.Properties.HyperCubeDef, o.Title, app)), TypeSwitch.Case <Gauge>(o => TextHelper.Print(o.GetType().Name, o.Properties.HyperCubeDef, o.Title, app)), TypeSwitch.Case <Combochart>(o => TextHelper.Print(o.GetType().Name, o.Properties.HyperCubeDef, o.Title, app)), TypeSwitch.Case <TextImage>(o => TextHelper.Print(o.GetType().Name, o.Properties.HyperCubeDef, o.Title, app)), TypeSwitch.Case <Listbox>(o => TextHelper.Print(o.GetType().Name, o.Title)), TypeSwitch.Case <Filterpane>(o => TextHelper.Print(o.GetType().Name, o.Title)), TypeSwitch.Case <Kpi>(o => TextHelper.Print(o.GetType().Name, o.Title)), TypeSwitch.Case <Pivottable>(o => TextHelper.Print(o.GetType().Name, o.Title)), TypeSwitch.Case <Map>(o => TextHelper.Print(o.GetType().Name, o.Title)), TypeSwitch.Default(() => TextHelper.WriteLine(4, "Unknown type: " + genericObject.GetType().FullName)) ); }
public static void Write(this MenuSuiteNode node, CSideWriter writer) { writer.Write("{ "); writer.Write(node.NodeTypeAsString()); writer.Write(";"); writer.Write("[{0}] ", node.ID.ToString("B").ToUpper()); writer.Write(";"); writer.Indent(writer.Column); IEnumerable <Property> properties = null; TypeSwitch.Do( node, TypeSwitch.Case <RootNode>(n => properties = n.Properties), TypeSwitch.Case <MenuNode>(n => properties = n.Properties), TypeSwitch.Case <GroupNode>(n => properties = n.Properties), TypeSwitch.Case <ItemNode>(n => properties = n.Properties), TypeSwitch.Case <DeltaNode>(n => properties = n.Properties) ); var relevantProperties = properties.Where(p => p.HasValue); relevantProperties.Write(PropertiesStyle.Field, writer); writer.Unindent(); writer.WriteLine("}"); }
public override ISQLBuilder Literal(object value) { if (value != null) { TypeSwitch.Do( value, TypeSwitch.Case <byte[]>(x => Emit("X'").Emit(x.ToHexString(true)).Emit("'")), TypeSwitch.Case <Guid>(x => this.Literal(x.ToByteArray())), TypeSwitch.Case <Guid?>(x => { if (x.HasValue) { this.Literal(x.Value.ToByteArray()); } else { base.Literal(null); } }), TypeSwitch.Default(() => base.Literal(value)) ); } else { base.Literal(null); } return(this); }
public void TypeSwitch_Do_WhenNullCases_ExpectException() { var case1 = new TypeSwitch.CaseInfo { IsDefault = false, Action = null, Target = typeof(object) }; TypeSwitch.Do(null, case1); }
/// <summary> /// Az adott "Target Object"-en végrehajt egy állapot visszaállÃtást. Tehát az objektum /// új értéke, az elÅ‘zÅ‘leg megadott érték lesz. /// (Például: CurrentValue = 20; OldValue = 15; -> Undo -> CurrentValue = 15; OldValue = ) /// </summary> /// <param name="eventType"> /// Az az esemény tÃpus amely meghatározza, hogy a TargetObject-en milyen tÃpusú végrehajtott /// eseményeket kell kiválasztani, majd meghatározza, hogy melyik esemény "Parancsot" kell /// visszavonni. /// </param> public void UndoLast(object eventType) { List <object> currentEventTypeList = _personEventBrokerHelpers.FillCurrentEventTypeList(eventType.GetType(), this.AllEvents); TypeSwitch.Do(eventType, TypeSwitch.Case <AgeChangedEvent>(() => _personUndoMethods.UndoLastAgeChanged(currentEventTypeList, AllEvents, this)), TypeSwitch.Case <NameChangedEvent>(() => _personUndoMethods.UndoLastNameChanged(currentEventTypeList, AllEvents, this))); }
public void SomeDlsMethod() { TypeSwitch.Do(someDslObject, TypeSwitch.Case <DslObjectA>(someDslObjectA => ...), TypeSwitch.Case <DslObjectB>(someDslObjectB => ...), TypeSwitch.Default(() => ...) ); }
public void TypeSwitch_Do_WhenCaseActionNull_ExpectException() { var case1 = new TypeSwitch.CaseInfo { IsDefault = false, Action = null, Target = typeof(object) }; var obj = new object(); TypeSwitch.Do(obj, case1); }
public void DoDoesNothingIfTypesDoNotMatchAndNoDefaultCaseExists() { TypeSwitch.Do <object>( TypeSwitch.Case <string>(() => Assert.That(false, "Expected default case, got string")), TypeSwitch.Case <bool>(() => Assert.That(false, "Expected default case, got bool")), TypeSwitch.Case <int>(() => Assert.That(false, "Expected default case, got int")), TypeSwitch.Case <float>(() => Assert.That(false, "Expected default case, got float")) ); }
public void TypeSwitch_Do_WhenDefault_ExpectActionCalled() { var wasCalled = false; var case1 = TypeSwitch.Default(delegate { wasCalled = true; }); TypeSwitch.Do(typeof(object), case1); Assert.IsTrue(wasCalled, "expected action to be called"); }
public static void Write(this PageControlBase pageControl, CSideWriter writer, int propertyIndentation) { TypeSwitch.Do( pageControl, TypeSwitch.Case <PageControlContainer>(c => c.Write(writer, propertyIndentation)), TypeSwitch.Case <PageControlGroup>(c => c.Write(writer, propertyIndentation)), TypeSwitch.Case <PageControlPart>(c => c.Write(writer, propertyIndentation)), TypeSwitch.Case <PageControl>(c => c.Write(writer, propertyIndentation))); }
public void DoSelectsCorrectCase() { TypeSwitch.Do <int>( TypeSwitch.Case <string>(() => Assert.That(false, "Expected int, got string")), TypeSwitch.Case <bool>(() => Assert.That(false, "Expected int, got bool")), TypeSwitch.Case <int>(() => {}), TypeSwitch.Case <float>(() => Assert.That(false, "Expected int, got float")) ); }
public static IDev2TOFn CreateNewDTO(IDev2TOFn dto, int index = 0, bool inserted = false, string initializeWith = "") { IDev2TOFn toReturn = null; TypeSwitch.Do(dto, // ReSharper disable ImplicitlyCapturedClosure TypeSwitch.Case <ActivityDTO>(x => toReturn = new ActivityDTO(initializeWith, "", index, inserted)), // ReSharper restore ImplicitlyCapturedClosure TypeSwitch.Case <DataSplitDTO>(x => { var dataSplitDto = dto as DataSplitDTO; if (dataSplitDto != null) { toReturn = new DataSplitDTO(initializeWith, dataSplitDto.SplitType, dataSplitDto.At, index, false, inserted); } }), TypeSwitch.Case <DataMergeDTO>(x => { var dataMergeDto = dto as DataMergeDTO; if (dataMergeDto != null) { toReturn = new DataMergeDTO(initializeWith, dataMergeDto.MergeType, dataMergeDto.At, index, dataMergeDto.Padding, dataMergeDto.Alignment, inserted); } }), TypeSwitch.Case <CaseConvertTO>(x => { var caseConvertTO = dto as CaseConvertTO; if (caseConvertTO != null) { toReturn = CaseConverterFactory.CreateCaseConverterTO(initializeWith, caseConvertTO.ConvertType, caseConvertTO.Result, index); } }), TypeSwitch.Case <BaseConvertTO>(x => { var baseConvertTO = dto as BaseConvertTO; if (baseConvertTO != null) { toReturn = new BaseConvertTO(initializeWith, baseConvertTO.FromType, baseConvertTO.ToType, baseConvertTO.ToExpression, index, inserted); } }), // ReSharper disable ImplicitlyCapturedClosure TypeSwitch.Case <GatherSystemInformationTO>(x => toReturn = // ReSharper restore ImplicitlyCapturedClosure new GatherSystemInformationTO(enTypeOfSystemInformationToGather.FullDateTime, initializeWith, index, inserted)), // ReSharper disable ImplicitlyCapturedClosure TypeSwitch.Case <XPathDTO>(x => toReturn = new XPathDTO(initializeWith, "", index, inserted)), // ReSharper restore ImplicitlyCapturedClosure // ReSharper disable ImplicitlyCapturedClosure TypeSwitch.Case <FindRecordsTO>(() => toReturn = new FindRecordsTO("", "", index, inserted)), // ReSharper restore ImplicitlyCapturedClosure // ReSharper disable ImplicitlyCapturedClosure TypeSwitch.Default(() => toReturn = null)); // ReSharper restore ImplicitlyCapturedClosure return(toReturn); }
public void TypeSwitch_Do_WhenSourceNullAndNoDefaultAction_ExpectException() { var act = new Action <object>(delegate { }); var case1 = new TypeSwitch.CaseInfo { IsDefault = false, Action = act, Target = typeof(object) }; TypeSwitch.Do(null, case1); }
private void ConfigureRequest(HttpWebRequest request, IRequestSettings <T> config) { TypeSwitch.Do( config.mailingProvider, TypeSwitch.Case <IIContactRequest>(() => { //IContactConfigureRequest(request, config); IContactConfigureRequestJson(request, config); }), TypeSwitch.Default(() => { })); }
public static void Write(this ReportElement reportElement, CSideWriter writer) { string type = null; TypeSwitch.Do( reportElement, TypeSwitch.Case <DataItemReportElement>(e => type = "DataItem"), TypeSwitch.Case <ColumnReportElement>(e => type = "Column")); var debt = 0; var elementID = BuildReportElementPart(reportElement.ID.ToString(), 4, ref debt); var elementIndentation = BuildReportElementPart(reportElement.IndentationLevel.AsString(), 4, ref debt); var elementType = BuildReportElementPart(type, 8, ref debt); var elementName = BuildReportElementPart(reportElement.Name ?? string.Empty, 20, ref debt); var declaration = string.Format("{{ {0};{1};{2};{3}", elementID, elementIndentation, elementType, elementName); writer.Write(declaration); writer.Indent(15); IEnumerable <Property> properties = null; TypeSwitch.Do( reportElement, TypeSwitch.Case <DataItemReportElement>(e => properties = e.Properties), TypeSwitch.Case <ColumnReportElement>(e => properties = e.Properties)); var relevantProperties = properties.Where(p => p.HasValue); switch (relevantProperties.Any()) { case true: writer.WriteLine(";"); relevantProperties.Write(PropertiesStyle.Field, writer); break; default: writer.Write(" "); break; } var lastProperty = relevantProperties.LastOrDefault(); if (lastProperty != null) { if (lastProperty is TriggerProperty) { writer.Write(new string(' ', lastProperty.Name.Length + 2)); } } writer.WriteLine("}"); writer.Unindent(); writer.InnerWriter.WriteLine(); }
private string CreatetUriRequest(T mailingProvider, IContactRequest typeRequest) { string uri = string.Empty; TypeSwitch.Do( mailingProvider, TypeSwitch.Case <IIContactRequest>(() => { uri = IContactCreatetUriRequest(mailingProvider, typeRequest); }), TypeSwitch.Default(() => { uri = string.Empty; })); return(uri); }
public void TypeSwitch_Do_WhenCaseActionNull_ExpectActionSet() { //------------Setup for test-------------------------- TypeSwitch.CaseInfo case1 = new TypeSwitch.CaseInfo { IsDefault = false, Action = null, Target = typeof(object) }; var obj = new object(); //------------Execute Test--------------------------- TypeSwitch.Do(obj, case1); }
public void TypeSwitch_Do_WhenNullCases_ExpectException() { //------------Setup for test-------------------------- TypeSwitch.CaseInfo case1 = new TypeSwitch.CaseInfo { IsDefault = false, Action = null, Target = typeof(object) }; //------------Execute Test--------------------------- TypeSwitch.Do(null, case1); }
public void TypeSwitch_Do_WhenSourceNullAndDefaultActionNotNull_ExpectNullActionValue() { var act = new Action <object>(delegate { }); var case1 = new TypeSwitch.CaseInfo { IsDefault = true, Action = act, Target = typeof(object) }; TypeSwitch.Do(null, case1); Assert.AreEqual(null, case1.Target.DeclaringType); }
public static void Write(this FormControlBase formControl, CSideWriter writer, int propertyIndentation) { TypeSwitch.Do( formControl, /*TypeSwitch.Case<PageControlContainer>(c => c.Write(writer, propertyIndentation)), * TypeSwitch.Case<PageControlGroup>(c => c.Write(writer, propertyIndentation)), * TypeSwitch.Case<PageControlPart>(c => c.Write(writer, propertyIndentation)),*/ //TypeSwitch.Case<FormMenuButtonControl>(m => m.Write(writer, propertyIndentation)), TypeSwitch.Case <FormControl>(c => c.Write(writer, propertyIndentation))); }
void OnReturnInstanceSignalDispatched(PoolableView view) { TypeSwitch.Do( view, TypeSwitch.Case <PlayerShipLaserView>(x => playerLaserPool.ReturnInstance(x)), TypeSwitch.Case <AsteroidView>(x => asteroidPool.ReturnInstance(x)), TypeSwitch.Case <EnemyShipView>(x => enemyShipPool.ReturnInstance(x)), TypeSwitch.Default(() => { throw new NotSupportedException("This view can not supported!!!!!"); }) ); }
public void TypeSwitch_Do_WhenSourceNullAndNoDefaultAction_ExpectException() { //------------Setup for test-------------------------- var act = new Action <object>(delegate { }); TypeSwitch.CaseInfo case1 = new TypeSwitch.CaseInfo { IsDefault = false, Action = act, Target = typeof(object) }; //------------Execute Test--------------------------- TypeSwitch.Do(null, case1); }
public void TypeSwitch_Do_WhenCaseActionNotNull_ExpectActionSet() { var wasCalled = false; var action = new Action(delegate { wasCalled = true; }); var case1 = TypeSwitch.Case <object>(action); var obj = new object(); TypeSwitch.Do(obj, case1); Assert.IsTrue(wasCalled, "expected action to be called"); }
public static void Write(this XmlPortNode xmlPortNode, CSideWriter writer) { TypeSwitch.Do( xmlPortNode, TypeSwitch.Case <XmlPortTextElement>(n => n.Write(writer)), TypeSwitch.Case <XmlPortTextAttribute>(n => n.Write(writer)), TypeSwitch.Case <XmlPortTableElement>(n => n.Write(writer)), TypeSwitch.Case <XmlPortTableAttribute>(n => n.Write(writer)), TypeSwitch.Case <XmlPortFieldElement>(n => n.Write(writer)), TypeSwitch.Case <XmlPortFieldAttribute>(n => n.Write(writer)) ); }
public virtual ISQLBuilder Literal(object value) { if (value == null || value == DBNull.Value) { return(Emit("NULL")); } TypeSwitch.Do(value, TypeSwitch.Case <SQLBuilderCommand>(c => { c.Execute(this.LeafBuilder); }), TypeSwitch.Default(() => Emit(value.ToSQLString())) ); return(this); }
private IDataType GetDataType() { var dataType = string.Empty; TypeSwitch.Do( CurrentColumnInfo.Column.FieldNameType, TypeSwitch.Case <string>(() => dataType = "StringDataType"), TypeSwitch.Case <DateTime>(() => dataType = "DatetimeDataType"), TypeSwitch.Case <DateTime?>(() => dataType = "DatetimeDataType"), TypeSwitch.Default(() => dataType = "DefaultType") ); return(DataTypeFactory.GetInstance().CreateInstance(dataType)); }
public static IDev2TOFn CreateNewDTO(IDev2TOFn dto, int index, bool inserted, string initializeWith) { IDev2TOFn toReturn = null; TypeSwitch.Do(dto, TypeSwitch.Case <ActivityDTO>(x => toReturn = new ActivityDTO(initializeWith, "", index, inserted)), TypeSwitch.Case <DataSplitDTO>(x => { if (dto is DataSplitDTO dataSplitDto) { toReturn = new DataSplitDTO(initializeWith, dataSplitDto.SplitType, dataSplitDto.At, index, false, inserted); } }), TypeSwitch.Case <DataMergeDTO>(x => { if (dto is DataMergeDTO dataMergeDto) { toReturn = new DataMergeDTO(initializeWith, dataMergeDto.MergeType, dataMergeDto.At, index, dataMergeDto.Padding, dataMergeDto.Alignment, inserted); } }), TypeSwitch.Case <CaseConvertTO>(x => { if (dto is CaseConvertTO caseConvertTO) { toReturn = CaseConverterFactory.CreateCaseConverterTO(initializeWith, caseConvertTO.ConvertType, caseConvertTO.Result, index); } }), TypeSwitch.Case <BaseConvertTO>(x => { if (dto is BaseConvertTO baseConvertTO) { toReturn = new BaseConvertTO(initializeWith, baseConvertTO.FromType, baseConvertTO.ToType, baseConvertTO.ToExpression, index, inserted); } }), TypeSwitch.Case <GatherSystemInformationTO>(x => toReturn = new GatherSystemInformationTO(enTypeOfSystemInformationToGather.FullDateTime, initializeWith, index, inserted)), TypeSwitch.Case <XPathDTO>(x => toReturn = new XPathDTO(initializeWith, "", index, inserted)), TypeSwitch.Case <FindRecordsTO>(() => toReturn = new FindRecordsTO("", "", index, inserted)), TypeSwitch.Case <DecisionTO>(() => toReturn = new DecisionTO(initializeWith, "", "", index, inserted)), TypeSwitch.Case <JsonMappingTo>(() => toReturn = new JsonMappingTo(initializeWith, index, inserted)), TypeSwitch.Case <SharepointSearchTo>(() => toReturn = new SharepointSearchTo(initializeWith, "=", "", index, inserted)), TypeSwitch.Case <SharepointReadListTo>(() => toReturn = new SharepointReadListTo("", initializeWith, "", "")), TypeSwitch.Case <AssignObjectDTO>(x => toReturn = new AssignObjectDTO(initializeWith, "", index, inserted)), TypeSwitch.Default(() => toReturn = null)); return(toReturn); }