Beispiel #1
0
        /// <summary>
        /// Cria o tipo da classe dinâmica.
        /// </summary>
        /// <param name="properties"></param>
        /// <returns></returns>
        private Type CreateDynamicClass(DynamicProperty[] properties)
        {
            var cookie = rwLock.UpgradeToWriterLock(System.Threading.Timeout.Infinite);

            try
            {
                string typeName = "DynamicClass" + (classCount + 1);
                                #if ENABLE_LINQ_PARTIAL_TRUST
                new ReflectionPermission(PermissionState.Unrestricted).Assert();
#endif
                try
                {
                    var tb     = this.module.DefineType(typeName, System.Reflection.TypeAttributes.Class | System.Reflection.TypeAttributes.Public, typeof(DynamicClass));
                    var fields = GenerateProperties(tb, properties);
                    GenerateEquals(tb, fields);
                    GenerateGetHashCode(tb, fields);
                    Type result = tb.CreateType();
                    classCount++;
                    return(result);
                }
                finally
                {
                                        #if ENABLE_LINQ_PARTIAL_TRUST
                    PermissionSet.RevertAssert();
#endif
                }
            }
            finally
            {
                rwLock.DowngradeFromWriterLock(ref cookie);
            }
        }
Beispiel #2
0
        public void UpgradeToWriterLock()
        {
            System.Diagnostics.Debug.Assert(type == LockType.ForReading);

            if (type == LockType.ForReading)
            {
                rwlock.UpgradeToWriterLock(-1);
                type = LockType.ForWriting;
            }
        }
Beispiel #3
0
 internal WriterLockUpgraded(System.Threading.ReaderWriterLock rwlock, int milliSeconds)
 {
     this.cookie = rwlock.UpgradeToWriterLock(milliSeconds);
     this.rwlock = rwlock;
 }