Пример #1
0
        public static object Merge(this object instance1, object instance2)
        {
            if (instance1 != null || instance2 != null)
            {
                if (instance1 == null)
                {
                    return(instance2);
                }
                if (instance2 == null)
                {
                    return(instance1);
                }

                IDictionary <string, object> instance1Dictionary = instance1.ToPropertyDictionary();
                IDictionary <string, object> instance2Dictionary = instance2.ToPropertyDictionary();

                foreach (KeyValuePair <string, object> i in instance2Dictionary.Where(i => !instance1Dictionary.Keys.Contains(i.Key)))
                {
                    instance1Dictionary.Add(i);
                }

                PropertyDef[] newInstanceInfo = instance1Dictionary.Select(i => PropertyDef.New(i.Key, i.Value)).ToArray();

                return(AnonymousBuilder.CreateInstance(newInstanceInfo));
            }

            return(null);
        }
Пример #2
0
        protected virtual void OnLockStateChanged(Lock @lock)
        {
            States.LockSomething = _lockHandler.Count > 0;

            var unitLock = @lock as UnitLock;

            if (unitLock != null)
            {
                UpdateTypes |= UnitUpdateTypes.Lock;
                UpdateVisibilityOf(unitLock.Target);
            }

            var builder = new AnonymousBuilder <Packet>(() => LockPacketBuilder.BuildPacket(@lock));

            OnBroadcastPacket(builder.ToProxy());
        }
Пример #3
0
        private static async Task ExecuteCommandReader <T>(SqlCommand command, ICollection <T> records, CancellationToken token) where T : new()
        {
            try
            {
                using (SqlDataReader reader = await command.ExecuteReaderAsync(token))
                {
                    IList <string> names = new List <string>();
                    for (int i = 0; i < reader.FieldCount; i++)
                    {
                        names.Add(reader.GetName(i));
                    }

                    AnonymousBuilder anonymousBuilder = typeof(T) == typeof(object)
                        ? new AnonymousBuilder(names.ToArray())
                        : null;

                    foreach (IDataRecord record in reader)
                    {
                        IList <object> values = new List <object>();
                        for (int i = 0; i < reader.FieldCount; i++)
                        {
                            values.Add(record[i] != DBNull.Value ? record[i] : null);
                        }

                        T instance = anonymousBuilder != null
                            ? (T)anonymousBuilder.CreateInstance(values.ToArray())
                            : CreateTypedInstance <T>(values);

                        records.Add(instance);
                    }
                }
            }
            catch (OperationCanceledException ex)
            {
                LogHelper.Exception(ex);
                throw;
            }
            catch (Exception ex)
            {
                LogHelper.Exception(ex);
                throw;
            }
        }
Пример #4
0
 public static object ToParamObject(this ParamDictionary parameters)
 {
     return(parameters.Any()
         ? AnonymousBuilder.CreateInstance(parameters.Values.Select(i => PropertyDef.New(i.Name, i.Value)).ToArray())
         : null);
 }