Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 24 additions & 24 deletions CalcBinding/CalcBinding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace CalcBinding
/// </summary>
public sealed class Binding : MarkupExtension
{
// We cannot use PropertyPath instead of string (such as standart Binding) because transformation from xaml value string to Property path
// We cannot use PropertyPath instead of string (such as standard Binding) because transformation from xaml value string to Property path
// is doing automatically by PropertyPathConverter and result PropertyPath object could have form, that cannot retranslate to normal string.
// e.g.: (local:MyStaticVM.Prop) -> PropertyPath.Path = (0), Converted to string = MyStaticVM.Prop (but we need to analyze static class with xaml namespace prefix)
public string Path { get; set; }
Expand All @@ -29,10 +29,10 @@ public sealed class Binding : MarkupExtension
public FalseToVisibility FalseToVisibility { get; set; } = FalseToVisibility.Collapsed;

/// <summary>
/// If true then single quotes and double quotes are considered as single quotes, otherwise - both are considerent as double quotes
/// If true then single quotes and double quotes are considered as single quotes, otherwise - both are considerate as double quotes
/// </summary>
/// <remarks>
/// Use this flag if you need to use char is path expresion
/// Use this flag if you need to use char is path expression
/// </remarks>
public bool SingleQuotes { get; set; } = false;

Expand Down Expand Up @@ -61,23 +61,23 @@ public override object ProvideValue(IServiceProvider serviceProvider)
var typeDescriptor = serviceProvider as ITypeDescriptorContext;

var normalizedPath = NormalizePath(Path);
var pathes = GetSourcePathes(normalizedPath, typeResolver);
var paths = GetSourcePaths(normalizedPath, typeResolver);

var expressionTemplate = GetExpressionTemplate(normalizedPath, pathes, out Dictionary<string, Type> enumParameters);
var expressionTemplate = GetExpressionTemplate(normalizedPath, paths, out Dictionary<string, Type> enumParameters);

var mathConverter = new CalcConverter(_parser.Value, FallbackValue, enumParameters)
{
FalseToVisibility = FalseToVisibility,
StringFormatDefined = StringFormat != null,
};

var bindingPathes = pathes
var bindingPaths = paths
.Where(p => p.PathId.PathType == PathTokenType.Property ||
p.PathId.PathType == PathTokenType.StaticProperty).ToList();

BindingBase resBinding;

if (bindingPathes.Count == 1)
if (bindingPaths.Count == 1)
{
// todo: can enums be binded ? What if one value is Enum? bug..
var binding = new System.Windows.Data.Binding()
Expand All @@ -96,13 +96,13 @@ public override object ProvideValue(IServiceProvider serviceProvider)
#endif
};

var pathId = bindingPathes.Single().PathId;
var pathId = bindingPaths.Single().PathId;
// we need to use convert from string for support of static properties
var pathValue = pathId.Value;

if (pathId.PathType == PathTokenType.StaticProperty)
{
pathValue = string.Format("({0})", pathValue); // need to use brackets for Static property recognition in standart binding
pathValue = string.Format("({0})", pathValue); // need to use brackets for Static property recognition in standard binding
}
var resPath = (PropertyPath)new PropertyPathConverter().ConvertFromString(typeDescriptor, pathValue);
binding.Path = resPath;
Expand All @@ -119,7 +119,7 @@ public override object ProvideValue(IServiceProvider serviceProvider)
if (StringFormat != null)
binding.StringFormat = StringFormat;

// we don't use converter if binding is trivial - {0}, except type convertion from bool to visibility
// we don't use converter if binding is trivial - {0}, except type conversion from bool to visibility

//todo: use more smart recognition for template (with analysing brackets ({1}) any count )
// trivial binding, CalcBinding converter is not needed
Expand Down Expand Up @@ -155,7 +155,7 @@ public override object ProvideValue(IServiceProvider serviceProvider)
if (StringFormat != null)
mBinding.StringFormat = StringFormat;

foreach (var path in bindingPathes)
foreach (var path in bindingPaths)
{
var binding = new System.Windows.Data.Binding();

Expand All @@ -164,7 +164,7 @@ public override object ProvideValue(IServiceProvider serviceProvider)

if (path.PathId.PathType == PathTokenType.StaticProperty)
{
pathValue = string.Format("({0})", pathValue); // need to use brackets for Static property recognition in standart binding
pathValue = string.Format("({0})", pathValue); // need to use brackets for Static property recognition in standard binding
}

var resPath = (PropertyPath)new PropertyPathConverter().ConvertFromString(typeDescriptor, pathValue);
Expand Down Expand Up @@ -213,10 +213,10 @@ private Type GetPropertyType(IServiceProvider serviceProvider)
}

/// <summary>
/// Replace source properties pathes by its numbers
/// Replace source properties paths by its numbers
/// </summary>
/// <param name="path"></param>
/// <param name="pathes"></param>
/// <param name="paths"></param>
/// <returns></returns>
private string GetExpressionTemplate(string path, List<PathAppearances> properties, out Dictionary<string, Type> enumParameters)
{
Expand All @@ -235,7 +235,7 @@ private string GetExpressionTemplate(string path, List<PathAppearances> properti
{
var propGroup = properties[index];
var propId = propGroup.PathId;
var targetProp = propGroup.Pathes.FirstOrDefault(token => token.Start == sourceIndex);
var targetProp = propGroup.paths.FirstOrDefault(token => token.Start == sourceIndex);

if (targetProp != null)
{
Expand All @@ -260,7 +260,7 @@ private string GetExpressionTemplate(string path, List<PathAppearances> properti
}
else if (propId.PathType == PathTokenType.Enum)
{
var enumPath = propGroup.Pathes.First() as EnumToken;
var enumPath = propGroup.paths.First() as EnumToken;

string enumTypeName = null;
if (enumNames.ContainsKey(propId))
Expand Down Expand Up @@ -302,17 +302,17 @@ private string GetEnumName(int i)
}

/// <summary>
/// Find all sourceProperties pathes in Path string
/// Find all sourceProperties paths in Path string
/// </summary>
/// <param name="normPath"></param>
/// <returns>List of pathes and its start positions</returns>
private List<PathAppearances> GetSourcePathes(string normPath, IXamlTypeResolver typeResolver)
/// <returns>List of paths and its start positions</returns>
private List<PathAppearances> GetSourcePaths(string normPath, IXamlTypeResolver typeResolver)
{
var propertyPathAnalyzer = new PropertyPathAnalyzer();

var pathes = propertyPathAnalyzer.GetPathes(normPath, typeResolver);
var paths = propertyPathAnalyzer.GetPaths(normPath, typeResolver);

var propertiesGroups = pathes.GroupBy(p => p.Id).Select(p => new PathAppearances(p.Key, p.ToList())).ToList();
var propertiesGroups = paths.GroupBy(p => p.Id).Select(p => new PathAppearances(p.Key, p.ToList())).ToList();

return propertiesGroups;
}
Expand Down Expand Up @@ -551,12 +551,12 @@ class PathAppearances
{
public PathTokenId PathId { get; private set; }

public IEnumerable<PathToken> Pathes { get; private set; }
public IEnumerable<PathToken> Paths { get; private set; }

public PathAppearances(PathTokenId id, List<PathToken> pathes)
public PathAppearances(PathTokenId id, List<PathToken> paths)
{
PathId = id;
Pathes = pathes;
Paths = paths;
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions CalcBinding/PathAnalysis/PropertyPathAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
namespace CalcBinding.PathAnalysis
{
/// <summary>
/// Idea of parser: to detect right all entries of property pathes, static property pathes etc. without parsing language structures
/// For full validation of expression there need to write own analizer of C# lanquage whick could determine xaml names too...
/// Idea of parser: to detect right all entries of property paths, static property paths etc. without parsing language structures
/// For full validation of expression there need to write own analyzer of C# language which could determine xaml names too...
/// </summary>
public class PropertyPathAnalyzer
{
Expand Down Expand Up @@ -55,16 +55,16 @@ static PropertyPathAnalyzer()

#region Parser cycle

public List<PathToken> GetPathes(string normPath, IXamlTypeResolver typeResolver)
public List<PathToken> GetPaths(string normPath, IXamlTypeResolver typeResolver)
{
_typeResolver = typeResolver;

Tracer.TraceDebug(string.Format("Start read {0} ", normPath));

var chunks = GetChunks(normPath);
var pathes = GetPathes(chunks);
var paths = GetPaths(chunks);

return pathes;
return paths;
}

private List<Chunk> GetChunks(string str)
Expand Down Expand Up @@ -126,7 +126,7 @@ private List<Chunk> GetChunks(string str)
} while (true);
}

private List<PathToken> GetPathes(List<Chunk> chunks)
private List<PathToken> GetPaths(List<Chunk> chunks)
{
List<PathToken> tokens = new List<PathToken>();

Expand Down
Loading