public void Constructor() { var attribute = new RedirectTypeAttribute("originalAssembly", "originalType"); Assert.AreEqual("originalAssembly", attribute.OriginalAssemblyName); Assert.AreEqual("originalType", attribute.OriginalTypeName); }
public void TypeToLoad() { var attribute = new RedirectTypeAttribute("Catel.Core.Old", "Catel.DataStuff.DataObjectBase"); attribute.NewAssemblyName = "Catel.Core"; attribute.NewTypeName = "Catel.Data.DataObjectBase"; Assert.AreEqual("Catel.Data.DataObjectBase, Catel.Core", attribute.TypeToLoad); }
public void OriginalType() { var attribute = new RedirectTypeAttribute("Catel.Core.Old", "Catel.DataStuff.DataObjectBase"); Assert.AreEqual("Catel.DataStuff.DataObjectBase, Catel.Core.Old", attribute.OriginalType); }
/// <summary> /// Initializes the binder by searching for all <see cref="RedirectTypeAttribute"/> in the /// attributes passed to this method. /// </summary> /// <param name="decoratedObject">object that was decorated with the attribute.</param> /// <param name="attributes">Array of attributes to search for.</param> private void InitializeAttributes(object decoratedObject, RedirectTypeAttribute[] attributes) { if (decoratedObject == null) { return; } if (attributes.Length == 0) { return; } var type = decoratedObject as Type; foreach (var attribute in attributes) { if (type != null) { string typeName = TypeHelper.FormatType(type.Assembly.FullName, type.FullName); typeName = TypeHelper.ConvertTypeToVersionIndependentType(typeName); string finalTypeName = TypeHelper.GetTypeName(typeName); string finalAssemblyName = TypeHelper.GetAssemblyName(typeName); attribute.NewTypeName = finalTypeName; attribute.NewAssemblyName = finalAssemblyName; } if (_redirectAttributes.ContainsKey(attribute.OriginalType)) { Log.Warning("A redirect for type '{0}' is already added to '{1}'. The redirect to '{2}' will not be added", attribute.OriginalType, _redirectAttributes[attribute.OriginalType].TypeToLoad, attribute.TypeToLoad); } else { Log.Debug("Adding redirect from '{0}' to '{1}'", attribute.OriginalTypeName, attribute.NewTypeName); _redirectAttributes.Add(attribute.OriginalType, attribute); } } }