From 920f445da06d7c02f9e620c17a4866446e9810bc Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Thu, 16 Feb 2012 14:07:50 +0100 Subject: [PATCH] Normalize newlines. --- .../Transforms/PatternStatementTransform.cs | 132 +++++++++--------- ICSharpCode.Decompiler/CecilExtensions.cs | 36 ++--- 2 files changed, 84 insertions(+), 84 deletions(-) diff --git a/ICSharpCode.Decompiler/Ast/Transforms/PatternStatementTransform.cs b/ICSharpCode.Decompiler/Ast/Transforms/PatternStatementTransform.cs index ef2c2524e..fc02a15d7 100644 --- a/ICSharpCode.Decompiler/Ast/Transforms/PatternStatementTransform.cs +++ b/ICSharpCode.Decompiler/Ast/Transforms/PatternStatementTransform.cs @@ -764,73 +764,73 @@ namespace ICSharpCode.Decompiler.Ast.Transforms } List> BuildDictionary(List dictCreation) - { - if (context.Settings.ObjectOrCollectionInitializers && dictCreation.Count == 1) - return BuildDictionaryFromInitializer(dictCreation[0]); - + { + if (context.Settings.ObjectOrCollectionInitializers && dictCreation.Count == 1) + return BuildDictionaryFromInitializer(dictCreation[0]); + return BuildDictionaryFromAddMethodCalls(dictCreation); - } - - static readonly Statement assignInitializedDictionary = new ExpressionStatement { - Expression = new AssignmentExpression { - Left = new AnyNode().ToExpression(), - Right = new ObjectCreateExpression { - Type = new AnyNode(), - Arguments = { new Repeat(new AnyNode()) }, - Initializer = new ArrayInitializerExpression { - Elements = { new Repeat(new AnyNode("dictJumpTable")) } - } - }, - }, - }; - - private List> BuildDictionaryFromInitializer(Statement statement) - { - List> dict = new List>(); - Match m = assignInitializedDictionary.Match(statement); - if (!m.Success) - return dict; - - foreach (ArrayInitializerExpression initializer in m.Get("dictJumpTable")) { - KeyValuePair pair; - if (TryGetPairFrom(initializer.Elements, out pair)) - dict.Add(pair); - } - - return dict; - } - - private static List> BuildDictionaryFromAddMethodCalls(List dictCreation) - { - List> dict = new List>(); - for (int i = 0; i < dictCreation.Count; i++) { - ExpressionStatement es = dictCreation[i] as ExpressionStatement; - if (es == null) - continue; - InvocationExpression ie = es.Expression as InvocationExpression; - if (ie == null) - continue; - - KeyValuePair pair; - if (TryGetPairFrom(ie.Arguments, out pair)) - dict.Add(pair); - } - return dict; - } - - private static bool TryGetPairFrom(AstNodeCollection expressions, out KeyValuePair pair) - { - PrimitiveExpression arg1 = expressions.ElementAtOrDefault(0) as PrimitiveExpression; - PrimitiveExpression arg2 = expressions.ElementAtOrDefault(1) as PrimitiveExpression; - if (arg1 != null && arg2 != null && arg1.Value is string && arg2.Value is int) { - pair = new KeyValuePair((string)arg1.Value, (int)arg2.Value); - return true; - } - - pair = default(KeyValuePair); - return false; - } - + } + + static readonly Statement assignInitializedDictionary = new ExpressionStatement { + Expression = new AssignmentExpression { + Left = new AnyNode().ToExpression(), + Right = new ObjectCreateExpression { + Type = new AnyNode(), + Arguments = { new Repeat(new AnyNode()) }, + Initializer = new ArrayInitializerExpression { + Elements = { new Repeat(new AnyNode("dictJumpTable")) } + } + }, + }, + }; + + private List> BuildDictionaryFromInitializer(Statement statement) + { + List> dict = new List>(); + Match m = assignInitializedDictionary.Match(statement); + if (!m.Success) + return dict; + + foreach (ArrayInitializerExpression initializer in m.Get("dictJumpTable")) { + KeyValuePair pair; + if (TryGetPairFrom(initializer.Elements, out pair)) + dict.Add(pair); + } + + return dict; + } + + private static List> BuildDictionaryFromAddMethodCalls(List dictCreation) + { + List> dict = new List>(); + for (int i = 0; i < dictCreation.Count; i++) { + ExpressionStatement es = dictCreation[i] as ExpressionStatement; + if (es == null) + continue; + InvocationExpression ie = es.Expression as InvocationExpression; + if (ie == null) + continue; + + KeyValuePair pair; + if (TryGetPairFrom(ie.Arguments, out pair)) + dict.Add(pair); + } + return dict; + } + + private static bool TryGetPairFrom(AstNodeCollection expressions, out KeyValuePair pair) + { + PrimitiveExpression arg1 = expressions.ElementAtOrDefault(0) as PrimitiveExpression; + PrimitiveExpression arg2 = expressions.ElementAtOrDefault(1) as PrimitiveExpression; + if (arg1 != null && arg2 != null && arg1.Value is string && arg2.Value is int) { + pair = new KeyValuePair((string)arg1.Value, (int)arg2.Value); + return true; + } + + pair = default(KeyValuePair); + return false; + } + #endregion #region Automatic Properties diff --git a/ICSharpCode.Decompiler/CecilExtensions.cs b/ICSharpCode.Decompiler/CecilExtensions.cs index df9e43242..82b67a07f 100644 --- a/ICSharpCode.Decompiler/CecilExtensions.cs +++ b/ICSharpCode.Decompiler/CecilExtensions.cs @@ -216,21 +216,21 @@ namespace ICSharpCode.Decompiler return IsCompilerGeneratedOrIsInCompilerGeneratedClass(member.DeclaringType); } - public static TypeReference GetEnumUnderlyingType(this TypeDefinition type) - { - if (!type.IsEnum) - throw new ArgumentException("Type must be an enum", "type"); - - var fields = type.Fields; - - for (int i = 0; i < fields.Count; i++) - { - var field = fields[i]; - if (!field.IsStatic) - return field.FieldType; - } - - throw new NotSupportedException(); + public static TypeReference GetEnumUnderlyingType(this TypeDefinition type) + { + if (!type.IsEnum) + throw new ArgumentException("Type must be an enum", "type"); + + var fields = type.Fields; + + for (int i = 0; i < fields.Count; i++) + { + var field = fields[i]; + if (!field.IsStatic) + return field.FieldType; + } + + throw new NotSupportedException(); } public static bool IsAnonymousType(this TypeReference type) @@ -244,9 +244,9 @@ namespace ICSharpCode.Decompiler return false; } - public static bool HasGeneratedName(this MemberReference member) - { - return member.Name.StartsWith("<", StringComparison.Ordinal); + public static bool HasGeneratedName(this MemberReference member) + { + return member.Name.StartsWith("<", StringComparison.Ordinal); } public static bool ContainsAnonymousType(this TypeReference type)