Search

Geniously efficient code in Microsoft.Expression.Interactions.dll by Andrii.C.Sharp

Active

1
0
Sign in
to vote
Type: Bug
ID: 773859
Opened: 12/8/2012 1:03:55 PM
Access Restriction: Public
0
Workaround(s)
0
User(s) can reproduce this bug
Look at this (line 2, it is from TypeConverterHelper class):
StringBuilder builder = new StringBuilder();
builder.Append("<ContentControl xmlns='http://schemas.microsoft.com/client/2007' xmlns:c='" + ("clr-namespace:" + nullableType.Namespace + ";assembly=" + nullableType.Assembly.FullName.Split(new char[] { ',' })[0]) + "'>\n");
builder.Append("<c:" + nullableType.Name + ">\n");
builder.Append(a);
builder.Append("</c:" + nullableType.Name + ">\n");
builder.Append("</ContentControl>");

It is similar to
bool a;
...
if (a.ToStrng().Length == 4)


Maybe this way it will work better:
builder.AppendFormat("<ContentControl xmlns='http://schemas.microsoft.com/client/2007' xmlns:c='{0}'>\n", string.Concat("clr-namespace:", nullableType.Namespace, ";assembly=", nullableType.GetTypeInfo().Assembly.FullName.Split(new char[] { ',' })[0]));
builder.AppendFormat("<c:{0}>\n", nullableType.Name);
builder.Append(a);
builder.AppendFormat("</c:{0}>\n", nullableType.Name);
builder.Append("</ContentControl>");
Details (expand)

Product?

Blend

Product Version?

 

Blend 4 SP1 (4.0.20901.0)

Issue Type?

Suggestion

Repro Steps? (N/A for Suggestion)

 
File Attachments
0 attachments
Sign in to post a comment.
Posted by Andrii.C.Sharp on 12/15/2012 at 7:00 AM
Look also at this:

private void ValidateStateName(string stateName)
{
    if ((base.AssociatedObject != null) && !string.IsNullOrEmpty(stateName))
    {
        foreach (VisualState state in this.TargetedVisualStates) // <<<<<<<<<<<<<<<<<< HERE! It can be written in 1 line without additional method!!! Example is below
        {
            if (stateName == state.Name)
            {
                return;
            }
        }
        throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, ExceptionStringTable.DataStateBehaviorStateNameNotFoundExceptionMessage, new object[] { stateName, (this.TargetObject != null) ? this.TargetObject.GetType().Name : "null" }));
    }
}

private IEnumerable<VisualState> TargetedVisualStates
{
    get
    {
        List<VisualState> list = new List<VisualState>();
        if (this.TargetObject != null)
        {
            foreach (VisualStateGroup group in VisualStateUtilities.GetVisualStateGroups(this.TargetObject))
            {
                foreach (VisualState state in group.States)
                {
                    list.Add(state);
                }
            }
        }
        return list;
    }
}


And look at this:

        private void ValidateStateName(string stateName)
        {
            if ((base.AssociatedObject != null) && !string.IsNullOrEmpty(stateName))
            {
                if (!VisualStateUtilities.GetVisualStateGroups(this.TargetObject)
                        .Any(visualStateGroup => visualStateGroup.States
                            .Any(visualState => visualState.Name == stateName)))
                {
                    throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, ExceptionStringTableHelper.DataStateBehaviorStateNameNotFoundExceptionMessage, new object[] { stateName, (this.TargetObject != null) ? this.TargetObject.GetType().Name : "null" }));
                }
            }
        }

Which option is better?
Posted by Microsoft on 12/11/2012 at 3:59 PM
Thanks for your feedback, we will look into this and fix this in future release of Blend / Visual Studio.
Sign in to post a workaround.