();
153 | do
154 | {
155 | instance2.Add(typeInfo);
156 | Type declaringType = typeInfo.DeclaringType;
157 | typeInfo = (object)declaringType != null ? IntrospectionExtensions.GetTypeInfo(declaringType) : null;
158 | }
159 | while (typeInfo != null);
160 | int genericArgIndex = 0;
161 | for (int index = instance2.Count - 1; index >= 0; --index)
162 | {
163 | this.AppendTypeInstantiation(builder, instance2[index], genericArguments, ref genericArgIndex);
164 | if (index > 0)
165 | builder.Append('.');
166 | }
167 | }
168 | else
169 | {
170 | int genericArgIndex = 0;
171 | this.AppendTypeInstantiation(builder, typeInfo, genericArguments, ref genericArgIndex);
172 | }
173 | return builder.ToString();
174 | }
175 |
176 | private void AppendTypeInstantiation(
177 | StringBuilder builder,
178 | System.Reflection.TypeInfo typeInfo,
179 | Type[] genericArguments,
180 | ref int genericArgIndex)
181 | {
182 | int num = (typeInfo.IsGenericTypeDefinition ? typeInfo.GenericTypeParameters.Length : typeInfo.GenericTypeArguments.Length) - genericArgIndex;
183 | if (num > 0)
184 | {
185 | string name = typeInfo.Name;
186 | int length = name.IndexOf('`');
187 | if (length > 0)
188 | builder.Append(name.Substring(0, length));
189 | else
190 | builder.Append(name);
191 | builder.Append(this.GenericParameterOpening);
192 | for (int index = 0; index < num; ++index)
193 | {
194 | if (index > 0)
195 | builder.Append(", ");
196 | builder.Append(this.FormatTypeName(genericArguments[genericArgIndex++]));
197 | }
198 | builder.Append(this.GenericParameterClosing);
199 | }
200 | else
201 | builder.Append(typeInfo.Name);
202 | }
203 | }
204 | }
205 |
--------------------------------------------------------------------------------
/MrHuo.Extensions/ObjectFormatter/ObjectDisplay.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Globalization;
3 | using System.Text;
4 |
5 | namespace MrHuo.Extensions
6 | {
7 | internal static class ObjectDisplay
8 | {
9 | internal static string NullLiteral
10 | {
11 | get
12 | {
13 | return "null";
14 | }
15 | }
16 |
17 | internal static string FormatLiteral(bool value)
18 | {
19 | return !value ? "false" : "true";
20 | }
21 |
22 | private static bool TryReplaceChar(char c, out string replaceWith)
23 | {
24 | replaceWith = null;
25 | switch (c)
26 | {
27 | case char.MinValue:
28 | replaceWith = "\\0";
29 | break;
30 | case '\a':
31 | replaceWith = "\\a";
32 | break;
33 | case '\b':
34 | replaceWith = "\\b";
35 | break;
36 | case '\t':
37 | replaceWith = "\\t";
38 | break;
39 | case '\n':
40 | replaceWith = "\\n";
41 | break;
42 | case '\v':
43 | replaceWith = "\\v";
44 | break;
45 | case '\f':
46 | replaceWith = "\\f";
47 | break;
48 | case '\r':
49 | replaceWith = "\\r";
50 | break;
51 | case '\\':
52 | replaceWith = "\\\\";
53 | break;
54 | }
55 | if (replaceWith != null)
56 | return true;
57 | if (!ObjectDisplay.NeedsEscaping(CharUnicodeInfo.GetUnicodeCategory(c)))
58 | return false;
59 | replaceWith = "\\u" + ((int)c).ToString("x4");
60 | return true;
61 | }
62 |
63 | private static bool NeedsEscaping(UnicodeCategory category)
64 | {
65 | switch (category)
66 | {
67 | case UnicodeCategory.LineSeparator:
68 | case UnicodeCategory.ParagraphSeparator:
69 | case UnicodeCategory.Control:
70 | case UnicodeCategory.Surrogate:
71 | case UnicodeCategory.OtherNotAssigned:
72 | return true;
73 | default:
74 | return false;
75 | }
76 | }
77 |
78 | public static string FormatLiteral(string value, ObjectDisplayOptions options)
79 | {
80 | if (value == null)
81 | throw new ArgumentNullException(nameof(value));
82 | StringBuilder builder = new StringBuilder();
83 | bool flag1 = options.IncludesOption(ObjectDisplayOptions.UseQuotes);
84 | bool flag2 = options.IncludesOption(ObjectDisplayOptions.EscapeNonPrintableCharacters);
85 | bool flag3 = flag1 && !flag2 && ObjectDisplay.ContainsNewLine(value);
86 | if (flag1)
87 | {
88 | if (flag3)
89 | builder.Append('@');
90 | builder.Append('"');
91 | }
92 | for (int index = 0; index < value.Length; ++index)
93 | {
94 | char ch = value[index];
95 | if (flag2 && CharUnicodeInfo.GetUnicodeCategory(ch) == UnicodeCategory.Surrogate)
96 | {
97 | UnicodeCategory unicodeCategory = CharUnicodeInfo.GetUnicodeCategory(value, index);
98 | if (unicodeCategory == UnicodeCategory.Surrogate)
99 | builder.Append("\\u" + ((int)ch).ToString("x4"));
100 | else if (ObjectDisplay.NeedsEscaping(unicodeCategory))
101 | {
102 | int utf32 = char.ConvertToUtf32(value, index);
103 | builder.Append("\\U" + utf32.ToString("x8"));
104 | ++index;
105 | }
106 | else
107 | {
108 | builder.Append(ch);
109 | builder.Append(value[++index]);
110 | }
111 | }
112 | else
113 | {
114 | string replaceWith;
115 | if (flag2 && ObjectDisplay.TryReplaceChar(ch, out replaceWith))
116 | builder.Append(replaceWith);
117 | else if (flag1 && ch == '"')
118 | {
119 | if (flag3)
120 | {
121 | builder.Append('"');
122 | builder.Append('"');
123 | }
124 | else
125 | {
126 | builder.Append('\\');
127 | builder.Append('"');
128 | }
129 | }
130 | else
131 | builder.Append(ch);
132 | }
133 | }
134 | if (flag1)
135 | builder.Append('"');
136 | return builder.ToString();
137 | }
138 |
139 | private static bool IsNewLine(char ch)
140 | {
141 | if (ch != '\r' && ch != '\n' && (ch != '\x0085' && ch != '\x2028'))
142 | return ch == '\x2029';
143 | return true;
144 | }
145 |
146 | private static bool ContainsNewLine(string s)
147 | {
148 | foreach (char ch in s)
149 | {
150 | if (IsNewLine(ch))
151 | return true;
152 | }
153 | return false;
154 | }
155 |
156 | internal static string FormatLiteral(char c, ObjectDisplayOptions options)
157 | {
158 | StringBuilder builder = new StringBuilder();
159 | if (options.IncludesOption(ObjectDisplayOptions.IncludeCodePoints))
160 | {
161 | builder.Append(options.IncludesOption(ObjectDisplayOptions.UseHexadecimalNumbers) ? "0x" + ((int)c).ToString("x4") : ((int)c).ToString());
162 | builder.Append(" ");
163 | }
164 | bool flag1 = options.IncludesOption(ObjectDisplayOptions.UseQuotes);
165 | bool flag2 = options.IncludesOption(ObjectDisplayOptions.EscapeNonPrintableCharacters);
166 | if (flag1)
167 | builder.Append('\'');
168 | string replaceWith;
169 | if (flag2 && ObjectDisplay.TryReplaceChar(c, out replaceWith))
170 | builder.Append(replaceWith);
171 | else if (flag1 && c == '\'')
172 | {
173 | builder.Append('\\');
174 | builder.Append('\'');
175 | }
176 | else
177 | builder.Append(c);
178 | if (flag1)
179 | builder.Append('\'');
180 | return builder.ToString();
181 | }
182 |
183 | internal static string FormatLiteral(
184 | sbyte value,
185 | ObjectDisplayOptions options,
186 | CultureInfo cultureInfo = null)
187 | {
188 | if (options.IncludesOption(ObjectDisplayOptions.UseHexadecimalNumbers))
189 | return "0x" + (value >= 0 ? value.ToString("x2") : ((int)value).ToString("x8"));
190 | return value.ToString(ObjectDisplay.GetFormatCulture(cultureInfo));
191 | }
192 |
193 | internal static string FormatLiteral(
194 | byte value,
195 | ObjectDisplayOptions options,
196 | CultureInfo cultureInfo = null)
197 | {
198 | if (options.IncludesOption(ObjectDisplayOptions.UseHexadecimalNumbers))
199 | return "0x" + value.ToString("x2");
200 | return value.ToString(ObjectDisplay.GetFormatCulture(cultureInfo));
201 | }
202 |
203 | internal static string FormatLiteral(
204 | short value,
205 | ObjectDisplayOptions options,
206 | CultureInfo cultureInfo = null)
207 | {
208 | if (options.IncludesOption(ObjectDisplayOptions.UseHexadecimalNumbers))
209 | return "0x" + (value >= 0 ? value.ToString("x4") : ((int)value).ToString("x8"));
210 | return value.ToString(ObjectDisplay.GetFormatCulture(cultureInfo));
211 | }
212 |
213 | internal static string FormatLiteral(
214 | ushort value,
215 | ObjectDisplayOptions options,
216 | CultureInfo cultureInfo = null)
217 | {
218 | if (options.IncludesOption(ObjectDisplayOptions.UseHexadecimalNumbers))
219 | return "0x" + value.ToString("x4");
220 | return value.ToString(ObjectDisplay.GetFormatCulture(cultureInfo));
221 | }
222 |
223 | internal static string FormatLiteral(
224 | int value,
225 | ObjectDisplayOptions options,
226 | CultureInfo cultureInfo = null)
227 | {
228 | if (options.IncludesOption(ObjectDisplayOptions.UseHexadecimalNumbers))
229 | return "0x" + value.ToString("x8");
230 | return value.ToString(ObjectDisplay.GetFormatCulture(cultureInfo));
231 | }
232 |
233 | internal static string FormatLiteral(
234 | uint value,
235 | ObjectDisplayOptions options,
236 | CultureInfo cultureInfo = null)
237 | {
238 | StringBuilder builder = new StringBuilder();
239 | if (options.IncludesOption(ObjectDisplayOptions.UseHexadecimalNumbers))
240 | {
241 | builder.Append("0x");
242 | builder.Append(value.ToString("x8"));
243 | }
244 | else
245 | builder.Append(value.ToString(ObjectDisplay.GetFormatCulture(cultureInfo)));
246 | if (options.IncludesOption(ObjectDisplayOptions.IncludeTypeSuffix))
247 | builder.Append('U');
248 | return builder.ToString();
249 | }
250 |
251 | internal static string FormatLiteral(
252 | long value,
253 | ObjectDisplayOptions options,
254 | CultureInfo cultureInfo = null)
255 | {
256 | StringBuilder builder = new StringBuilder();
257 | if (options.IncludesOption(ObjectDisplayOptions.UseHexadecimalNumbers))
258 | {
259 | builder.Append("0x");
260 | builder.Append(value.ToString("x16"));
261 | }
262 | else
263 | builder.Append(value.ToString(ObjectDisplay.GetFormatCulture(cultureInfo)));
264 | if (options.IncludesOption(ObjectDisplayOptions.IncludeTypeSuffix))
265 | builder.Append('L');
266 | return builder.ToString();
267 | }
268 |
269 | internal static string FormatLiteral(
270 | ulong value,
271 | ObjectDisplayOptions options,
272 | CultureInfo cultureInfo = null)
273 | {
274 | StringBuilder builder = new StringBuilder();
275 | if (options.IncludesOption(ObjectDisplayOptions.UseHexadecimalNumbers))
276 | {
277 | builder.Append("0x");
278 | builder.Append(value.ToString("x16"));
279 | }
280 | else
281 | builder.Append(value.ToString(ObjectDisplay.GetFormatCulture(cultureInfo)));
282 | if (options.IncludesOption(ObjectDisplayOptions.IncludeTypeSuffix))
283 | builder.Append("UL");
284 | return builder.ToString();
285 | }
286 |
287 | internal static string FormatLiteral(
288 | double value,
289 | ObjectDisplayOptions options,
290 | CultureInfo cultureInfo = null)
291 | {
292 | string str = value.ToString("R", ObjectDisplay.GetFormatCulture(cultureInfo));
293 | if (!options.IncludesOption(ObjectDisplayOptions.IncludeTypeSuffix))
294 | return str;
295 | return str + "D";
296 | }
297 |
298 | internal static string FormatLiteral(
299 | float value,
300 | ObjectDisplayOptions options,
301 | CultureInfo cultureInfo = null)
302 | {
303 | string str = value.ToString("R", ObjectDisplay.GetFormatCulture(cultureInfo));
304 | if (!options.IncludesOption(ObjectDisplayOptions.IncludeTypeSuffix))
305 | return str;
306 | return str + "F";
307 | }
308 |
309 | internal static string FormatLiteral(
310 | Decimal value,
311 | ObjectDisplayOptions options,
312 | CultureInfo cultureInfo = null)
313 | {
314 | string str = value.ToString(ObjectDisplay.GetFormatCulture(cultureInfo));
315 | if (!options.IncludesOption(ObjectDisplayOptions.IncludeTypeSuffix))
316 | return str;
317 | return str + "M";
318 | }
319 |
320 | private static CultureInfo GetFormatCulture(CultureInfo cultureInfo)
321 | {
322 | return cultureInfo ?? CultureInfo.InvariantCulture;
323 | }
324 | }
325 | }
326 |
--------------------------------------------------------------------------------
/MrHuo.Extensions/ObjectFormatter/GeneratedNames.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Globalization;
3 | using System.Text;
4 |
5 | namespace MrHuo.Extensions
6 | {
7 | internal static class GeneratedNames
8 | {
9 | internal const string SynthesizedLocalNamePrefix = "CS$";
10 | internal const char DotReplacementInTypeNames = '-';
11 | private const string SuffixSeparator = "__";
12 | private const char IdSeparator = '_';
13 | private const char GenerationSeparator = '#';
14 | private const char LocalFunctionNameTerminator = '|';
15 | internal const string AnonymousNamePrefix = "<>f__AnonymousType";
16 |
17 | internal static bool IsGeneratedMemberName(string memberName)
18 | {
19 | if (memberName.Length > 0)
20 | return memberName[0] == '<';
21 | return false;
22 | }
23 |
24 | internal static string MakeBackingFieldName(string propertyName)
25 | {
26 | return "<" + propertyName + ">k__BackingField";
27 | }
28 |
29 | internal static string MakeIteratorFinallyMethodName(int iteratorState)
30 | {
31 | return "<>m__Finally" + StringExtensions.GetNumeral(Math.Abs(iteratorState + 2));
32 | }
33 |
34 | internal static string MakeStaticLambdaDisplayClassName(int methodOrdinal, int generation)
35 | {
36 | return GeneratedNames.MakeMethodScopedSynthesizedName(GeneratedNameKind.LambdaDisplayClass, methodOrdinal, generation, null, null, char.MinValue, -1, -1);
37 | }
38 |
39 | internal static string MakeLambdaDisplayClassName(
40 | int methodOrdinal,
41 | int generation,
42 | int closureOrdinal,
43 | int closureGeneration)
44 | {
45 | return GeneratedNames.MakeMethodScopedSynthesizedName(GeneratedNameKind.LambdaDisplayClass, methodOrdinal, generation, null, "DisplayClass", char.MinValue, closureOrdinal, closureGeneration);
46 | }
47 |
48 | internal static string MakeAnonymousTypeTemplateName(
49 | int index,
50 | int submissionSlotIndex,
51 | string moduleId)
52 | {
53 | string str = "<" + moduleId + ">f__AnonymousType" + StringExtensions.GetNumeral(index);
54 | if (submissionSlotIndex >= 0)
55 | str = str + "#" + StringExtensions.GetNumeral(submissionSlotIndex);
56 | return str;
57 | }
58 |
59 | internal static bool TryParseAnonymousTypeTemplateName(string name, out int index)
60 | {
61 | if (name.StartsWith("<>f__AnonymousType", StringComparison.Ordinal) && int.TryParse(name.Substring("<>f__AnonymousType".Length), NumberStyles.None, CultureInfo.InvariantCulture, out index))
62 | return true;
63 | index = -1;
64 | return false;
65 | }
66 |
67 | internal static string MakeAnonymousTypeBackingFieldName(string propertyName)
68 | {
69 | return "<" + propertyName + ">i__Field";
70 | }
71 |
72 | internal static string MakeAnonymousTypeParameterName(string propertyName)
73 | {
74 | return "<" + propertyName + ">j__TPar";
75 | }
76 |
77 | internal static bool TryParseAnonymousTypeParameterName(
78 | string typeParameterName,
79 | out string propertyName)
80 | {
81 | if (typeParameterName.StartsWith("<", StringComparison.Ordinal) && typeParameterName.EndsWith(">j__TPar", StringComparison.Ordinal))
82 | {
83 | propertyName = typeParameterName.Substring(1, typeParameterName.Length - 9);
84 | return true;
85 | }
86 | propertyName = null;
87 | return false;
88 | }
89 |
90 | internal static string MakeStateMachineTypeName(
91 | string methodName,
92 | int methodOrdinal,
93 | int generation)
94 | {
95 | return GeneratedNames.MakeMethodScopedSynthesizedName(GeneratedNameKind.StateMachineType, methodOrdinal, generation, methodName, null, char.MinValue, -1, -1);
96 | }
97 |
98 | internal static string MakeBaseMethodWrapperName(int uniqueId)
99 | {
100 | return "<>n__" + StringExtensions.GetNumeral(uniqueId);
101 | }
102 |
103 | internal static string MakeLambdaMethodName(
104 | string methodName,
105 | int methodOrdinal,
106 | int methodGeneration,
107 | int lambdaOrdinal,
108 | int lambdaGeneration)
109 | {
110 | return GeneratedNames.MakeMethodScopedSynthesizedName(GeneratedNameKind.LambdaMethod, methodOrdinal, methodGeneration, methodName, null, char.MinValue, lambdaOrdinal, lambdaGeneration);
111 | }
112 |
113 | internal static string MakeLambdaCacheFieldName(
114 | int methodOrdinal,
115 | int generation,
116 | int lambdaOrdinal,
117 | int lambdaGeneration)
118 | {
119 | return GeneratedNames.MakeMethodScopedSynthesizedName(GeneratedNameKind.LambdaCacheField, methodOrdinal, generation, null, null, char.MinValue, lambdaOrdinal, lambdaGeneration);
120 | }
121 |
122 | internal static string MakeLocalFunctionName(
123 | string methodName,
124 | string localFunctionName,
125 | int methodOrdinal,
126 | int methodGeneration,
127 | int lambdaOrdinal,
128 | int lambdaGeneration)
129 | {
130 | return GeneratedNames.MakeMethodScopedSynthesizedName(GeneratedNameKind.LocalFunction, methodOrdinal, methodGeneration, methodName, localFunctionName, '|', lambdaOrdinal, lambdaGeneration);
131 | }
132 |
133 | private static string MakeMethodScopedSynthesizedName(
134 | GeneratedNameKind kind,
135 | int methodOrdinal,
136 | int methodGeneration,
137 | string methodNameOpt = null,
138 | string suffix = null,
139 | char suffixTerminator = '\0',
140 | int entityOrdinal = -1,
141 | int entityGeneration = -1)
142 | {
143 | StringBuilder builder = new StringBuilder();
144 | builder.Append('<');
145 | if (methodNameOpt != null)
146 | {
147 | builder.Append(methodNameOpt);
148 | if (kind.IsTypeName())
149 | builder.Replace('.', '-');
150 | }
151 | builder.Append('>');
152 | builder.Append((char)kind);
153 | if (suffix != null || methodOrdinal >= 0 || entityOrdinal >= 0)
154 | {
155 | builder.Append("__");
156 | builder.Append(suffix);
157 | if (suffixTerminator != char.MinValue)
158 | builder.Append(suffixTerminator);
159 | if (methodOrdinal >= 0)
160 | {
161 | builder.Append(methodOrdinal);
162 | GeneratedNames.AppendOptionalGeneration(builder, methodGeneration);
163 | }
164 | if (entityOrdinal >= 0)
165 | {
166 | if (methodOrdinal >= 0)
167 | builder.Append('_');
168 | builder.Append(entityOrdinal);
169 | GeneratedNames.AppendOptionalGeneration(builder, entityGeneration);
170 | }
171 | }
172 | return builder.ToString();
173 | }
174 |
175 | private static void AppendOptionalGeneration(StringBuilder builder, int generation)
176 | {
177 | if (generation <= 0)
178 | return;
179 | builder.Append('#');
180 | builder.Append(generation);
181 | }
182 |
183 | internal static GeneratedNameKind GetKind(string name)
184 | {
185 | GeneratedNameKind kind;
186 | int openBracketOffset;
187 | int closeBracketOffset;
188 | if (!GeneratedNames.TryParseGeneratedName(name, out kind, out openBracketOffset, out closeBracketOffset))
189 | return GeneratedNameKind.None;
190 | return kind;
191 | }
192 |
193 | internal static bool TryParseGeneratedName(
194 | string name,
195 | out GeneratedNameKind kind,
196 | out int openBracketOffset,
197 | out int closeBracketOffset)
198 | {
199 | openBracketOffset = -1;
200 | if (name.StartsWith("CS$<", StringComparison.Ordinal))
201 | openBracketOffset = 3;
202 | else if (name.StartsWith("<", StringComparison.Ordinal))
203 | openBracketOffset = 0;
204 | if (openBracketOffset >= 0)
205 | {
206 | closeBracketOffset = name.IndexOfBalancedParenthesis(openBracketOffset, '>');
207 | if (closeBracketOffset >= 0 && closeBracketOffset + 1 < name.Length)
208 | {
209 | int num = name[closeBracketOffset + 1];
210 | if (num >= 49 && num <= 57 || num >= 97 && num <= 122)
211 | {
212 | kind = (GeneratedNameKind)num;
213 | return true;
214 | }
215 | }
216 | }
217 | kind = GeneratedNameKind.None;
218 | openBracketOffset = -1;
219 | closeBracketOffset = -1;
220 | return false;
221 | }
222 |
223 | internal static bool TryParseSourceMethodNameFromGeneratedName(
224 | string generatedName,
225 | GeneratedNameKind requiredKind,
226 | out string methodName)
227 | {
228 | GeneratedNameKind kind;
229 | int openBracketOffset;
230 | int closeBracketOffset;
231 | if (!GeneratedNames.TryParseGeneratedName(generatedName, out kind, out openBracketOffset, out closeBracketOffset))
232 | {
233 | methodName = null;
234 | return false;
235 | }
236 | if (requiredKind != GeneratedNameKind.None && kind != requiredKind)
237 | {
238 | methodName = null;
239 | return false;
240 | }
241 | methodName = generatedName.Substring(openBracketOffset + 1, closeBracketOffset - openBracketOffset - 1);
242 | if (kind.IsTypeName())
243 | methodName = methodName.Replace('-', '.');
244 | return true;
245 | }
246 |
247 | internal static string AsyncAwaiterFieldName(int slotIndex)
248 | {
249 | return "<>u__" + StringExtensions.GetNumeral(slotIndex + 1);
250 | }
251 |
252 | internal static bool TryParseSlotIndex(string fieldName, out int slotIndex)
253 | {
254 | int num = fieldName.LastIndexOf('_');
255 | if (num - 1 < 0 || num == fieldName.Length || fieldName[num - 1] != '_')
256 | {
257 | slotIndex = -1;
258 | return false;
259 | }
260 | if (int.TryParse(fieldName.Substring(num + 1), NumberStyles.None, CultureInfo.InvariantCulture, out slotIndex) && slotIndex >= 1)
261 | {
262 | --slotIndex;
263 | return true;
264 | }
265 | slotIndex = -1;
266 | return false;
267 | }
268 |
269 | internal static string MakeCachedFrameInstanceFieldName()
270 | {
271 | return "<>9";
272 | }
273 |
274 | internal static string MakeLambdaDisplayLocalName(int uniqueId)
275 | {
276 | return "CS$<>8__locals" + StringExtensions.GetNumeral(uniqueId);
277 | }
278 |
279 | internal static bool IsSynthesizedLocalName(string name)
280 | {
281 | return name.StartsWith("CS$", StringComparison.Ordinal);
282 | }
283 |
284 | internal static string MakeFixedFieldImplementationName(string fieldName)
285 | {
286 | return "<" + fieldName + ">e__FixedBuffer";
287 | }
288 |
289 | internal static string MakeStateMachineStateFieldName()
290 | {
291 | return "<>1__state";
292 | }
293 |
294 | internal static string MakeIteratorCurrentFieldName()
295 | {
296 | return "<>2__current";
297 | }
298 |
299 | internal static string MakeIteratorCurrentThreadIdFieldName()
300 | {
301 | return "<>l__initialThreadId";
302 | }
303 |
304 | internal static string ThisProxyFieldName()
305 | {
306 | return "<>4__this";
307 | }
308 |
309 | internal static string StateMachineThisParameterProxyName()
310 | {
311 | return GeneratedNames.StateMachineParameterProxyFieldName(GeneratedNames.ThisProxyFieldName());
312 | }
313 |
314 | internal static string StateMachineParameterProxyFieldName(string parameterName)
315 | {
316 | return "<>3__" + parameterName;
317 | }
318 |
319 | internal static string MakeDynamicCallSiteContainerName(int methodOrdinal, int generation)
320 | {
321 | return GeneratedNames.MakeMethodScopedSynthesizedName(GeneratedNameKind.DynamicCallSiteContainerType, methodOrdinal, generation, null, null, char.MinValue, -1, -1);
322 | }
323 |
324 | internal static string MakeDynamicCallSiteFieldName(int uniqueId)
325 | {
326 | return "<>p__" + StringExtensions.GetNumeral(uniqueId);
327 | }
328 |
329 | internal static string AsyncBuilderFieldName()
330 | {
331 | return "<>t__builder";
332 | }
333 |
334 | internal static string ReusableHoistedLocalFieldName(int number)
335 | {
336 | return "<>7__wrap" + StringExtensions.GetNumeral(number);
337 | }
338 |
339 | internal static string LambdaCopyParameterName(int ordinal)
340 | {
341 | return "";
342 | }
343 | }
344 | }
345 |
--------------------------------------------------------------------------------
/MrHuo.Extensions/ExcelHelper.cs:
--------------------------------------------------------------------------------
1 | using NPOI.HSSF.UserModel;
2 | using NPOI.SS.UserModel;
3 | using NPOI.XSSF.UserModel;
4 | using System;
5 | using System.Collections.Generic;
6 | using System.Data;
7 | using System.IO;
8 |
9 | namespace MrHuo.Extensions
10 | {
11 | ///
12 | /// Excel 帮助类
13 | /// 包含功能:Excel 导入,Excel 导出
14 | ///
15 | public static class ExcelHelper
16 | {
17 | #region [ICellExtensions]
18 | ///
19 | /// 获取单元格的数据
20 | ///
21 | ///
22 | ///
23 | public static object GetCellValue(this ICell cell)
24 | {
25 | switch (cell.CellType)
26 | {
27 | case CellType.Numeric:
28 | return cell.NumericCellValue;
29 | case CellType.Formula:
30 | return cell.CellFormula;
31 | case CellType.Boolean:
32 | return cell.BooleanCellValue;
33 | case CellType.Blank:
34 | case CellType.String:
35 | case CellType.Unknown:
36 | default:
37 | try
38 | {
39 | return cell.StringCellValue;
40 | }
41 | catch (Exception ex)
42 | {
43 | return null;
44 | }
45 | }
46 | }
47 | #endregion
48 |
49 | #region [Import]
50 | ///
51 | /// 从 Excel 导入数据
52 | ///
53 | ///
54 | /// Excel 文件
55 | /// 列定义
56 | /// 是否包含标题行,默认包含
57 | /// 标题行数,默认1行
58 | /// Sheet 索引
59 | ///
60 | public static List Import(
61 | string excelFile,
62 | List<(string PropertyName, int? ColumnIndex, Func