From 88238aae3deed94fc95a551bfc8e622b3396d008 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jean-Philippe=20Bruy=C3=A8re?= Date: Fri, 14 Dec 2018 20:03:50 +0100 Subject: [PATCH] ordinal string tests, debug log loading times, dataSourceType property --- .gitignore | 1 + Crow/Crow.csproj | 2 +- Crow/src/Colors.cs | 10 ++-- Crow/src/CompilerServices/CompilerServices.cs | 17 +++--- Crow/src/Fill/Fill.cs | 6 +- Crow/src/GraphicObjects/GraphicObject.cs | 31 ++++++---- Crow/src/GraphicObjects/TemplatedGroup.cs | 14 ++--- Crow/src/IML/BindingDefinition.cs | 9 +-- Crow/src/IML/BindingMember.cs | 4 +- Crow/src/IML/IMLContext.cs | 6 +- Crow/src/IML/NodeAddress.cs | 2 +- Crow/src/Instantiator.cs | 58 +++++++++++++------ Crow/src/Interface.cs | 6 +- Crow/src/ItemTemplate.cs | 4 +- Crow/src/Size.cs | 3 +- CrowIDE/src/Editors/Parsers/CSharpParser.cs | 4 +- CrowIDE/src/Project.cs | 2 +- Tests/keysyms.cs | 8 +-- 18 files changed, 108 insertions(+), 79 deletions(-) diff --git a/.gitignore b/.gitignore index b43159a2..e3dbba2d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +*.log build Win_x86 Crow.userprefs diff --git a/Crow/Crow.csproj b/Crow/Crow.csproj index dfdc08f7..186019f8 100644 --- a/Crow/Crow.csproj +++ b/Crow/Crow.csproj @@ -32,7 +32,7 @@ true false $(SolutionDir)build\Debug - DEBUG_BINDING_FUNC_CALLS0;DEBUG_DRAGNDROP0;DEBUG_LOG0;XLIB_BACKEND0;DESIGN_MODE;DEBUG_UPDATE0;DEBUG_FOCUS0;DEBUG_DISPOSE0;TRACE0;DEBUG;MEASURE_TIME;DEBUG_LOAD0;DEBUG_BINDING0;DEBUG_CLIP_RECTANGLE0 + TRACE0;DEBUG;DEBUG_BINDING_FUNC_CALLS0;DEBUG_DRAGNDROP0;DEBUG_LOG0;XLIB_BACKEND0;DESIGN_MODE;DEBUG_UPDATE0;DEBUG_FOCUS0;DEBUG_DISPOSE0;MEASURE_TIME;DEBUG_LOAD0;DEBUG_BINDING0;DEBUG_CLIP_RECTANGLE0 diff --git a/Crow/src/Colors.cs b/Crow/src/Colors.cs index 1da99135..8b918074 100644 --- a/Crow/src/Colors.cs +++ b/Crow/src/Colors.cs @@ -41,8 +41,6 @@ namespace Crow /// public struct Color { - internal static Type TColor = typeof(Color); - #region CTOR public Color(double _R, double _G, double _B, double _A) { @@ -104,7 +102,7 @@ namespace Crow if (string.IsNullOrEmpty(s)) return White; Color cc = default(Color); - if (s.StartsWith ("#")) { + if (s.StartsWith ("#", StringComparison.Ordinal)) { cc.R = int.Parse (s.Substring (1, 2), System.Globalization.NumberStyles.HexNumber) / 255.0; cc.G = int.Parse (s.Substring (3, 2), System.Globalization.NumberStyles.HexNumber) / 255.0; cc.B = int.Parse (s.Substring (5, 2), System.Globalization.NumberStyles.HexNumber) / 255.0; @@ -151,13 +149,13 @@ namespace Crow } public static bool operator ==(Color c, string n) { - return n.StartsWith("#") ? + return n.StartsWith("#", StringComparison.Ordinal) ? string.Equals(c.HtmlCode, n, StringComparison.Ordinal) : string.Equals(c.Name, n, StringComparison.Ordinal); } public static bool operator !=(Color c, string n) { - return n.StartsWith("#") ? + return n.StartsWith("#", StringComparison.Ordinal) ? !string.Equals(c.HtmlCode, n, StringComparison.Ordinal) : !string.Equals(c.Name, n, StringComparison.Ordinal); } @@ -429,7 +427,7 @@ namespace Crow } public override bool Equals (object obj) { - return (obj == null || obj.GetType() != TColor) ? + return (obj == null || obj.GetType() != typeof(Color)) ? false : this == (Color)obj; } diff --git a/Crow/src/CompilerServices/CompilerServices.cs b/Crow/src/CompilerServices/CompilerServices.cs index 14d9bb76..ee6770a8 100644 --- a/Crow/src/CompilerServices/CompilerServices.cs +++ b/Crow/src/CompilerServices/CompilerServices.cs @@ -50,7 +50,6 @@ namespace Crow.IML /// internal static Dictionary knownExtMethods = new Dictionary (); - internal static Type TObject = typeof(object); internal static MethodInfo stringEquals = typeof (string).GetMethod("Equals", new Type [3] { typeof (string), typeof (string), typeof (StringComparison) }); internal static MethodInfo miObjToString = typeof(object).GetMethod("ToString"); internal static MethodInfo miGetType = typeof(object).GetMethod("GetType"); @@ -289,7 +288,7 @@ namespace Crow.IML static MemberInfo getMemberInfoWithReflexion(object instance, string member){ Type t = instance.GetType(); #if DEBUG_BINDING_FUNC_CALLS - Console.WriteLine ($"getMemberInfoWithReflexion ({instance},{member}); type:{t}"); + Console.WriteLine ($"getMemberInfoWithReflexion ({instance},{member}); type:{t}"); #endif MemberInfo mi = t.GetMember (member)?.FirstOrDefault(); if (mi == null) @@ -330,7 +329,7 @@ namespace Crow.IML try { if (value != null) { - if (destType == TObject)//TODO: check that test of destType is not causing problems + if (destType == typeof (object))//TODO: check that test of destType is not causing problems convertedVal = value; else { origType = value.GetType (); @@ -387,7 +386,7 @@ namespace Crow.IML if (tmp != null) return tmp; - if (dstType == typeof(string) || dstType == CompilerServices.TObject)//TODO:object should be allowed to return null and not "" + if (dstType == typeof(string) || dstType == typeof (object))//TODO:object should be allowed to return null and not "" return ""; if (dstType.IsValueType) return Activator.CreateInstance (dstType); @@ -551,7 +550,7 @@ namespace Crow.IML /// Emit MSIL for conversion from orig type to dest type /// internal static void emitConvert(ILGenerator il, Type origType, Type destType){ - if (destType == CompilerServices.TObject) + if (destType == typeof(object)) return; if (destType == typeof(string)) { System.Reflection.Emit.Label emitNullStr = il.DefineLabel (); @@ -600,7 +599,7 @@ namespace Crow.IML else { //implicit conversion can't be defined from or to object base class, //so we will check if object underlying type is one of the implicit converter of destType - if (origType == TObject) {//test all implicit converter to destType on obj + if (origType == typeof(object)) {//test all implicit converter to destType on obj System.Reflection.Emit.Label emitTestNextImpOp; System.Reflection.Emit.Label emitImpOpFound = il.DefineLabel (); foreach (MethodInfo mi in destType.GetMethods(BindingFlags.Public|BindingFlags.Static)) { @@ -691,11 +690,11 @@ namespace Crow.IML il.MarkLabel (convert); il.Emit (OpCodes.Ldnull);//null instance for invoke il.Emit (OpCodes.Ldc_I4_1); - il.Emit(OpCodes.Newarr, CompilerServices.TObject); + il.Emit(OpCodes.Newarr, typeof (object)); il.Emit (OpCodes.Dup);//duplicate the array ref il.Emit (OpCodes.Ldc_I4_0);//push the index 0 il.Emit (OpCodes.Ldloc_0);//push the orig value to convert - il.Emit (OpCodes.Stelem, CompilerServices.TObject);//set the array element at index 0 + il.Emit (OpCodes.Stelem, typeof (object));//set the array element at index 0 il.Emit (OpCodes.Callvirt, miMIInvoke); } @@ -777,7 +776,7 @@ namespace Crow.IML Type handlerArgsType = evtParams [1].ParameterType; #endregion - Type [] args = { CompilerServices.TObject, handlerArgsType }; + Type [] args = { typeof (object), handlerArgsType }; DynamicMethod dm = new DynamicMethod ("dyn_eventHandler", typeof(void), args, true); diff --git a/Crow/src/Fill/Fill.cs b/Crow/src/Fill/Fill.cs index d98e47cf..0c0bdf5b 100644 --- a/Crow/src/Fill/Fill.cs +++ b/Crow/src/Fill/Fill.cs @@ -44,16 +44,16 @@ namespace Crow public static object Parse (string s){ if (string.IsNullOrEmpty (s)) return null; - if (s.Substring (1).StartsWith ("gradient")) + if (s.Substring (1).StartsWith ("gradient", StringComparison.Ordinal)) return (Gradient)Gradient.Parse (s); if (s.EndsWith (".svg", true, System.Globalization.CultureInfo.InvariantCulture)) - return SvgPicture.Parse (s); + return Parse (s); if (s.EndsWith (".png", true, System.Globalization.CultureInfo.InvariantCulture) || s.EndsWith (".jpg", true, System.Globalization.CultureInfo.InvariantCulture) || s.EndsWith (".jpeg", true, System.Globalization.CultureInfo.InvariantCulture) || s.EndsWith (".bmp", true, System.Globalization.CultureInfo.InvariantCulture) || s.EndsWith (".gif", true, System.Globalization.CultureInfo.InvariantCulture)) - return BmpPicture.Parse (s); + return Parse (s); return (SolidColor)SolidColor.Parse (s); } diff --git a/Crow/src/GraphicObjects/GraphicObject.cs b/Crow/src/GraphicObjects/GraphicObject.cs index b43ae54a..aa200802 100644 --- a/Crow/src/GraphicObjects/GraphicObject.cs +++ b/Crow/src/GraphicObjects/GraphicObject.cs @@ -297,6 +297,7 @@ namespace Crow Size minimumSize = "0,0"; bool cacheEnabled = false; bool clipToClientRect = true; + Type dataSourceType; protected object dataSource; bool rootDataLevel; string style; @@ -929,15 +930,26 @@ namespace Crow maximumSize = value; - NotifyValueChanged ("MaximumSize", maximumSize); + NotifyValueChanged (nameof(MaximumSize), maximumSize); RegisterForLayouting (LayoutingType.Sizing); } } /// + /// Fully qualify type name of expected data source. + /// If set, datasource bindings will be speedup by avoiding reflexion in generated dyn methods. + /// If an object of a different type is set as datasource, bindings will be canceled. + /// It accepts all derived type. + /// + [DesignCategory ("Data")] + public Type DataSourceType { + get { return dataSourceType; } + set { dataSourceType = value; } + } + /// /// Seek first logical tree upward if logicalParent is set, or seek graphic tree for /// a not null dataSource that will be active for all descendants having dataSource=null /// - [DesignCategory ("Data")] + [DesignCategory ("Data")] public virtual object DataSource { set { if (DataSource == value) @@ -1097,19 +1109,14 @@ namespace Crow //all other instance of this type would not longer use reflexion to init properly //but will fetch the dynamic initialisation method compiled for this precise type //TODO:measure speed gain. - #region Delfault values Loading dynamic compilation +#region Delfault values Loading dynamic compilation DynamicMethod dm = null; ILGenerator il = null; - /*dm = new DynamicMethod("dyn_loadDefValues", - MethodAttributes.Family | MethodAttributes.FamANDAssem | MethodAttributes.NewSlot, - CallingConventions.Standard, - typeof(void),new Type[] {CompilerServices.TObject}, thisType, true);*/ - - dm = new DynamicMethod("dyn_loadDefValues", null, new Type[] {CompilerServices.TObject}, thisType, true); + dm = new DynamicMethod("dyn_loadDefValues", null, new Type[] { typeof (object) }, thisType, true); il = dm.GetILGenerator(256); - il.DeclareLocal(CompilerServices.TObject); + il.DeclareLocal(typeof (object));//store root il.Emit(OpCodes.Nop); //set local GraphicObject to root object passed as 1st argument il.Emit (OpCodes.Ldarg_0); @@ -1122,7 +1129,7 @@ namespace Crow //TODO:dynEventHandler could be cached somewhere, maybe a style instanciator class holding the styling delegate and bound to it. foreach (string exp in CompilerServices.splitOnSemiColumnOutsideAccolades(expression)) { string trimed = exp.Trim(); - if (trimed.StartsWith ("{", StringComparison.OrdinalIgnoreCase)){ + if (trimed.StartsWith ("{", StringComparison.Ordinal)){ il.Emit (OpCodes.Ldloc_0);//load this as 1st arg of event Add //push eventInfo as 1st arg of compile @@ -1225,7 +1232,7 @@ namespace Crow } return false; } - #endregion +#endregion public virtual GraphicObject FindByName(string nameToFind){ return string.Equals(nameToFind, name, StringComparison.Ordinal) ? this : null; diff --git a/Crow/src/GraphicObjects/TemplatedGroup.cs b/Crow/src/GraphicObjects/TemplatedGroup.cs index 29056a50..b8a7c084 100644 --- a/Crow/src/GraphicObjects/TemplatedGroup.cs +++ b/Crow/src/GraphicObjects/TemplatedGroup.cs @@ -35,6 +35,7 @@ using System.Threading; using System.Linq; using Crow.IML; using System.Diagnostics; +using System.IO; namespace Crow { @@ -365,8 +366,7 @@ namespace Crow void loadPage(IList _data, Group page, string _dataTest) { #if DEBUG_LOAD - Stopwatch loadingTime = new Stopwatch (); - loadingTime.Start (); + Stopwatch loadingTime = Stopwatch.StartNew (); #endif @@ -404,12 +404,12 @@ namespace Crow // lock (CurrentInterface.LayoutMutex) // items.AddChild (page); - #if DEBUG_LOAD +#if DEBUG_LOAD loadingTime.Stop (); - Debug.WriteLine("Listbox {2} Loading: {0} ticks \t, {1} ms", - loadingTime.ElapsedTicks, - loadingTime.ElapsedMilliseconds, this.ToString()); - #endif + using (StreamWriter sw = new StreamWriter ("loading.log", true)) { + sw.WriteLine ($"NEW ;{this.ToString(),-50};{loadingTime.ElapsedTicks,8};{loadingTime.ElapsedMilliseconds,8}"); + } +#endif } protected void loadItem(object o, Group page, string _dataTest){ diff --git a/Crow/src/IML/BindingDefinition.cs b/Crow/src/IML/BindingDefinition.cs index 075b80b3..9cbaf62b 100644 --- a/Crow/src/IML/BindingDefinition.cs +++ b/Crow/src/IML/BindingDefinition.cs @@ -33,12 +33,13 @@ namespace Crow.IML /// public class BindingDefinition { - public NodeAddress SourceNA = null; - public string SourceMember = ""; - public NodeAddress TargetNA = null; + public NodeAddress SourceNA = null;//the widget declaring this binding in a member + public string SourceMember = "";//the member where the binding string has been found + public NodeAddress TargetNA = null;// public string TargetMember = ""; public string TargetName = ""; - public bool TwoWay = false; + public bool TwoWay = false;//two way binding + public Type targetType = null;//added to store dataSourceType if set #region CTOR public BindingDefinition (NodeAddress _sourceNA, string _sourceMember){ diff --git a/Crow/src/IML/BindingMember.cs b/Crow/src/IML/BindingMember.cs index 47cba5fc..f6cc047d 100644 --- a/Crow/src/IML/BindingMember.cs +++ b/Crow/src/IML/BindingMember.cs @@ -89,8 +89,8 @@ namespace Crow.IML int ptr = 0; if (splitedExp.Length == 1) { - if (splitedExp [0].StartsWith ("\'")) { - if (!splitedExp [0].EndsWith ("\'")) + if (splitedExp [0].StartsWith ("\'",StringComparison.Ordinal)) { + if (!splitedExp [0].EndsWith ("\'", StringComparison.Ordinal)) throw new Exception (string.Format ("IML:malformed string constant in binding expression: {0}", splitedExp [0])); Tokens = new string[] { splitedExp [0].Substring (1, splitedExp [0].Length - 2) }; diff --git a/Crow/src/IML/IMLContext.cs b/Crow/src/IML/IMLContext.cs index 6042e6da..8e12c41b 100644 --- a/Crow/src/IML/IMLContext.cs +++ b/Crow/src/IML/IMLContext.cs @@ -64,7 +64,7 @@ namespace Crow.IML { RootType = rootType; dm = new DynamicMethod ("dyn_instantiator", - CompilerServices.TObject, new Type [] { typeof (Instantiator), typeof (Interface) }, true); + typeof (object), new Type [] { typeof (Instantiator), typeof (Interface) }, true); il = dm.GetILGenerator (256); il.DeclareLocal (typeof (GraphicObject)); @@ -112,6 +112,10 @@ namespace Crow.IML if (bindDef.TwoWay) StorePropertyBinding (bindDef.SourceNA, bindDef.SourceMember, bindDef.TargetNA, bindDef.TargetMember); } + /// + /// Stores all the names found in current iml for binding resolution if any of them + /// are targeting named widget + /// public void StoreCurrentName(string name){ if (!Names.ContainsKey(name)) Names[name] = new List(); diff --git a/Crow/src/IML/NodeAddress.cs b/Crow/src/IML/NodeAddress.cs index 450a9d2d..55ef21b0 100644 --- a/Crow/src/IML/NodeAddress.cs +++ b/Crow/src/IML/NodeAddress.cs @@ -86,7 +86,7 @@ namespace Crow.IML if (string.IsNullOrEmpty (expression)) { return bindingDef; } else { - if (expression.StartsWith ("²")) { + if (expression.StartsWith ("²", StringComparison.Ordinal)) { bindingDef.TwoWay = true; expression = expression.Substring (1); } diff --git a/Crow/src/Instantiator.cs b/Crow/src/Instantiator.cs index 09479f05..14218bfc 100644 --- a/Crow/src/Instantiator.cs +++ b/Crow/src/Instantiator.cs @@ -101,8 +101,7 @@ namespace Crow.IML iface = _iface; sourcePath = srcPath; #if DEBUG_LOAD - Stopwatch loadingTime = new Stopwatch (); - loadingTime.Start (); + Stopwatch loadingTime = Stopwatch.StartNew (); #endif try { using (XmlReader itr = XmlReader.Create (stream)) { @@ -114,8 +113,9 @@ namespace Crow.IML } finally { #if DEBUG_LOAD loadingTime.Stop (); - Debug.WriteLine ("IML Instantiator creation '{2}' : {0} ticks, {1} ms", - loadingTime.ElapsedTicks, loadingTime.ElapsedMilliseconds, sourcePath); + using (StreamWriter sw = new StreamWriter ("loading.log", true)) { + sw.WriteLine ($"ITOR;{sourcePath,-50};{loadingTime.ElapsedTicks,8};{loadingTime.ElapsedMilliseconds,8}"); + } #endif } } @@ -155,21 +155,38 @@ namespace Crow.IML /// /// Creates a new instance of the GraphicObject compiled in the instantiator - /// and bind it the an interface /// /// The new graphic object instance - /// The interface to bind to public GraphicObject CreateInstance(){ +#if DEBUG_LOAD + Stopwatch loadingTime = Stopwatch.StartNew (); + GraphicObject o = loader (iface) as GraphicObject; + loadingTime.Stop (); + using (StreamWriter sw = new StreamWriter ("loading.log", true)) { + sw.WriteLine ($"NEW ;{sourcePath,-50};{loadingTime.ElapsedTicks,8};{loadingTime.ElapsedMilliseconds,8}"); + } + return o; +#else return loader (iface) as GraphicObject; +#endif } /// /// Creates a new instance of T compiled in the instantiator /// and bind it the an interface /// /// The new T instance - /// The interface to bind to public T CreateInstance(){ +#if DEBUG_LOAD + Stopwatch loadingTime = Stopwatch.StartNew (); + T i = (T)loader (iface); + loadingTime.Stop (); + using (StreamWriter sw = new StreamWriter ("loading.log", true)) { + sw.WriteLine ($"NEW ;{sourcePath,-50};{loadingTime.ElapsedTicks,8};{loadingTime.ElapsedMilliseconds,8}"); + } + return i; +#else return (T)loader (iface); +#endif } List dsValueChangedDynMeths = new List(); List cachedDelegates = new List(); @@ -428,8 +445,7 @@ namespace Crow.IML ctx.il.Emit (OpCodes.Ldstr, sourcePath); ctx.il.Emit (OpCodes.Stfld, typeof(GraphicObject).GetField("design_imlPath")); } - #endif - +#endif #region Styling and default values loading //first check for Style attribute then trigger default value loading if (reader.HasAttributes) { @@ -464,7 +480,7 @@ namespace Crow.IML if (mi.MemberType == MemberTypes.Event) { foreach (string exp in CompilerServices.splitOnSemiColumnOutsideAccolades(reader.Value)) { string trimed = exp.Trim(); - if (trimed.StartsWith ("{", StringComparison.OrdinalIgnoreCase)) + if (trimed.StartsWith ("{", StringComparison.Ordinal)) compileAndStoreDynHandler (ctx, mi as EventInfo, trimed.Substring (1, trimed.Length - 2)); else emitHandlerBinding (ctx, mi as EventInfo, trimed); @@ -479,7 +495,7 @@ namespace Crow.IML if (pi.Name == "Name") ctx.StoreCurrentName (reader.Value); - if (reader.Value.StartsWith ("{", StringComparison.OrdinalIgnoreCase)) + if (reader.Value.StartsWith ("{", StringComparison.Ordinal)) readPropertyBinding (ctx, reader.Name, reader.Value.Substring (1, reader.Value.Length - 2)); else CompilerServices.EmitSetValue (ctx.il, pi, reader.Value); @@ -548,7 +564,12 @@ namespace Crow.IML } } #endregion - + /// + /// Reads binding expression found as attribute value in iml + /// + /// IML Context + /// IML Attribute name + /// Binding Expression with accollades trimed void readPropertyBinding (IMLContext ctx, string sourceMember, string expression) { NodeAddress sourceNA = ctx.CurrentNodeAddress; @@ -707,7 +728,7 @@ namespace Crow.IML System.Reflection.Emit.Label endMethod = il.DefineLabel (); - il.DeclareLocal (CompilerServices.TObject); + il.DeclareLocal (typeof(object)); il.Emit (OpCodes.Nop); @@ -814,8 +835,8 @@ namespace Crow.IML System.Reflection.Emit.Label endMethod = il.DefineLabel (); - il.DeclareLocal (CompilerServices.TObject); - ilPC.DeclareLocal (CompilerServices.TObject);//used for checking propery less bindings + il.DeclareLocal (typeof(object)); + ilPC.DeclareLocal (typeof(object));//used for checking propery less bindings ilPC.DeclareLocal (typeof(MemberInfo));//used for checking propery less bindings System.Reflection.Emit.Label cancel = ilPC.DefineLabel (); @@ -970,7 +991,7 @@ namespace Crow.IML System.Reflection.Emit.Label endMethod = il.DefineLabel (); - il.DeclareLocal (CompilerServices.TObject); + il.DeclareLocal (typeof(object)); il.Emit (OpCodes.Nop); @@ -993,7 +1014,6 @@ namespace Crow.IML //by default, source value type is deducted from target member type to allow //memberless binding, if targetMember exists, it will be used to determine target //value type for conversion - CompilerServices.emitConvert (il, piSource.PropertyType); if (!piSource.CanWrite) @@ -1022,7 +1042,7 @@ namespace Crow.IML il = dm.GetILGenerator (256); - il.DeclareLocal (CompilerServices.TObject);//used for checking propery less bindings + il.DeclareLocal (typeof(object));//used for checking propery less bindings il.DeclareLocal (typeof(MemberInfo));//used for checking propery less bindings System.Reflection.Emit.Label cancel = il.DefineLabel (); System.Reflection.Emit.Label newDSIsNull = il.DefineLabel (); @@ -1148,7 +1168,7 @@ namespace Crow.IML System.Reflection.Emit.Label endMethod = il.DefineLabel (); - il.DeclareLocal (CompilerServices.TObject); + il.DeclareLocal (typeof(object)); il.Emit (OpCodes.Nop); //load value changed member name onto the stack diff --git a/Crow/src/Interface.cs b/Crow/src/Interface.cs index 621d5549..f4743402 100644 --- a/Crow/src/Interface.cs +++ b/Crow/src/Interface.cs @@ -462,12 +462,12 @@ namespace Crow { Stream stream = null; - if (path.StartsWith ("#")) { + if (path.StartsWith ("#", StringComparison.Ordinal)) { string resId = path.Substring (1); //try/catch added to prevent nunit error try { stream = System.Reflection.Assembly.GetEntryAssembly ().GetManifestResourceStream (resId); - } catch{} + } catch {} if (stream == null)//try to find ressource in Crow assembly stream = System.Reflection.Assembly.GetExecutingAssembly ().GetManifestResourceStream (resId); if (stream == null) @@ -483,7 +483,7 @@ namespace Crow { Stream stream = null; - if (path.StartsWith ("#")) { + if (path.StartsWith ("#", StringComparison.Ordinal)) { string resId = path.Substring (1); //try/catch added to prevent nunit error try { diff --git a/Crow/src/ItemTemplate.cs b/Crow/src/ItemTemplate.cs index e42c7540..a12823cc 100644 --- a/Crow/src/ItemTemplate.cs +++ b/Crow/src/ItemTemplate.cs @@ -151,7 +151,7 @@ namespace Crow ParameterInfo [] evtParams = evtInvoke.GetParameters (); Type handlerArgsType = evtParams [1].ParameterType; - Type [] args = { CompilerServices.TObject, CompilerServices.TObject, handlerArgsType }; + Type [] args = { typeof(object), typeof(object), handlerArgsType }; #region Expand dyn meth //DM is bound to templatedGroup root (arg0) @@ -222,7 +222,7 @@ namespace Crow #region Items counting dyn method //dm is unbound, arg0 is instance of Item container to expand dm = new DynamicMethod ("dyn_count_" + fetchMethodName, - typeof (bool), new Type[] {CompilerServices.TObject}, true); + typeof (bool), new Type[] {typeof(object)}, true); il = dm.GetILGenerator (256); //get the dataSource of the arg0 diff --git a/Crow/src/Size.cs b/Crow/src/Size.cs index 891c1fb5..4d0bcb58 100644 --- a/Crow/src/Size.cs +++ b/Crow/src/Size.cs @@ -33,7 +33,6 @@ namespace Crow { public struct Size { - internal static Type TSize = typeof(Size); public static Size Zero { get { return new Size(0, 0); } } @@ -186,7 +185,7 @@ namespace Crow } public override bool Equals (object obj) { - return (obj == null || obj.GetType() != TSize) ? + return (obj == null || obj.GetType() != typeof(Size)) ? false : this == (Size)obj; } diff --git a/CrowIDE/src/Editors/Parsers/CSharpParser.cs b/CrowIDE/src/Editors/Parsers/CSharpParser.cs index 11e72598..23655aa6 100644 --- a/CrowIDE/src/Editors/Parsers/CSharpParser.cs +++ b/CrowIDE/src/Editors/Parsers/CSharpParser.cs @@ -358,9 +358,9 @@ namespace Crow.Coding closeNodeAndGoUp (ref currentNode, cl); break; case TokenType.Preprocessor: - if (cl.Tokens [tokPtr].Content.StartsWith ("#region")) { + if (cl.Tokens [tokPtr].Content.StartsWith ("#region", StringComparison.Ordinal)) { currentNode = addChildNode (currentNode, cl, tokPtr, "region"); - } else if (cl.Tokens [tokPtr].Content.StartsWith ("#endregion")) { + } else if (cl.Tokens [tokPtr].Content.StartsWith ("#endregion", StringComparison.Ordinal)) { closeNodeAndGoUp (ref currentNode, cl,"region"); } diff --git a/CrowIDE/src/Project.cs b/CrowIDE/src/Project.cs index 407f60b3..3b406367 100644 --- a/CrowIDE/src/Project.cs +++ b/CrowIDE/src/Project.cs @@ -427,7 +427,7 @@ namespace Crow.Coding { return pi != null; } public bool TryGetProjectFileFromPath (string path, out ProjectFile pi) { - if (path.StartsWith ("#")) + if (path.StartsWith ("#", StringComparison.Ordinal)) pi = flattenNodes.OfType ().FirstOrDefault (pp => pp.Type == ItemType.EmbeddedResource && pp.ResourceID == path.Substring (1)); else diff --git a/Tests/keysyms.cs b/Tests/keysyms.cs index e33add92..412d06b1 100644 --- a/Tests/keysyms.cs +++ b/Tests/keysyms.cs @@ -48,16 +48,16 @@ namespace Tests while (!r.EndOfStream) { string s = r.ReadLine ().Trim(); if (skip) { - if (s.EndsWith ("*/")) + if (s.EndsWith ("*/", StringComparison.Ordinal)) skip = false; continue; } - if (s.StartsWith ("/*")) { - if (!s.EndsWith ("*/")) + if (s.StartsWith ("/*", StringComparison.Ordinal)) { + if (!s.EndsWith ("*/", StringComparison.Ordinal)) skip = true; continue; } - if (!s.StartsWith ("#define")) + if (!s.StartsWith ("#define", StringComparison.Ordinal)) continue; string[] tmp = s.Split (new char[] {' ', '\t'}, StringSplitOptions.RemoveEmptyEntries); -- 2.47.3