Ejemplo n.º 1
0
        /// <summary>
        ///     Determines whether the specified objects instances are the same instance.
        /// </summary>
        /// <exception cref="ArgumentNullException">The first object can not be null.</exception>
        /// <exception cref="ArgumentNullException">The second object can not be null.</exception>
        /// <param name="obj0">The first object to compare.</param>
        /// <param name="obj1">The second object  to compare.</param>
        /// <returns>Returns true if if the objects are the same instance.</returns>
        public static Boolean RefEquals( this Object obj0, Object obj1 )
        {
            obj0.ThrowIfNull( nameof( obj0 ) );
            obj1.ThrowIfNull( nameof( obj1 ) );

            return ReferenceEquals( obj0, obj1 );
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Wires up an entire object according to its usage of CommandWirerAttributes
        /// </summary>
        /// <param name="toWire"></param>
        /// <returns></returns>
        public static IList<CommandWirer> WireAll(Object toWire)
        {
            toWire.ThrowIfNull ("toWire");

            var toWireType = toWire.GetType ();

            var helperMap = new Dictionary<String, CommandWirer> ();

            foreach (var prop in
                toWireType.GetProperties (BindingFlags.Public | BindingFlags.Instance)
                .Union (toWireType.GetProperties (BindingFlags.NonPublic | BindingFlags.Instance))
                .Union (toWireType.GetProperties (BindingFlags.Public | BindingFlags.Static))
                .Union (toWireType.GetProperties (BindingFlags.NonPublic | BindingFlags.Static)))
            {
                foreach (var attr in prop.GetCustomAttributes (typeof (CommandWirerAttribute), true).Cast<CommandWirerAttribute> ())
                {
                    attr.SetKeyFromMethodName (prop.Name);

                    CommandWirer helper;
                    if (!helperMap.TryGetValue (attr.Key, out helper))
                        helperMap[attr.Key] = helper = new CommandWirer { Key = attr.Key, InvokeOn = toWire };

                    attr.Configure (helper, prop);
                }
            }

            foreach (var method in
                toWireType.GetMethods (BindingFlags.Public | BindingFlags.Instance)
                .Union (toWireType.GetMethods (BindingFlags.NonPublic | BindingFlags.Instance))
                .Union (toWireType.GetMethods (BindingFlags.Public | BindingFlags.Static))
                .Union (toWireType.GetMethods (BindingFlags.NonPublic | BindingFlags.Static)))
            {
                foreach (var attr in method.GetCustomAttributes (typeof (CommandWirerAttribute), true).Cast<CommandWirerAttribute> ())
                {
                    attr.SetKeyFromMethodName (method.Name);

                    CommandWirer helper;
                    if (!helperMap.TryGetValue (attr.Key, out helper))
                        helperMap[attr.Key] = helper = new CommandWirer { Key = attr.Key };

                    attr.Configure (helper, method);
                }
            }

            foreach (var helper in helperMap.Values)
                helper.Wire ();

            return helperMap.Values.ToList ();
        }
Ejemplo n.º 3
0
 public void ThrowIfNull_SetNotNull_Success()
 {
     object obj = new Object();
     obj.ThrowIfNull("obj");
 }