public void test_linq_orderby1() { var array = new[] { "aaa", "bb", "dddd", "c" }; var r1 = string.Join(",", array.Select(i => i.Length).OrderBy(i => i).ToArray()); var r2 = string.Join(",", Linq2.From(array).Select(i => i.Length).OrderBy(i => i).ToArray()); Assert.AreEqual(r1, r2); }
private IList <String> GetVariablesNames(Expression Expression, ExpressionGroup ExpressionGroup) { #if !NET20 return(Expression. Tokens. Where(t => t.TokenType == TokenType.VARIABLE && !ExpressionGroup.Expressions.ContainsKey(t.TokenName)). Select(t => t.TokenName). ToArray()); #else return(Linq2.From(Expression.Tokens). Where(t => t.TokenType == TokenType.VARIABLE && !ExpressionGroup.Expressions.ContainsKey(t.TokenName)). Select(t => t.TokenName). ToArray()); #endif }
////////////////////////////////////////////////// public void CopyTo(Object Source, Object Dest, String[] PropertiesToOmit) { if (Source == null || Dest == null) { return; } if (unsensitive) { #if !NET20 PropertiesToOmit = PropertiesToOmit.Select(i => i.ToUpper()).ToArray(); #else PropertiesToOmit = Linq2.From(PropertiesToOmit).Select(i => i.ToUpper()).ToArray(); #endif } foreach (var property in GetPropertyinfos(Source)) { if (PropertiesToOmit != null && PropertiesToOmit.Length > 0) { if (Linq2.Contains(PropertiesToOmit, unsensitive ? property.Name.ToUpper() : property.Name)) { continue; } } if (Attribute.IsDefined(property, typeof(NoCloneAttribute))) { continue; } try { SetValue( Dest, property.Name, GetValue(Source, property.Name)); } catch { throw; } } }
public String[] GetProperties(Type Type) { if (!_cacheProperties.ContainsKey(Type)) { lock (lck) { if (!_cacheProperties.ContainsKey(Type)) { #if !NET20 _cacheProperties[Type] = Type.GetProperties().Select(p => this.unsensitive ? p.Name.ToUpper() : p.Name).ToArray(); #else _cacheProperties[Type] = Linq2.From(Type.GetProperties()).Select(p => this.unsensitive ? p.Name.ToUpper() : p.Name).ToArray(); #endif } } } return(_cacheProperties.ContainsKey(Type) ? _cacheProperties[Type] : new String[0]); }
private static ExpressionMethodResult EvaluateInlineMethod( Object Object, Object Method, IList <Object> MethodParameters, DynLanContext DynLanContext) { if (Method is OnpMethodInfo) { OnpMethodInfo methodInfo = Method as OnpMethodInfo; DynamicCallResult callResult = MyReflectionHelper.CallMethod( methodInfo.Obj, methodInfo.MethodName, CorrectParameters(MethodParameters)); if (callResult != null) { return(new ExpressionMethodResult(callResult.Value)); } } else if (Method is OnpActionMethodInfo) { OnpActionMethodInfo methodInfo = Method as OnpActionMethodInfo; if (methodInfo != null && methodInfo.Action != null) { return(new ExpressionMethodResult(methodInfo.Action(CorrectParameters(MethodParameters)))); } } else if (Method is ExpressionMethod) { ExpressionMethod onpMethod = Method as ExpressionMethod; ExpressionMethodResult result = null; if (Object is EmptyObject) { result = onpMethod. CalculateValueDelegate( DynLanContext, CorrectParameters(MethodParameters)); } else { #if !NET20 var tmp = new[] { Object }.Union(MethodParameters); #else var tmp = Linq2.From(new[] { Object }).Union(MethodParameters).ToArray(); #endif result = onpMethod. CalculateValueDelegate( DynLanContext, CorrectParameters(tmp)); } return(result == null ? new ExpressionMethodResult(null) : result); } else if (Method is ExpressionMethodInfo) { ExpressionMethodInfo onpMethodInfo = Method as ExpressionMethodInfo; ExpressionMethod onpMethod = BuildinMethods.GetByID(onpMethodInfo.ID); ExpressionMethodResult result = null; if (onpMethod == null) { return(new ExpressionMethodResult(result)); } if (Object is EmptyObject) { result = onpMethod. CalculateValueDelegate( DynLanContext, CorrectParameters(MethodParameters)); } else { #if !NET20 var tmp = new[] { Object }.Union(MethodParameters); #else var tmp = Linq2.From(new[] { Object }).Union(MethodParameters).ToArray(); #endif result = onpMethod. CalculateValueDelegate( DynLanContext, CorrectParameters(tmp)); } if (result != null) { result.Value = InternalTypeConverter.ToInner(result.Value); } return(result == null ? new ExpressionMethodResult(null) : result); } else if (Method is ExpressionExtender) { ExpressionExtender onpExtender = Method as ExpressionExtender; return(new ExpressionMethodResult( onpExtender. CalculateValueDelegate( DynLanContext, Object, MethodParameters))); } else if (Method is ExpressionExtenderInfo) { ExpressionExtenderInfo onpExtenderInfo = Method as ExpressionExtenderInfo; ExpressionExtender onpExtender = BuildinExtenders.GetByID(onpExtenderInfo.ID); if (onpExtender == null) { return(new ExpressionMethodResult(null)); } return(new ExpressionMethodResult( onpExtender. CalculateValueDelegate( DynLanContext, Object, MethodParameters))); } else if (Method is Delegate) { #if NETCE throw new NotSupportedException("Calling delegates is forbidden on wince2.0!"); #else Delegate m = Method as Delegate; DynamicCallResult callResult = MyReflectionHelper.CallMethod( m.Target, m.Method, CorrectParameters(MethodParameters)); if (callResult != null) { return(new ExpressionMethodResult(callResult.Value)); } #endif } if (Method == null) { if (Object == null) { throw new DynLanMethodNotFoundException("Cannot find a method to call"); } else { throw new DynLanMethodNotFoundException("Cannot find a method to call in object " + Object.GetType().Name + ""); } } throw new DynLanUnsupportedMethodTypeException("Unsupported method type " + Method.GetType() + "!"); }