public void Equivalence () { var a1 = new AttachableMemberIdentifier (typeof (string), "Foo"); var a2 = new AttachableMemberIdentifier (typeof (string), "Foo"); var a3 = new AttachableMemberIdentifier (null, "Foo"); var a4 = new AttachableMemberIdentifier (null, "Foo"); var a5 = new AttachableMemberIdentifier (typeof (string), null); var a6 = new AttachableMemberIdentifier (typeof (string), null); Assert.IsTrue (a1 == a2, "#1"); Assert.IsFalse (a1 == a3, "#2"); Assert.IsFalse (a1 == a5, "#3"); Assert.IsTrue (a3 == a4, "#4"); Assert.IsFalse (a3 == a1, "#5"); Assert.IsFalse (a3 == a5, "#6"); Assert.IsTrue (a5 == a6, "#7"); Assert.IsFalse (a5 == a1, "#8"); Assert.IsFalse (a5 == a3, "#9"); Assert.IsTrue (a1.Equals (a2),"#11"); Assert.IsFalse (a1.Equals (a3),"#12"); Assert.IsFalse (a1.Equals (a5),"#13"); Assert.IsTrue (a3.Equals (a4),"#14"); Assert.IsFalse (a3.Equals (a1),"#15"); Assert.IsFalse (a3.Equals (a5),"#16"); Assert.IsTrue (a5.Equals (a6),"#17"); Assert.IsFalse (a5.Equals (a1),"#18"); Assert.IsFalse (a5.Equals (a3),"#19"); }
public void Equivalence() { var a1 = new AttachableMemberIdentifier(typeof(string), "Foo"); var a2 = new AttachableMemberIdentifier(typeof(string), "Foo"); var a3 = new AttachableMemberIdentifier(null, "Foo"); var a4 = new AttachableMemberIdentifier(null, "Foo"); var a5 = new AttachableMemberIdentifier(typeof(string), null); var a6 = new AttachableMemberIdentifier(typeof(string), null); Assert.IsTrue(a1 == a2, "#1"); Assert.IsFalse(a1 == a3, "#2"); Assert.IsFalse(a1 == a5, "#3"); Assert.IsTrue(a3 == a4, "#4"); Assert.IsFalse(a3 == a1, "#5"); Assert.IsFalse(a3 == a5, "#6"); Assert.IsTrue(a5 == a6, "#7"); Assert.IsFalse(a5 == a1, "#8"); Assert.IsFalse(a5 == a3, "#9"); Assert.IsTrue(a1.Equals(a2), "#11"); Assert.IsFalse(a1.Equals(a3), "#12"); Assert.IsFalse(a1.Equals(a5), "#13"); Assert.IsTrue(a3.Equals(a4), "#14"); Assert.IsFalse(a3.Equals(a1), "#15"); Assert.IsFalse(a3.Equals(a5), "#16"); Assert.IsTrue(a5.Equals(a6), "#17"); Assert.IsFalse(a5.Equals(a1), "#18"); Assert.IsFalse(a5.Equals(a3), "#19"); }
/// <summary> /// Sets a value for the specified attachable member in the specified /// store. /// </summary> /// <param name="attachableMemberIdentifier"> /// The XAML type system identifier for /// the attachable member entry to set. /// </param> /// <param name="value">The value to set.</param> public void SetProperty( AttachableMemberIdentifier attachableMemberIdentifier , object value ) { AttachablePropertyServices.SetProperty(this, attachableMemberIdentifier, value); }
// We need this explicit check because otherwise, an empty collection might get serialized // just because the getter was accessed private static bool ShouldSerializeCollection <T>(object target, AttachableMemberIdentifier property) { if (AttachablePropertyServices.TryGetProperty(target, property, out IList <T> result)) { return(result.Count > 0); } return(false); }
private static int GetIntegerAttachedProperty(object instance, AttachableMemberIdentifier memberIdentifier) { int num; if (AttachablePropertyServices.TryGetProperty <int>(instance, memberIdentifier, out num)) { return(num); } return(-1); }
public void NullArguments() { var name = "MyPropertyCreateNullArguments"; var nameExpression = (IntPropertyExpression)(() => MyIntProperty); var identifier = new AttachableMemberIdentifier(typeof(AttachedPropertyTests), name); new Action(() => _ = AttachedProperty.Register <AttachedPropertyTests, int>((string)null, 1)).Should().Throw <ArgumentNullException>().Which.ParamName.Should().Be(nameof(name)); new Action(() => _ = AttachedProperty.Register <AttachedPropertyTests, int>((IntPropertyExpression)null, 1)).Should().Throw <ArgumentNullException>().Which.ParamName.Should().Be(nameof(nameExpression)); new Action(() => _ = AttachedProperty.Get(null)).Should().Throw <ArgumentNullException>().Which.ParamName.Should().Be(nameof(identifier)); }
public void Create() { var identifier = new AttachableMemberIdentifier(typeof(AttachedPropertyTests), "MyPropertyCreate"); var property = new AttachedProperty(identifier, "DefaultValue"); property.DefaultValueUntyped.Should().Be("DefaultValue"); property.Identifier.Should().Be(identifier); property.Name.Should().Be("MyPropertyCreate"); property.OwnerType.Should().Be <AttachedPropertyTests>(); }
private static IList <T> GetCollection <T>(object target, AttachableMemberIdentifier property) { if (!AttachablePropertyServices.TryGetProperty(target, property, out IList <T> result)) { result = new Collection <T>(); AttachablePropertyServices.SetProperty(target, property, result); } return(result); }
/// <summary> /// Attempts to get a value for the specified attachable member in the /// specified store. /// </summary> /// <param name="attachableMemberIdentifier"> /// The XAML type system identifier for /// the attachable member entry to get. /// </param> /// <param name="value"> /// Out parameter. When this method returns, contains the /// destination object for the value if /// <paramref name="attachableMemberIdentifier" /> exists in the store and /// has /// a value. /// </param> /// <returns> /// <see langword="true" /> if an attachable member entry for /// <paramref name="attachableMemberIdentifier" /> was found in the store /// and a /// value was posted to <paramref name="value" />; otherwise, /// <see langword="false" />. /// </returns> public bool TryGetProperty( AttachableMemberIdentifier attachableMemberIdentifier , out object value ) { return(AttachablePropertyServices.TryGetProperty( this , attachableMemberIdentifier , out value )); }
public void CopyPropertiesToCopiesValues() { var store = new AttachablePropertyStoreTest(); var identifier = new AttachableMemberIdentifier( typeof(AttachablePropertyStoreTest), "Test"); store.SetProperty(identifier, 123); var array = new KeyValuePair<AttachableMemberIdentifier, object>[1]; store.CopyPropertiesTo(array, 0); Assert.AreSame(identifier, array[0].Key); }
public static AttachedProperty <T> Register <TOwner, T>([NotNull] string name, T defaultValue = default(T)) { if (name == null) { throw new ArgumentNullException(nameof(name)); } var identifier = new AttachableMemberIdentifier(typeof(TOwner), name); var property = new AttachedProperty <T>(identifier, defaultValue); _Properties.Add(identifier, property); return(property); }
public void RemovePropertyAddsAProperty() { var store = new AttachablePropertyStoreTest(); var identifier = new AttachableMemberIdentifier( typeof(AttachablePropertyStoreTest), "Test"); store.SetProperty(identifier, 123); Assert.IsTrue(store.RemoveProperty(identifier)); Assert.AreEqual(0, store.PropertyCount); object value; Assert.IsFalse(store.TryGetProperty(identifier, out value)); }
public void SetNamespaces(object target) { var dev2ActivitiesAssembly = typeof(WorkflowHelper).Assembly; var dev2CommonAssembly = typeof(GlobalConstants).Assembly; var dev2DataAssembly = typeof(Dev2DataListDecisionHandler).Assembly; var namespaces = new Dictionary <string, Assembly> { { "Dev2.Common", dev2CommonAssembly }, { "Dev2.Data.Decisions.Operations", dev2DataAssembly }, { "Dev2.Data.SystemTemplates.Models", dev2DataAssembly }, { "Dev2.DataList.Contract", dev2DataAssembly }, { "Dev2.DataList.Contract.Binary_Objects", dev2DataAssembly }, { "Unlimited.Applications.BusinessDesignStudio.Activities", dev2ActivitiesAssembly } }; #region Set C# assembly references // http://stackoverflow.com/questions/16086612/wf-4-5-using-c-sharp-expressions-with-external-class-references // http://blogs.msdn.com/b/tilovell/archive/2012/05/25/wf4-5-using-csharpvalue-lt-t-gt-and-csharpreference-lt-t-gt-in-net-4-5-compiling-expressions-and-changes-in-visual-studio-generated-xaml.aspx TextExpression.SetReferencesForImplementation(target, namespaces.Values.Distinct().Select(a => new AssemblyReference { Assembly = a }).ToArray()); var impl = new AttachableMemberIdentifier(typeof(TextExpression), "NamespacesForImplementation"); AttachablePropertyServices.SetProperty(target, impl, namespaces.Keys.ToList()); #endregion #region Set VB assembly references // var vbSettings = VisualBasic.GetSettings(target) ?? new VisualBasicSettings(); // vbSettings.ImportReferences.Clear(); // // foreach(var ns in namespaces.Keys) // { // try // { // vbSettings.ImportReferences.Add(new VisualBasicImportReference { Assembly = namespaces[ns].GetName().Name, Import = ns }); // } // catch(Exception e) // { // Dev2Logger.Error(e.Message,e); // } // } // // VisualBasic.SetSettings(target, vbSettings); #endregion }
static int GetIntegerAttachedProperty(object instance, AttachableMemberIdentifier memberIdentifier) { int value; if (AttachablePropertyServices.TryGetProperty(instance, memberIdentifier, out value)) { return(value); } else { return(-1); } }
public void CopyPropertiesToCopiesValues() { var store = new AttachablePropertyStoreTest(); var identifier = new AttachableMemberIdentifier( typeof(AttachablePropertyStoreTest), "Test"); store.SetProperty(identifier, 123); var array = new KeyValuePair <AttachableMemberIdentifier, object> [1]; store.CopyPropertiesTo(array, 0); Assert.AreSame(identifier, array[0].Key); }
public void RemovePropertyAddsAProperty() { var store = new AttachablePropertyStoreTest(); var identifier = new AttachableMemberIdentifier( typeof(AttachablePropertyStoreTest), "Test"); store.SetProperty(identifier, 123); Assert.IsTrue(store.RemoveProperty(identifier)); Assert.AreEqual(0, store.PropertyCount); object value; Assert.IsFalse(store.TryGetProperty(identifier, out value)); }
private static void SetCollection <T>(object target, AttachableMemberIdentifier property, IList <T> collection) { if (collection == null) { AttachablePropertyServices.RemoveProperty(target, property); } else { if (collection is Array) { collection = new Collection <T>(collection); } AttachablePropertyServices.SetProperty(target, property, collection); } }
/// <summary> /// Sets the priority on an item. /// </summary> /// <param name="item">The item.</param> /// <param name="priority">The priority.</param> public static void SetPriority(ServerItem item, int? priority) { var memberIdentifier = new AttachableMemberIdentifier(typeof(Queue), "Priority"); if (priority.HasValue) { AttachablePropertyServices.SetProperty( item, memberIdentifier, priority); } else { AttachablePropertyServices.RemoveProperty( item, memberIdentifier); } }
public static void Apply(this AttachableMemberIdentifier identifier, object target, object value) { if (identifier == null || identifier.DeclaringType == null) { return; } #if WINRT var setMethod = identifier.DeclaringType.GetTypeInfo().GetDeclaredMethod(string.Concat("Set", identifier.MemberName)); #else var setMethod = identifier.DeclaringType.GetMethod(string.Concat("Set", identifier.MemberName), BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); #endif if (setMethod != null) { setMethod.Invoke(null, new object[] { target, value }); } }
/// <summary> /// Sets the priority on an item. /// </summary> /// <param name="item">The item.</param> /// <param name="priority">The priority.</param> public static void SetPriority(ServerItem item, int?priority) { var memberIdentifier = new AttachableMemberIdentifier(typeof(Queue), "Priority"); if (priority.HasValue) { AttachablePropertyServices.SetProperty( item, memberIdentifier, priority); } else { AttachablePropertyServices.RemoveProperty( item, memberIdentifier); } }
void IAttachedPropertyStore.SetProperty(AttachableMemberIdentifier attachableMemberIdentifier, object value) { if (attachedProperties == null) { attachedProperties = new AttachableMemberIdentifierCollection(); } object oldValue; attachedProperties.TryGetValue(attachableMemberIdentifier, out oldValue); AttachedPropertyChangedEventArgs.OldValue = oldValue; attachedProperties[attachableMemberIdentifier] = value; if (AttachedPropertyChanged != null) { AttachedPropertyChangedEventArgs.Property = attachableMemberIdentifier; AttachedPropertyChangedEventArgs.NewValue = value; AttachedPropertyChanged(this, AttachedPropertyChangedEventArgs); } }
static void Main() { var errorCodeWorkflow = new DynamicActivity { Name = "MyScenario.MyDynamicActivity3", Properties = { new DynamicActivityProperty { Name = "Address", Type = typeof(InArgument <MailAddress>), }, }, Implementation = () => new WriteLine { Text = new CSharpValue <String> { ExpressionText = "\"MyDynamicActivity \" + Address.DisplayName" } } }; var impl = new AttachableMemberIdentifier(typeof(TextExpression), "NamespacesForImplementation"); var namespaces = new List <string> { typeof(MailAddress).Namespace }; TextExpression.SetReferencesForImplementation(errorCodeWorkflow, new AssemblyReference { Assembly = typeof(MailAddress).Assembly }); AttachablePropertyServices.SetProperty(errorCodeWorkflow, impl, namespaces); CompileExpressions(errorCodeWorkflow); WorkflowInvoker.Invoke(errorCodeWorkflow, new Dictionary <String, Object> { { "Address", new MailAddress { DisplayName = "TestDisplayName" } } }); }
bool IAttachedPropertyStore.RemoveProperty(AttachableMemberIdentifier attachableMemberIdentifier) { if (attachedProperties == null) { return(false); } object oldValue; attachedProperties.TryGetValue(attachableMemberIdentifier, out oldValue); AttachedPropertyChangedEventArgs.OldValue = oldValue; if (attachedProperties.Remove(attachableMemberIdentifier)) { if (AttachedPropertyChanged != null) { AttachedPropertyChangedEventArgs.Property = attachableMemberIdentifier; AttachedPropertyChangedEventArgs.NewValue = null; AttachedPropertyChanged(this, AttachedPropertyChangedEventArgs); } return(true); } return(false); }
public void WorkflowHelperCompileExpressionsWithActivityExpectedSetsNamespaces() { var activity = new DynamicActivity(); new WorkflowHelper().CompileExpressions(activity); var impl = new AttachableMemberIdentifier(typeof(TextExpression), "NamespacesForImplementation"); object property; AttachablePropertyServices.TryGetProperty(activity, impl, out property); var namespaces = property as List <string>; if (namespaces != null) { Assert.IsTrue(namespaces.SequenceEqual(ExpectedNamespaces)); } else { Assert.Fail(); } }
public void SetProperty(AttachableMemberIdentifier attachableMemberIdentifier, object value) { props [attachableMemberIdentifier] = value; }
public bool TryGetProperty(AttachableMemberIdentifier attachableMemberIdentifier, out object value) { return(props.TryGetValue(attachableMemberIdentifier, out value)); }
bool IAttachedPropertyStore.TryGetProperty (AttachableMemberIdentifier attachableMemberIdentifier, out object value) { return this.Properties.TryGetValue (attachableMemberIdentifier, out value); }
public bool RemoveProperty(AttachableMemberIdentifier attachableMemberIdentifier) { return(props.Remove(attachableMemberIdentifier)); }
/// <summary> /// Sets a value for the specified attachable member in the specified store. /// </summary> /// <param name="attachableMemberIdentifier">The XAML type system identifier for the attachable member entry to set.</param> /// <param name="value">The value to set.</param> public void SetProperty(AttachableMemberIdentifier attachableMemberIdentifier, object value) { this.attachedProperties[attachableMemberIdentifier] = value; }
bool IAttachedPropertyStore.TryGetProperty(AttachableMemberIdentifier attachableMemberIdentifier, out object value) { return(_attachedProperties.TryGetValue(attachableMemberIdentifier, out value)); }
internal AttachedProperty(AttachableMemberIdentifier identifier, object defaultValue) { Identifier = identifier; DefaultValueUntyped = defaultValue; }
public void WorkflowHelperCompileExpressionsWithActivityExpectedSetsNamespaces() { var activity = new DynamicActivity(); new WorkflowHelper().CompileExpressions(activity,Guid.NewGuid()); var impl = new AttachableMemberIdentifier(typeof(TextExpression), "NamespacesForImplementation"); object property; AttachablePropertyServices.TryGetProperty(activity, impl, out property); var namespaces = property as List<string>; if(namespaces != null) { Assert.IsTrue(namespaces.SequenceEqual(ExpectedNamespaces)); } else { Assert.Fail(); } }
public void SetProperty (AttachableMemberIdentifier attachableMemberIdentifier, object value) { props [attachableMemberIdentifier] = value; }
internal static AttachedProperty Get(AttachableMemberIdentifier identifier) => _Properties[identifier];
void IAttachedPropertyStore.SetProperty (AttachableMemberIdentifier attachableMemberIdentifier, object value) { this.Properties[attachableMemberIdentifier] = value; }
static int GetIntegerAttachedProperty(object instance, AttachableMemberIdentifier memberIdentifier) { int value; if (AttachablePropertyServices.TryGetProperty(instance, memberIdentifier, out value)) { return value; } else { return -1; } }
/// <summary> /// Attempts to get a value for the specified attachable member in the specified store. /// </summary> /// <param name="attachableMemberIdentifier">The XAML type system identifier for the attachable member entry to get.</param> /// <param name="value">Out parameter. Destination object for the value if <paramref name="attachableMemberIdentifier"/> exists in the store and has a value.</param> /// <returns> /// true if an attachable member entry for name was found in the store and a value was posted to <paramref name="value"/>; otherwise, false. /// </returns> public bool TryGetProperty(AttachableMemberIdentifier attachableMemberIdentifier, out object value) { return attachedProperties.TryGetValue(attachableMemberIdentifier, out value); }
internal AttachedProperty([NotNull] AttachableMemberIdentifier identifier, object defaultValue) { Identifier = identifier ?? throw new ArgumentNullException(nameof(identifier)); DefaultValueUntyped = defaultValue; }
T IBetterAttachedPropertyStore.GetValue <T>(AttachableMemberIdentifier attachableMemberIdentifier) { object val; return(_attachedProperties.TryGetValue(attachableMemberIdentifier, out val) ? (T)val : default(T)); }
internal static AttachedProperty Get([NotNull] AttachableMemberIdentifier identifier) =>
/// <summary> /// Initializes a new instance of the <see cref="AttachedPropertyChangedEventArgs"/> class. /// </summary> public AttachedPropertyChangedEventArgs(AttachableMemberIdentifier property, object newValue, object oldValue) { Property = property; NewValue = newValue; OldValue = oldValue; }
bool IAttachedPropertyStore.RemoveProperty (AttachableMemberIdentifier attachableMemberIdentifier) { return this.Properties.Remove (attachableMemberIdentifier); }
/// <summary> /// Removes the entry for the specified attachable member from this attachable member store. /// </summary> /// <param name="attachableMemberIdentifier">The XAML type system identifier for the attachable member entry to remove.</param> /// <returns> /// true if an attachable member entry for name> was found in the store and removed; otherwise, false. /// </returns> public bool RemoveProperty(AttachableMemberIdentifier attachableMemberIdentifier) { return attachedProperties.Remove(attachableMemberIdentifier); }