##// END OF EJS Templates
minor changes
cin -
r95:0141a165d032 v2
parent child
Show More
@@ -1,224 +1,222
1 1 <?xml version="1.0" encoding="utf-8"?>
2 2 <Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3 3 <PropertyGroup>
4 4 <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
5 5 <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
6 6 <ProjectGuid>{F550F1F8-8746-4AD0-9614-855F4C4B7F05}</ProjectGuid>
7 7 <OutputType>Library</OutputType>
8 8 <RootNamespace>Implab</RootNamespace>
9 9 <AssemblyName>Implab</AssemblyName>
10 <ProductVersion>8.0.30703</ProductVersion>
11 <SchemaVersion>2.0</SchemaVersion>
12 10 </PropertyGroup>
13 11 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
14 12 <DebugSymbols>true</DebugSymbols>
15 13 <DebugType>full</DebugType>
16 14 <Optimize>false</Optimize>
17 15 <OutputPath>bin\Debug</OutputPath>
18 16 <DefineConstants>TRACE;DEBUG;</DefineConstants>
19 17 <ErrorReport>prompt</ErrorReport>
20 18 <WarningLevel>4</WarningLevel>
21 19 <ConsolePause>false</ConsolePause>
22 20 <RunCodeAnalysis>true</RunCodeAnalysis>
23 21 </PropertyGroup>
24 22 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
25 23 <DebugType>full</DebugType>
26 24 <Optimize>true</Optimize>
27 25 <OutputPath>bin\Release</OutputPath>
28 26 <ErrorReport>prompt</ErrorReport>
29 27 <WarningLevel>4</WarningLevel>
30 28 <ConsolePause>false</ConsolePause>
31 29 </PropertyGroup>
32 30 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug 4.5|AnyCPU' ">
33 31 <DebugSymbols>true</DebugSymbols>
34 32 <DebugType>full</DebugType>
35 33 <Optimize>false</Optimize>
36 34 <OutputPath>bin\Debug</OutputPath>
37 35 <DefineConstants>TRACE;DEBUG;NET_4_5</DefineConstants>
38 36 <ErrorReport>prompt</ErrorReport>
39 37 <WarningLevel>4</WarningLevel>
40 38 <RunCodeAnalysis>true</RunCodeAnalysis>
41 39 <ConsolePause>false</ConsolePause>
42 40 </PropertyGroup>
43 41 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release 4.5|AnyCPU' ">
44 42 <Optimize>true</Optimize>
45 43 <OutputPath>bin\Release</OutputPath>
46 44 <ErrorReport>prompt</ErrorReport>
47 45 <WarningLevel>4</WarningLevel>
48 46 <ConsolePause>false</ConsolePause>
49 47 <DefineConstants>NET_4_5</DefineConstants>
50 48 </PropertyGroup>
51 49 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'DebugMono|AnyCPU' ">
52 50 <DebugSymbols>true</DebugSymbols>
53 51 <DebugType>full</DebugType>
54 52 <Optimize>false</Optimize>
55 53 <OutputPath>bin\Debug</OutputPath>
56 54 <DefineConstants>TRACE;DEBUG;NET_4_5;MONO</DefineConstants>
57 55 <ErrorReport>prompt</ErrorReport>
58 56 <WarningLevel>4</WarningLevel>
59 57 <RunCodeAnalysis>true</RunCodeAnalysis>
60 58 <ConsolePause>false</ConsolePause>
61 59 </PropertyGroup>
62 60 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'ReleaseMono|AnyCPU' ">
63 61 <Optimize>true</Optimize>
64 62 <OutputPath>bin\Release</OutputPath>
65 63 <DefineConstants>NET_4_5;MONO;</DefineConstants>
66 64 <ErrorReport>prompt</ErrorReport>
67 65 <WarningLevel>4</WarningLevel>
68 66 <ConsolePause>false</ConsolePause>
69 67 </PropertyGroup>
70 68 <ItemGroup>
71 69 <Reference Include="System" />
72 70 <Reference Include="System.Xml" />
73 71 </ItemGroup>
74 72 <ItemGroup>
75 73 <Compile Include="Component.cs" />
76 74 <Compile Include="CustomEqualityComparer.cs" />
77 75 <Compile Include="Diagnostics\ConsoleTraceListener.cs" />
78 76 <Compile Include="Diagnostics\EventText.cs" />
79 77 <Compile Include="Diagnostics\IEventTextFormatter.cs" />
80 78 <Compile Include="Diagnostics\LogChannel.cs" />
81 79 <Compile Include="Diagnostics\LogicalOperation.cs" />
82 80 <Compile Include="Diagnostics\TextFileListener.cs" />
83 81 <Compile Include="Diagnostics\TextListenerBase.cs" />
84 82 <Compile Include="Diagnostics\TraceLog.cs" />
85 83 <Compile Include="Diagnostics\TraceEvent.cs" />
86 84 <Compile Include="Diagnostics\TraceEventType.cs" />
87 85 <Compile Include="Disposable.cs" />
88 86 <Compile Include="ICancellable.cs" />
89 87 <Compile Include="IProgressHandler.cs" />
90 88 <Compile Include="IProgressNotifier.cs" />
91 89 <Compile Include="IPromiseT.cs" />
92 90 <Compile Include="IPromise.cs" />
93 91 <Compile Include="IServiceLocator.cs" />
94 92 <Compile Include="ITaskController.cs" />
95 93 <Compile Include="JSON\JSONElementContext.cs" />
96 94 <Compile Include="JSON\JSONElementType.cs" />
97 95 <Compile Include="JSON\JSONGrammar.cs" />
98 96 <Compile Include="JSON\JSONParser.cs" />
99 97 <Compile Include="JSON\JSONScanner.cs" />
100 98 <Compile Include="JSON\JsonTokenType.cs" />
101 99 <Compile Include="JSON\JSONWriter.cs" />
102 100 <Compile Include="JSON\JSONXmlReader.cs" />
103 101 <Compile Include="JSON\JSONXmlReaderOptions.cs" />
104 102 <Compile Include="JSON\StringTranslator.cs" />
105 103 <Compile Include="Parallels\DispatchPool.cs" />
106 104 <Compile Include="Parallels\ArrayTraits.cs" />
107 105 <Compile Include="Parallels\MTQueue.cs" />
108 106 <Compile Include="Parallels\WorkerPool.cs" />
109 107 <Compile Include="Parsing\Alphabet.cs" />
110 108 <Compile Include="Parsing\AlphabetBase.cs" />
111 109 <Compile Include="Parsing\AltToken.cs" />
112 110 <Compile Include="Parsing\BinaryToken.cs" />
113 111 <Compile Include="Parsing\CatToken.cs" />
114 112 <Compile Include="Parsing\CDFADefinition.cs" />
115 113 <Compile Include="Parsing\DFABuilder.cs" />
116 114 <Compile Include="Parsing\DFADefinitionBase.cs" />
117 115 <Compile Include="Parsing\DFAStateDescriptor.cs" />
118 116 <Compile Include="Parsing\DFAutomaton.cs" />
119 117 <Compile Include="Parsing\EDFADefinition.cs" />
120 118 <Compile Include="Parsing\EmptyToken.cs" />
121 119 <Compile Include="Parsing\EndToken.cs" />
122 120 <Compile Include="Parsing\EnumAlphabet.cs" />
123 121 <Compile Include="Parsing\Grammar.cs" />
124 122 <Compile Include="Parsing\IAlphabet.cs" />
125 123 <Compile Include="Parsing\IDFADefinition.cs" />
126 124 <Compile Include="Parsing\IVisitor.cs" />
127 125 <Compile Include="Parsing\ParserException.cs" />
128 126 <Compile Include="Parsing\Scanner.cs" />
129 127 <Compile Include="Parsing\StarToken.cs" />
130 128 <Compile Include="Parsing\SymbolToken.cs" />
131 129 <Compile Include="Parsing\Token.cs" />
132 130 <Compile Include="SafePool.cs" />
133 131 <Compile Include="ServiceLocator.cs" />
134 132 <Compile Include="TaskController.cs" />
135 133 <Compile Include="ProgressInitEventArgs.cs" />
136 134 <Compile Include="Properties\AssemblyInfo.cs" />
137 135 <Compile Include="Promise.cs" />
138 136 <Compile Include="Parallels\AsyncPool.cs" />
139 137 <Compile Include="Safe.cs" />
140 138 <Compile Include="ValueEventArgs.cs" />
141 139 <Compile Include="PromiseExtensions.cs" />
142 140 <Compile Include="TransientPromiseException.cs" />
143 141 <Compile Include="SyncContextPromise.cs" />
144 142 <Compile Include="ObjectPool.cs" />
145 143 <Compile Include="Diagnostics\OperationContext.cs" />
146 144 <Compile Include="Diagnostics\TraceContext.cs" />
147 145 <Compile Include="Diagnostics\LogEventArgs.cs" />
148 146 <Compile Include="Diagnostics\LogEventArgsT.cs" />
149 147 <Compile Include="Diagnostics\Extensions.cs" />
150 148 <Compile Include="IComponentContainer.cs" />
151 149 <Compile Include="MTComponentContainer.cs" />
152 150 </ItemGroup>
153 151 <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
154 152 <ItemGroup />
155 153 <ProjectExtensions>
156 154 <MonoDevelop>
157 155 <Properties>
158 156 <Policies>
159 157 <CSharpFormattingPolicy IndentSwitchBody="True" NamespaceBraceStyle="EndOfLine" ClassBraceStyle="EndOfLine" InterfaceBraceStyle="EndOfLine" StructBraceStyle="EndOfLine" EnumBraceStyle="EndOfLine" MethodBraceStyle="EndOfLine" ConstructorBraceStyle="EndOfLine" DestructorBraceStyle="EndOfLine" BeforeMethodDeclarationParentheses="False" BeforeMethodCallParentheses="False" BeforeConstructorDeclarationParentheses="False" NewLineBeforeConstructorInitializerColon="NewLine" NewLineAfterConstructorInitializerColon="SameLine" BeforeIndexerDeclarationBracket="False" BeforeDelegateDeclarationParentheses="False" NewParentheses="False" SpacesBeforeBrackets="False" inheritsSet="Mono" inheritsScope="text/x-csharp" scope="text/x-csharp" />
160 158 <TextStylePolicy FileWidth="120" EolMarker="Unix" inheritsSet="VisualStudio" inheritsScope="text/plain" scope="text/x-csharp" />
161 159 <DotNetNamingPolicy DirectoryNamespaceAssociation="PrefixedHierarchical" ResourceNamePolicy="MSBuild" />
162 160 <TextStylePolicy FileWidth="120" TabsToSpaces="False" inheritsSet="VisualStudio" inheritsScope="text/plain" scope="application/xml" />
163 161 <XmlFormattingPolicy inheritsSet="Mono" inheritsScope="application/xml" scope="application/xml" />
164 162 <TextStylePolicy FileWidth="120" TabsToSpaces="False" inheritsSet="VisualStudio" inheritsScope="text/plain" scope="text/plain" />
165 163 <NameConventionPolicy>
166 164 <Rules>
167 165 <NamingRule Name="Namespaces" AffectedEntity="Namespace" VisibilityMask="VisibilityMask" NamingStyle="PascalCase" IncludeInstanceMembers="True" IncludeStaticEntities="True" />
168 166 <NamingRule Name="Types" AffectedEntity="Class, Struct, Enum, Delegate" VisibilityMask="VisibilityMask" NamingStyle="PascalCase" IncludeInstanceMembers="True" IncludeStaticEntities="True" />
169 167 <NamingRule Name="Interfaces" AffectedEntity="Interface" VisibilityMask="VisibilityMask" NamingStyle="PascalCase" IncludeInstanceMembers="True" IncludeStaticEntities="True">
170 168 <RequiredPrefixes>
171 169 <String>I</String>
172 170 </RequiredPrefixes>
173 171 </NamingRule>
174 172 <NamingRule Name="Attributes" AffectedEntity="CustomAttributes" VisibilityMask="VisibilityMask" NamingStyle="PascalCase" IncludeInstanceMembers="True" IncludeStaticEntities="True">
175 173 <RequiredSuffixes>
176 174 <String>Attribute</String>
177 175 </RequiredSuffixes>
178 176 </NamingRule>
179 177 <NamingRule Name="Event Arguments" AffectedEntity="CustomEventArgs" VisibilityMask="VisibilityMask" NamingStyle="PascalCase" IncludeInstanceMembers="True" IncludeStaticEntities="True">
180 178 <RequiredSuffixes>
181 179 <String>EventArgs</String>
182 180 </RequiredSuffixes>
183 181 </NamingRule>
184 182 <NamingRule Name="Exceptions" AffectedEntity="CustomExceptions" VisibilityMask="VisibilityMask" NamingStyle="PascalCase" IncludeInstanceMembers="True" IncludeStaticEntities="True">
185 183 <RequiredSuffixes>
186 184 <String>Exception</String>
187 185 </RequiredSuffixes>
188 186 </NamingRule>
189 187 <NamingRule Name="Methods" AffectedEntity="Methods" VisibilityMask="VisibilityMask" NamingStyle="PascalCase" IncludeInstanceMembers="True" IncludeStaticEntities="True" />
190 188 <NamingRule Name="Static Readonly Fields" AffectedEntity="ReadonlyField" VisibilityMask="Internal, Protected, Public" NamingStyle="CamelCase" IncludeInstanceMembers="False" IncludeStaticEntities="True" />
191 189 <NamingRule Name="Fields (Non Private)" AffectedEntity="Field" VisibilityMask="Internal, Public" NamingStyle="CamelCase" IncludeInstanceMembers="True" IncludeStaticEntities="True" />
192 190 <NamingRule Name="ReadOnly Fields (Non Private)" AffectedEntity="ReadonlyField" VisibilityMask="Internal, Public" NamingStyle="CamelCase" IncludeInstanceMembers="True" IncludeStaticEntities="False" />
193 191 <NamingRule Name="Fields (Private)" AffectedEntity="Field, ReadonlyField" VisibilityMask="Private, Protected" NamingStyle="CamelCase" IncludeInstanceMembers="True" IncludeStaticEntities="False">
194 192 <RequiredPrefixes>
195 193 <String>m_</String>
196 194 </RequiredPrefixes>
197 195 </NamingRule>
198 196 <NamingRule Name="Static Fields (Private)" AffectedEntity="Field" VisibilityMask="Private" NamingStyle="CamelCase" IncludeInstanceMembers="False" IncludeStaticEntities="True">
199 197 <RequiredPrefixes>
200 198 <String>_</String>
201 199 </RequiredPrefixes>
202 200 </NamingRule>
203 201 <NamingRule Name="ReadOnly Fields (Private)" AffectedEntity="ReadonlyField" VisibilityMask="Private, Protected" NamingStyle="CamelCase" IncludeInstanceMembers="True" IncludeStaticEntities="False">
204 202 <RequiredPrefixes>
205 203 <String>m_</String>
206 204 </RequiredPrefixes>
207 205 </NamingRule>
208 206 <NamingRule Name="Constant Fields" AffectedEntity="ConstantField" VisibilityMask="VisibilityMask" NamingStyle="AllUpper" IncludeInstanceMembers="True" IncludeStaticEntities="True" />
209 207 <NamingRule Name="Properties" AffectedEntity="Property" VisibilityMask="VisibilityMask" NamingStyle="PascalCase" IncludeInstanceMembers="True" IncludeStaticEntities="True" />
210 208 <NamingRule Name="Events" AffectedEntity="Event" VisibilityMask="VisibilityMask" NamingStyle="PascalCase" IncludeInstanceMembers="True" IncludeStaticEntities="True" />
211 209 <NamingRule Name="Enum Members" AffectedEntity="EnumMember" VisibilityMask="VisibilityMask" NamingStyle="PascalCase" IncludeInstanceMembers="True" IncludeStaticEntities="True" />
212 210 <NamingRule Name="Parameters" AffectedEntity="Parameter, LocalVariable" VisibilityMask="VisibilityMask" NamingStyle="CamelCase" IncludeInstanceMembers="True" IncludeStaticEntities="True" />
213 211 <NamingRule Name="Type Parameters" AffectedEntity="TypeParameter" VisibilityMask="VisibilityMask" NamingStyle="PascalCase" IncludeInstanceMembers="True" IncludeStaticEntities="True">
214 212 <RequiredPrefixes>
215 213 <String>T</String>
216 214 </RequiredPrefixes>
217 215 </NamingRule>
218 216 </Rules>
219 217 </NameConventionPolicy>
220 218 </Policies>
221 219 </Properties>
222 220 </MonoDevelop>
223 221 </ProjectExtensions>
224 222 </Project> No newline at end of file
@@ -1,71 +1,86
1 1 using System;
2 2 using System.Collections.Generic;
3 3 using System.Linq;
4 4 using System.Text;
5 5 using System.Text.RegularExpressions;
6 6 using System.Diagnostics;
7 7
8 8 namespace Implab
9 9 {
10 10 public static class Safe
11 11 {
12 12 public static void ArgumentMatch(string param, string name, Regex rx) {
13 13 if (rx == null)
14 14 throw new ArgumentNullException("rx");
15 15 if (!rx.IsMatch(param))
16 16 throw new ArgumentException(String.Format("The prameter value must match {0}", rx), name);
17 17 }
18 18
19 19 public static void ArgumentNotEmpty(string param, string name) {
20 20 if (String.IsNullOrEmpty(param))
21 21 throw new ArgumentException("The parameter can't be empty", name);
22 22 }
23 23
24 24 public static void ArgumentNotEmpty<T>(T[] param, string name) {
25 25 if (param == null || param.Length == 0)
26 26 throw new ArgumentException("The array must be not emty");
27 27 }
28 28
29 29 public static void ArgumentNotNull(object param, string name) {
30 30 if (param == null)
31 31 throw new ArgumentNullException(name);
32 32 }
33 33
34 34 public static void ArgumentInRange(int arg, int min, int max, string name) {
35 35 if (arg < min || arg > max)
36 36 throw new ArgumentOutOfRangeException(name);
37 37 }
38 38
39 39 public static void Dispose<T>(T obj) where T : class
40 40 {
41 41 var disp = obj as IDisposable;
42 42 if (disp != null)
43 43 disp.Dispose();
44 44 }
45 45
46 46 [DebuggerStepThrough]
47 47 public static IPromise<T> InvokePromise<T>(Func<T> action) {
48 48 ArgumentNotNull(action, "action");
49 49
50 50 var p = new Promise<T>();
51 51 try {
52 52 p.Resolve(action());
53 53 } catch (Exception err) {
54 54 p.Reject(err);
55 55 }
56 56
57 57 return p;
58 58 }
59 59
60 60 [DebuggerStepThrough]
61 public static IPromise<T> InvokePromise<T>(Action action) {
62 ArgumentNotNull(action, "action");
63
64 var p = new Promise<object>();
65 try {
66 action();
67 p.Resolve();
68 } catch (Exception err) {
69 p.Reject(err);
70 }
71
72 return p;
73 }
74
75 [DebuggerStepThrough]
61 76 public static IPromise<T> InvokePromise<T>(Func<IPromise<T>> action) {
62 77 ArgumentNotNull(action, "action");
63 78
64 79 try {
65 80 return action() ?? Promise<T>.ExceptionToPromise(new Exception("The action returned null"));
66 81 } catch (Exception err) {
67 82 return Promise<T>.ExceptionToPromise(err);
68 83 }
69 84 }
70 85 }
71 86 }
General Comments 0
You need to be logged in to leave comments. Login now