/// <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); } }
public void DowngradeToReaderLock() { System.Diagnostics.Debug.Assert(type == LockType.ForWriting); if (type == LockType.ForWriting) { System.Threading.LockCookie c = cookie.Value; rwlock.DowngradeFromWriterLock(ref c); cookie = null; type = LockType.ForReading; } }