public void canReflectOn() { var member = ReflectOn <ReflectionTests> .Member(t => t.ProtectedProperty); Assert.IsNotNull(member); Assert.AreEqual(member.Name, "ProtectedProperty"); }
public void Describe(DescribeContext context) { Func <IShapeFactory, dynamic> formFactory = shape => { var form = this.Shape.Form( Id: ConditionalBranchTask.EventName, _Type: this.Shape.FieldSet( Title: this.T("Resume the workflow on a conditional branch."), _FirstBranch: this.Shape.Textbox( Id: ReflectOn <ConditionalBranchViewModel> .NameOf(x => x.FirstBranch), Name: ReflectOn <ConditionalBranchViewModel> .NameOf(x => x.FirstBranch), Title: this.T("The first branch"), Description: this.T("A comma separated list of something"), Classes: new[] { "text", "large", "tokenized" }), _SecondBranch: this.Shape.Textbox( Id: ReflectOn <ConditionalBranchViewModel> .NameOf(x => x.SecondBranch), Name: ReflectOn <ConditionalBranchViewModel> .NameOf(x => x.SecondBranch), Title: this.T("The second branch"), Description: this.T("A comma separated list of something"), Classes: new[] { "text", "large", "tokenized" }), _ThirdBranch: this.Shape.Checkbox( Id: ReflectOn <ConditionalBranchViewModel> .NameOf(x => x.ThirdBranch), Name: ReflectOn <ConditionalBranchViewModel> .NameOf(x => x.ThirdBranch), Title: this.T("The third branch"), Description: this.T("Check to enable the branch"), Value: false) )); return(form); }; context.Form(ConditionalBranchTask.EventName, formFactory); }
// Ripped from the original BranchActivity and modified private static IEnumerable <string> GetBranches(ActivityContext context) { var branches = new List <string>(); var firstBranch = context.GetState <string>(ReflectOn <ConditionalBranchViewModel> .NameOf(x => x.FirstBranch)); if (firstBranch != null) { branches.Add(FirstBranchOutcome); } var secondBranch = context.GetState <string>(ReflectOn <ConditionalBranchViewModel> .NameOf(x => x.SecondBranch)); if (!string.IsNullOrEmpty(secondBranch)) { branches.AddRange(secondBranch.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(x => x.Trim()).ToList()); } var thirdBranch = context.GetState <bool>(ReflectOn <ConditionalBranchViewModel> .NameOf(x => x.ThirdBranch)); if (thirdBranch) { branches.Add(ThirdBranchOutcome); } branches.AddRange(new[] { ErrorOutcome, DoneOutcome }); return(branches); }
public RootClassDescriptor <T> HideMember <TMember>(Expression <Func <T, TMember> > expression) { var member = ReflectOn <T> .ForMember(expression); MemberVisibility[member.Name] = false; return(this); }
public void ReflectOnShouldWorkOnIndexers() { Assert.That(ReflectOn <TestClass> .NameOf(p => p[0].MyTestClass[1].MyProperty), Is.EqualTo("[0].MyTestClass[1].MyProperty")); int j = 5; int index = j; Assert.That(ReflectOn <TestClass> .NameOf(p => p.MyTestClass[index].MyProperty), Is.EqualTo("MyTestClass[5].MyProperty")); }
public void Ignore_Return_Type() { MethodInfo doSomething = ReflectOn <Subject> .ForMethod(x => x.DoSomething(null)); ClassMethodDescriptor descriptor = new ClassMethodDescriptor(doSomething); Assert.That(descriptor.Key, Is.EqualTo("DoSomething(String)")); }
public static void CreateIndexForSingleColumn <TRecord>(this AlterTableCommand self, Expression <Func <TRecord, object> > expression, string indexNameOverride = null) { var property = ReflectOn <TRecord> .NameOf(expression); var indexName = indexNameOverride.HasValue() ? indexNameOverride : CreateIndexKeyName <TRecord>(expression); self.CreateIndex(indexName, new[] { property }); }
public void Void_With_Parameters_Method_Should_Return_The_Method_Name_And_Coma_Delimited_List_Of_Parameter_Types() { MethodInfo doSomething = ReflectOn <Subject> .ForMethod(x => x.DoSomething(null, null, null)); ClassMethodDescriptor descriptor = new ClassMethodDescriptor(doSomething); Assert.That(descriptor.Key, Is.EqualTo("DoSomething(String, Nullable<DateTime>, Subject)")); }
public void Simple_Parameterless_Void_Method_Should_Return_The_Method_Name() { MethodInfo doSomething = ReflectOn <Subject> .ForMethod(x => x.DoSomething()); ClassMethodDescriptor descriptor = new ClassMethodDescriptor(doSomething); Assert.That(descriptor.Key, Is.EqualTo("DoSomething()")); }
public void ReflectOnShouldWorkOnMethods() { Assert.That(ReflectOn <TestClass> .GetMethod(p => p.MyMethod(5)).Name, Is.EqualTo("MyMethod")); Assert.That(ReflectOn <TestClass> .GetMethod(p => p.MyMethod("")).Name, Is.EqualTo("MyMethod")); Assert.That(ReflectOn <TestClass> .GetMethod(p => p.MyMethod("")).ReturnType, Is.EqualTo(typeof(int))); Assert.That(ReflectOn <TestClass> .GetMethod(p => p.MyMethod2(5)).Name, Is.EqualTo("MyMethod2")); Assert.That(ReflectOn <TestClass> .GetMethod(p => p.MyMethod2("")).Name, Is.EqualTo("MyMethod2")); Assert.That(ReflectOn <TestClass> .GetMethod(p => p.MyMethod2("")).ReturnType, Is.EqualTo(typeof(int))); }
/// <summary>Creates a column with the name of TBaseRecordProperty_Id. This follows the standard orchard conventions.</summary> /// <typeparam name="TForeignRecord">The Record-Type of the virtual property.</typeparam> /// <typeparam name="TBaseRecord">The ContentPartRecord holding the virtual property pointing to the foreign record.</typeparam> /// <param name="self">A CreateTableCommand</param> /// <param name="expression">An expression to get the virtual property.</param> /// <param name="column">Actions to alter the column further.</param> /// <returns>The CreateTableCommand</returns> public static CreateTableCommand ColumnForForeignKey <TForeignRecord, TBaseRecord>(this CreateTableCommand self, Expression <Func <TBaseRecord, TForeignRecord> > expression, Action <CreateColumnCommand> column = null) { var dbType = SchemaUtils.ToDbType(typeof(int)); var property = ReflectOn <TBaseRecord> .NameOf(expression); var columnName = string.Format("{0}_Id", property); return(self.Column(columnName, dbType, column)); }
public override IEnumerable <LocalizedString> Execute(WorkflowContext workflowContext, ActivityContext activityContext) { // Do whatever here.... // This stuff here is obviously pretty useless and only exists to see if the activity works. var possibleOutcomes = GetBranches(activityContext); var firstBranchValue = activityContext.GetState <string>(ReflectOn <ConditionalBranchViewModel> .NameOf(x => x.FirstBranch)); if (possibleOutcomes.Contains(FirstBranchOutcome) && !string.IsNullOrWhiteSpace(firstBranchValue) && firstBranchValue.Equals("ThrowError", StringComparison.OrdinalIgnoreCase)) { yield return(this.T(ErrorOutcome)); } else { foreach (var outcome in possibleOutcomes) { yield return(this.T(outcome)); } } }
public ReflectFluidOn <T> AddNameOf(Expression <Action <T> > expression) { this.memberNames.Add(ReflectOn <T> .NameOf(expression)); return(this); }
public void ReflectOnShouldWorkOnDottedProperties() { Assert.That(ReflectOn <TestClass> .NameOf(p => p.MyTestClass.MyTestClass.MyProperty), Is.EqualTo("MyTestClass.MyTestClass.MyProperty")); }
public void ReflectOnShouldWorkOnProperties() { Assert.That(ReflectOn <TestClass> .GetProperty(p => p.MyProperty).Name, Is.EqualTo("MyProperty")); Assert.That(ReflectOn <TestClass> .GetProperty(p => p.MyProperty2).Name, Is.EqualTo("MyProperty2")); }
public void ReflectOnShouldWorkOnFields() { Assert.That(ReflectOn <TestClass> .GetField(p => p.MyField).Name, Is.EqualTo("MyField")); Assert.That(ReflectOn <TestClass> .GetField(p => p.MyField2).Name, Is.EqualTo("MyField2")); }
public void ReflectOnGetMemberShouldReturnCorrectMemberInfo() { Assert.That(ReflectOn <TestClass> .GetMember(p => p.MyField).Name, Is.EqualTo("MyField")); Assert.That(ReflectOn <TestClass> .GetMember(p => p.MyMethod(5)).Name, Is.EqualTo("MyMethod")); }
public ForMemberDescriptor <T> ForMember <TMember>(Expression <Func <T, TMember> > expression) { return(new ForMemberDescriptor <T>(this, ReflectOn <T> .ForMember(expression))); }
public static string CreateIndexKeyName <TRecord>(Expression <Func <TRecord, object> > expression) { var property = ReflectOn <TRecord> .NameOf(expression); return(string.Format("IX_{0}_{1}", typeof(TRecord).FullName, property)); }
public ReflectFluidOn <T> AddNameOf <TResult>(Expression <Func <T, TResult> > expression) { this.memberNames.Add(ReflectOn <T> .NameOf(expression)); return(this); }
public ForMemberDescriptor <TMember> CustomerDiagram <TForMember>(Expression <Func <TMember, TForMember> > expression) { return(new ForMemberDescriptor <TMember>(_descriptor, ReflectOn <TMember> .ForMember(expression))); }