Skip to content

Commit

Permalink
[.NET SDK] Adding the Order attribute to the FormFlow (#4236)
Browse files Browse the repository at this point in the history
  • Loading branch information
flash2048 authored and Tom Laird-McConnell committed Jun 29, 2018
1 parent 3f6da33 commit 4fbea59
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
Expand Up @@ -395,7 +395,7 @@ private void Fields(JObject schema, string prefix, IList<string> fields)
private void FieldPaths(Type type, string path, List<string> paths)
{
var newPath = (path == "" ? path : path + ".");
foreach (var field in type.GetFields(BindingFlags.Public | BindingFlags.Instance).Where(f => !f.IsDefined(typeof(IgnoreFieldAttribute))))
foreach (var field in type.GetFields(BindingFlags.Public | BindingFlags.Instance).Where(f => !f.IsDefined(typeof(IgnoreFieldAttribute))).OrderBy(f => f.GetCustomAttributes(typeof(OrderAttribute), true).Cast<OrderAttribute>().Select(a => a.Order).FirstOrDefault()))
{
TypePaths(field.FieldType, newPath + field.Name, paths);
}
Expand Down
24 changes: 24 additions & 0 deletions CSharp/Library/Microsoft.Bot.Builder/FormFlow/Attributes.cs
Expand Up @@ -726,6 +726,30 @@ public class IgnoreFieldAttribute : Attribute
public IgnoreFieldAttribute()
{ }
}

/// <summary>
/// Define a order weight of the field or property.
/// </summary>
/// <remarks>
/// By default the order weight is 0.
/// </remarks>
[Serializable]
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property)]
public class OrderAttribute : Attribute
{
private readonly int _order;

/// <summary>
/// Sets the order weight of the field or property
/// </summary>
/// <param name="order">The order weight</param>
public OrderAttribute(int order = 0)
{
_order = order;
}

public int Order => _order;
}
}

namespace Microsoft.Bot.Builder.FormFlow.Advanced
Expand Down
Expand Up @@ -461,7 +461,7 @@ public override IFormBuilder<T> AddRemainingFields(IEnumerable<string> exclude =
private void FieldPaths(Type type, string path, List<string> paths)
{
var newPath = (path == "" ? path : path + ".");
foreach (var field in type.GetFields(BindingFlags.Public | BindingFlags.Instance).Where(f => !f.IsDefined(typeof(IgnoreFieldAttribute))))
foreach (var field in type.GetFields(BindingFlags.Public | BindingFlags.Instance).Where(f => !f.IsDefined(typeof(IgnoreFieldAttribute))).OrderBy(f => f.GetCustomAttributes(typeof(OrderAttribute), true).Cast<OrderAttribute>().Select(a => a.Order).FirstOrDefault()))
{
TypePaths(field.FieldType, newPath + field.Name, paths);
}
Expand Down

0 comments on commit 4fbea59

Please sign in to comment.