コード例 #1
0
        /// <summary>
        /// Get a deserializer for dynamic objects.
        /// </summary>
        /// <typeparam name="T">The type of object to deserialize.</typeparam>
        /// <typeparam name="TImpl">The type of object to use to implement the requested type.</typeparam>
        /// <returns>A deserializer that returns dynamic objects.</returns>
        private static Func <IDataReader, T> GetDynamicDeserializer <T, TImpl>() where TImpl : T, IDictionary <String, Object>, new()
        {
            return(r =>
            {
                // we need it to implement IDictionary so we can set the properties
                T t = new TImpl();
                IDictionary <String, Object> o = (IDictionary <String, Object>)t;

                // get all of the values at once to avoid overhead
                int fieldCount = r.FieldCount;
                object[] values = new object[fieldCount];
                r.GetValues(values);

                // stick the values into the array
                for (int i = 0; i < fieldCount; i++)
                {
                    // handle dbnull conversion
                    object value = values[i];
                    if (value == DBNull.Value)
                    {
                        value = null;
                    }

                    // set the value on the dictionary
                    // GetName is pretty efficient
                    o.Add(r.GetName(i), value);
                }

                return t;
            });
        }
コード例 #2
0
            public AvaloniaLocator ToSingleton <TImpl>() where TImpl : class, TService, new()
            {
                TImpl instance = null;

                return(ToFunc(() => instance ?? (instance = new TImpl())));
            }
コード例 #3
0
ファイル: XRC4Cipher.cs プロジェクト: odasm/rolePLAY
 public XRC4Cipher(string pKey)
 {
     m_pImpl = new TImpl();
     Clear();
     m_pImpl.Init(pKey);
 }
コード例 #4
0
 public ConvertComparer(TImpl source)
 {
     _source = source;
 }
コード例 #5
0
 public ConvertCursor(ICursor <TKey, TValue> innerCursor, TImpl source)
 {
     _innerCursor = innerCursor;
     _source      = source;
 }
コード例 #6
0
ファイル: XRC4Cipher.cs プロジェクト: KirieZ/Tartarus
 public XRC4Cipher(string pKey)
 {
     m_pImpl = new TImpl();
     Clear();
     m_pImpl.Init(pKey);
 }