Jypeli  5
The simple game programming library
Assert.cs
Siirry tämän tiedoston dokumentaatioon.
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 using System.IO;
6 
7 namespace Jypeli
8 {
9  public partial class FileManager
10  {
11  public event Action<Exception> ReadAccessDenied;
12  public event Action<Exception> WriteAccessDenied;
13 
14  protected virtual void Initialize()
15  {
16  }
17 
18  private void OnAccessDenied( Exception e, bool write )
19  {
20  if ( !write && ReadAccessDenied != null )
21  ReadAccessDenied( e );
22  if ( write && WriteAccessDenied != null )
23  WriteAccessDenied( e );
24  }
25 
26  protected void FMAssert( Action func, bool write )
27  {
28 #if DEBUG
29  func();
30 #else
31  try
32  {
33  func();
34  }
35  catch ( Exception e )
36  {
37  OnAccessDenied( e, write );
38  }
39 #endif
40  }
41 
42  protected void FMAssert<TP1>( Action<TP1> func, bool write, TP1 p1 )
43  {
44 #if DEBUG
45  func( p1 );
46 #else
47  try
48  {
49  func( p1 );
50  }
51  catch ( Exception e )
52  {
53  OnAccessDenied( e, write );
54  }
55 #endif
56  }
57 
58  protected TR FMAssert<TR>(Func<TR> func, bool write, TR defaultVal)
59  {
60 #if DEBUG
61  return func();
62 #else
63  try
64  {
65  return func();
66  }
67  catch ( Exception e )
68  {
69  OnAccessDenied( e, write );
70  }
71 
72  return defaultVal;
73 #endif
74  }
75 
76  protected TR FMAssert<TP1, TR>( Func<TP1, TR> func, bool write, TR defaultVal, TP1 p1 )
77  {
78 #if DEBUG
79  return func( p1 );
80 #else
81  try
82  {
83  return func( p1 );
84  }
85  catch ( Exception e )
86  {
87  OnAccessDenied( e, write );
88  }
89 
90  return defaultVal;
91 #endif
92  }
93 
94  protected TR FMAssert<TP1, TP2, TR>( Func<TP1, TP2, TR> func, bool write, TR defaultVal, TP1 p1, TP2 p2 )
95  {
96 #if DEBUG
97  return func( p1, p2 );
98 #else
99  try
100  {
101  return func( p1, p2 );
102  }
103  catch ( Exception e )
104  {
105  OnAccessDenied( e, write );
106  }
107 
108  return defaultVal;
109 #endif
110  }
111  }
112 }
void FMAssert(Action func, bool write)
Definition: Assert.cs:26
Action< Exception > ReadAccessDenied
Definition: Assert.cs:11
void FMAssert< TP1 >(Action< TP1 > func, bool write, TP1 p1)
Definition: Assert.cs:42
Action< Exception > WriteAccessDenied
Definition: Assert.cs:12
TR FMAssert< TP1, TR >(Func< TP1, TR > func, bool write, TR defaultVal, TP1 p1)
Definition: Assert.cs:76
virtual void Initialize()
Definition: Assert.cs:14
TR FMAssert< TP1, TP2, TR >(Func< TP1, TP2, TR > func, bool write, TR defaultVal, TP1 p1, TP2 p2)
Definition: Assert.cs:94
TR FMAssert< TR >(Func< TR > func, bool write, TR defaultVal)
Definition: Assert.cs:58