Пример #1
0
        internal static IEnumerable <RuleFeedbackBase> CheckProblemInput(MgaFCO child)
        {
            var result = new List <RuleFeedbackBase>();
            var incomingConnections = Enumerable.Cast <IMgaConnPoint>(child.PartOfConns).Where(cp => cp.ConnRole == "dst").Select(cp => cp.Owner)
                                      .Cast <IMgaSimpleConnection>();

            if (incomingConnections.Where(conn => conn.ParentModel.ID == child.ParentModel.ID).Count() > 1)
            {
                var feedback = new GenericRuleFeedback()
                {
                    FeedbackType = FeedbackTypes.Error,
                    Message      = string.Format("ProblemInput may have only one incoming connection at the same level of hierarchy")
                };
                feedback.InvolvedObjectsByRole.Add((IMgaFCO)child);
                result.Add(feedback);
            }
            if (incomingConnections.Where(conn => conn.ParentModel.ID != child.ParentModel.ID).Count() > 1)
            {
                var feedback = new GenericRuleFeedback()
                {
                    FeedbackType = FeedbackTypes.Error,
                    Message      = string.Format("ProblemInput may have only one incoming connection from the parent ParametricExploration")
                };
                feedback.InvolvedObjectsByRole.Add((IMgaFCO)child);
                result.Add(feedback);
            }
            if (incomingConnections.Where(conn => conn.ParentModel.ID == child.ParentModel.ID).Count() == 1 &&
                incomingConnections.Where(conn => conn.ParentModel.ID == child.ParentModel.ID).First().Src.Meta.Name != typeof(CyPhy.DesignVariable).Name &&
                incomingConnections.Where(conn => conn.ParentModel.ID != child.ParentModel.ID).Count() == 1)
            {
                var feedback = new GenericRuleFeedback()
                {
                    FeedbackType = FeedbackTypes.Error,
                    Message      = string.Format("ProblemInput must be connected to a Design Variable") // TODO: if it is connected one hierarchy level up
                };
                feedback.InvolvedObjectsByRole.Add((IMgaFCO)child);
                result.Add(feedback);
            }

            if (isValidParamOrOutputName(child.Name) == false)
            {
                var feedback = new GenericRuleFeedback()
                {
                    FeedbackType = FeedbackTypes.Error,
                    Message      =
                        string.Format("Problem Input ({0}) has an invalid name. " + NAME_EXPLANATION, (object)child.Name)
                };

                feedback.InvolvedObjectsByRole.Add(child);
                result.Add(feedback);
            }

            return(result);
        }
Пример #2
0
        protected virtual void SaveBlocks(T entity, FormCollection collection)
        {
            var vm           = (dynamic)entity;
            var listToRemove = Enumerable.Cast <IBlockEntity>((IEnumerable)vm.Blocks).ToList();

            //var engine = DependencyResolver.Current.GetService<MixberryTemplateEngine>();

            foreach (var key in collection.AllKeys.Where(x => x.StartsWith("BlockId")).ToList())
            {
                var idValue      = collection[key];
                var sortValue    = collection["BlockSort" + idValue];
                var imageIdValue = collection["BlockImagesId" + idValue];
                var id           = int.Parse(idValue);
                var sort         = int.Parse(sortValue);
                var name         = collection["BlockName" + idValue];
                var alias        = collection["BlockAlias" + idValue];
                var content      = collection["BlockContent" + idValue];

                var item = listToRemove.FirstOrDefault(x => x.Id == id);
                if (item != null)
                {
                    item.Sort  = sort;
                    item.Name  = name;
                    item.Alias = alias;
                    if (item.Alias.IsNullOrEmpty())
                    {
                        item.Alias = item.Name.Transliterate();
                    }
                    item.Content = content;
                    if (!imageIdValue.IsNullOrEmpty())
                    {
                        var imageId = int.Parse(imageIdValue);
                        if (imageId != 0)
                        {
                            item.Images.Clear();
                            item.Images.Add(Repository.DataContext.Set <WebFile>().Find(imageId));
                        }
                    }
                    listToRemove.Remove(item);
                }

                collection.Remove(key);
                collection.Remove("BlockSort" + idValue);
                collection.Remove("BlockImageId" + idValue);
                collection.Remove("BlockName" + idValue);
                collection.Remove("BlockAlias" + idValue);
                collection.Remove("BlockContent" + idValue);
            }

            listToRemove.ForEach(x =>
            {
                RemoveBlock(entity, x);
            });
        }
Пример #3
0
 internal static T GetControl <T>(Control c) where T : Control
 {
     if (c == null)
     {
         return(default(T));
     }
     if (c is T)
     {
         return((T)c);
     }
     return(Enumerable.FirstOrDefault <T>(Enumerable.Select <Control, T>(Enumerable.Cast <Control>((IEnumerable)c.Controls), (Func <Control, T>)(child => Interop.GetControl <T>(child))), (Func <T, bool>)(ret => (object)ret != null)));
 }
Пример #4
0
        public void Array_System()
        {
            var _ = Enumerable.Cast <object>(this.array);

            if (EnumerateAfterwards)
            {
                foreach (var __ in _)
                {
                    ;
                }
            }
        }
Пример #5
0
        /// <summary>
        ///     Set EndTime to start of the next file of the same type where it has not yet been set explicitly.
        /// </summary>
        /// <param name="objectSequence">
        ///     Must be sorted chronologically
        /// </param>
        public static void InferEndTimeWhereNotDefinedExplicitly(List <BackupFileInfo> objectSequence)
        {
            var supportedBackupTypes = Enumerable.Cast <SupportedBackupType>(
                Enum.GetValues(typeof(SupportedBackupType)))
                                       .Where(t => t != SupportedBackupType.None);

            foreach (var tp in supportedBackupTypes)
            {
                var filesOfTheSameType = objectSequence.Where(o => o.BackupType == tp).ToList();
                BackupFileCatalog.InferEndTimeWhereNotDefinedExplicitly(filesOfTheSameType);
            }
        }
Пример #6
0
        public void Collection_System()
        {
            var _ = Enumerable.Cast <object>(this.collection);

            if (EnumerateAfterwards)
            {
                foreach (var __ in _)
                {
                    ;
                }
            }
        }
        public object[] ExecuteQuery(System.Xml.Linq.XElement xml)
        {
            Expression           e      = this.serializer.Deserialize(xml);
            MethodCallExpression m      = (MethodCallExpression)e;
            LambdaExpression     lambda = Expression.Lambda(m);
            Delegate             fn     = lambda.Compile();
            dynamic result = fn.DynamicInvoke(new object[0]);
            //dynamic array = Enumerable.ToArray(result);
            var array = Enumerable.ToArray(Enumerable.Cast <NorthwindObject>(result));

            return(array);
        }
Пример #8
0
        static FyleDb()
        {
            ParameterExpression expression;
            ParameterExpression expression2;
            ParameterExpression expression3;
            ParameterExpression expression4;

            FunkFsoInt           = new Func <KV <int, KV <int, string> >, int>(< > c.< > 9, this.<.cctor > b__53_0);
            FunkFsoIntMax        = new Func <IEnumerable <KV <int, KV <int, string> > >, int>(< > c.< > 9, this.<.cctor > b__53_1);
            FunkStrKV            = null;
            FunkFsoKV            = new Func <FileSystemInfo, int, int, KV <int, KV <int, string> > >(< > c.< > 9, this.<.cctor > b__53_2);
            FunkFsoInts          = new Func <IEnumerable <KV <int, KV <int, string> > >, IEnumerable <int> >(< > c.< > 9, this.<.cctor > b__53_3);
            FunkFsoKVs           = new Func <IEnumerable <FileSystemInfo>, int, IEnumerable <KV <int, KV <int, string> > > >(< > c.< > 9, this.<.cctor > b__53_4);
            StrFuncSplitRmvEmpty = new Func <string, Func <string, string[]> >(< > c.< > 9, this.<.cctor > b__53_6);
            Expression[] arguments = new Expression[2];
            arguments[0] = expression2 = Expression.Parameter(typeof(string[]), "strAry");
            Expression[] expressionArray2 = new Expression[] { expression = Expression.Parameter(typeof(string), "s") };
            Expression[] expressionArray3 = new Expression[1];
            Expression[] expressionArray4 = new Expression[] { expression4 = Expression.Parameter(typeof(string), "x") };
            expressionArray3[0] = Expression.Call(expression3, (MethodInfo)methodof(Func <string, string> .Invoke, Func <string, string>), expressionArray4);
            ParameterExpression[] parameters = new ParameterExpression[] { expression4 };
            arguments[1] = Expression.Lambda <Func <string, bool> >(Expression.Call(Expression.Call(expression3 = Expression.Parameter(typeof(Func <string, string>), "F"), (MethodInfo)methodof(Func <string, string> .Invoke, Func <string, string>), expressionArray2), (MethodInfo)methodof(string.Contains), expressionArray3), parameters);
            ParameterExpression[] expressionArray6 = new ParameterExpression[] { expression, expression2, expression3 };
            ExprStrAryStrAll = Expression.Lambda <Func <string, string[], Func <string, string>, bool> >(Expression.Call(null, (MethodInfo)methodof(Enumerable.All), arguments), expressionArray6);
            Expression[] expressionArray7 = new Expression[2];
            Expression[] expressionArray8 = new Expression[] { expression4 = Expression.Parameter(typeof(FileSystemInfo), "fso") };
            expressionArray7[0] = Expression.Invoke(expression3 = Expression.Parameter(typeof(Func <FileSystemInfo, string>), "f2s"), expressionArray8);
            expressionArray7[1] = expression = Expression.Parameter(typeof(string), "s");
            ParameterExpression[] expressionArray9  = new ParameterExpression[] { expression4 };
            ParameterExpression[] expressionArray10 = new ParameterExpression[] { expression };
            ParameterExpression[] expressionArray11 = new ParameterExpression[] { expression3, expression2 };
            esff       = Expression.Lambda <Func <Func <FileSystemInfo, string>, Func <string, string, bool>, Expression <Func <string, Expression <Func <FileSystemInfo, bool> > > > > >(Expression.Quote(Expression.Lambda <Func <string, Expression <Func <FileSystemInfo, bool> > > >(Expression.Quote(Expression.Lambda <Func <FileSystemInfo, bool> >(Expression.Invoke(expression2 = Expression.Parameter(typeof(Func <string, string, bool>), "ss2b"), expressionArray7), expressionArray9)), expressionArray10)), expressionArray11);
            ef         = esff.Compile().Invoke(new Func <FileSystemInfo, string>(< > c.< > 9, this.<.cctor > b__53_8), new Func <string, string, bool>(< > c.< > 9, this.<.cctor > b__53_9));
            tests010ff = new Func <Expression <Func <FileSystemInfo, string> >, Expression <Func <string, string, bool> >, string, Func <FileSystemInfo, bool> >(< > c.< > 9, this.<.cctor > b__53_10);
            Expression[]          expressionArray12 = new Expression[] { Expression.Property(expression2 = Expression.Parameter(typeof(FileSystemInfo), "x"), (MethodInfo)methodof(FileSystemInfo.get_FullName)) };
            ParameterExpression[] expressionArray13 = new ParameterExpression[] { expression2 };
            XprsnFileNm = Expression.Lambda <Func <FileSystemInfo, string> >(Expression.Call(null, (MethodInfo)methodof(Path.GetFileName), expressionArray12), expressionArray13);
            FuncFileNm  = XprsnFileNm;
            tests010f   = new Func <string, Expression <Func <string, string, bool> >, Func <FileSystemInfo, bool> >(< > c.< > 9, this.<.cctor > b__53_11);
            tests101    = new Func <string, Func <FileSystemInfo, bool> >(< > c.< > 9, this.<.cctor > b__53_12);
            tests102    = new Func <string, Func <FileSystemInfo, bool> >(< > c.< > 9, this.<.cctor > b__53_13);
            tests103    = new Func <string, Func <FileSystemInfo, bool> >(< > c.< > 9, this.<.cctor > b__53_14);
            tests104    = new Func <string, Func <FileSystemInfo, bool> >(< > c.< > 9, this.<.cctor > b__53_15);
            tests01Ary  = new Func <FileSystemInfo, bool>[] { tests101.Invoke("index"), tests102.Invoke("-"), tests103.Invoke("ml"), tests104.Invoke(@"(ht|f)tps?:\/\/") };
            Func <FileSystemInfo, bool>[] funcArray2 = new Func <FileSystemInfo, bool> [4];
            funcArray2[0] = ef.Compile().Invoke("index").Compile();
            funcArray2[1] = ef.Compile().Invoke("publishers").Compile();
            Func <FileSystemInfo, bool>[][] source = new Func <FileSystemInfo, bool>[][] { tests01Ary };
            funcArray2[2] = IsTypAndAll <FileSystemInfo>(typeof(DirectoryInfo), Enumerable.Cast <Expression <Func <FileSystemInfo, bool> > >(source)).Compile();
            Func <FileSystemInfo, bool>[][] funcArrayArray2 = new Func <FileSystemInfo, bool>[][] { tests01Ary };
            funcArray2[3] = IsTypAndAll <FileSystemInfo>(typeof(FileInfo), Enumerable.Cast <Expression <Func <FileSystemInfo, bool> > >(funcArrayArray2)).Compile();
            tests105      = funcArray2;
        }
 private List <DatabaseFile> ReadDatabaseFileList(Restore restore)
 {
     return(Enumerable.Cast <DataRow>(restore.ReadFileList(Server).Rows).Select(
                r => new DatabaseFile()
     {
         LogicalName = (string)r["LogicalName"],
         PhysicalName = (string)r["PhysicalName"],
         IsLog = "L".Equals((string)r["Type"]),
         Size = Convert.ToInt64(r["Size"]),
         UniqueId = (Guid)r["UniqueId"]
     }).ToList());
 }
Пример #10
0
        private void TryChangeWorkingProject()
        {
            IProject project = this.designerContext.ActiveProject;

            if (project == this.workingProject)
            {
                return;
            }
            this.workingProject = project;
            this.UpdateProviders(project);
            EnumerableExtensions.ForEach <UserThemeAssetProvider>(Enumerable.Cast <UserThemeAssetProvider>((IEnumerable)this.AssetProviders), (Action <UserThemeAssetProvider>)(provider => provider.OnProjectChanged(project)));
        }
Пример #11
0
        public static IEnumerable <TResult> Cast <TResult>(this IEnumerable list)
        {
#if UNITY_IOS || UNITY_ANDROID
            foreach (var e in list)
            {
                TResult c = (TResult)e;
                yield return(c);
            }
                        #else
            return(Enumerable.Cast <TResult>(list));
#endif
        }
 private static void GetChildPrivateFields(IList <MemberInfo> initialFields, Type targetType, BindingFlags bindingAttr)
 {
     if ((bindingAttr & 32) != null)
     {
         BindingFlags bindingFlags = bindingAttr.RemoveFlag(16);
         while ((targetType = targetType.get_BaseType()) != null)
         {
             IEnumerable <MemberInfo> collection = Enumerable.Cast <MemberInfo>(Enumerable.Where <FieldInfo>(targetType.GetFields(bindingFlags), (FieldInfo f) => f.get_IsPrivate()));
             initialFields.AddRange(collection);
         }
     }
 }
Пример #13
0
        public void List_System()
        {
            var _ = Enumerable.Cast <object>(this.list);

            if (EnumerateAfterwards)
            {
                foreach (var __ in _)
                {
                    ;
                }
            }
        }
Пример #14
0
        private IEnumerable GetTextAlignments(SceneNodeProperty sceneNodeProperty)
        {
            SceneNodeObjectSet sceneNodeObjectSet = sceneNodeProperty.SceneNodeObjectSet;
            bool        flag   = sceneNodeObjectSet.ProjectContext.IsCapabilitySet(PlatformCapability.SupportsJustifyAlignmentEverywhere) || sceneNodeObjectSet.ObjectTypeId == null || PlatformTypes.RichTextBox.IsAssignableFrom((ITypeId)sceneNodeObjectSet.ObjectTypeId) || sceneNodeObjectSet.IsTextRange && this.IsRichTextBoxRange(sceneNodeObjectSet);
            IEnumerable source = (IEnumerable)sceneNodeProperty.StandardValues;

            if (!flag)
            {
                source = (IEnumerable)Enumerable.Where <object>(Enumerable.Cast <object>(source), (Func <object, bool>)(standardValue => !standardValue.ToString().Equals("Justify", StringComparison.OrdinalIgnoreCase)));
            }
            return(source);
        }
Пример #15
0
        /// <summary>
        /// Resolves all requested service instances.
        /// </summary>
        /// <param name="serviceType">Type of instance requested.</param>
        /// <returns>Sequence of service instance objects.</returns>
        /// <exception cref="T:System.ArgumentNullException">
        /// Thrown if <paramref name="serviceType" /> is <see langword="null" />.
        /// </exception>
        protected override IEnumerable <object> DoGetAllInstances(Type serviceType)
        {
            if (serviceType == null)
            {
                throw new ArgumentNullException("serviceType");
            }
            Type type = typeof(IEnumerable).MakeGenericType(new Type[]
            {
                serviceType
            });

            return(Enumerable.Cast <object>((IEnumerable)ResolutionExtensions.Resolve(this._container, type)));
        }
Пример #16
0
        internal static IEnumerable <string> GetColumnNames(IDataReader data)
        {
            var columns     = new List <string>();
            var sheetSchema = data.GetSchemaTable();

            if (sheetSchema == null)
            {
                return(columns);
            }
            columns.AddRange(from DataRow row in Enumerable.Cast <DataRow>(sheetSchema.Rows)
                             select row["ColumnName"].ToString());
            return(columns);
        }
Пример #17
0
 public override void Dispose()
 {
     base.Dispose();
     Utility.ForEach <Entry>(Enumerable.Cast <Entry>(this.newEntries), delegate(Entry x) {
         x.Close();
     });
     Utility.ForEach <Entry>(Enumerable.Cast <Entry>(this.removedEntries), delegate(Entry x) {
         x.Close();
     });
     Utility.ForEach <Entry>(Enumerable.Cast <Entry>(this.modifiedEntries), delegate(Entry x) {
         x.Close();
     });
 }
Пример #18
0
 public virtual void Dispose()
 {
     if (!this.disposed)
     {
         Utility.ForEach <TVolume>(this.lazyVolumes, delegate(TVolume v) {
             v.Dispose();
         });
         Utility.ForEach <Entry>(Enumerable.Cast <Entry>(this.lazyEntries.GetLoaded()), delegate(Entry x) {
             x.Close();
         });
         this.disposed = true;
     }
 }
Пример #19
0
        public static DataTable ToDataTable2(this IEnumerable <Dictionary <string, object> > parents)
        {
            var table = new DataTable();

            foreach (var parent in parents)
            {
                var children = parent.Values
                               .OfType <IEnumerable <IDictionary <string, object> > >()
                               .ToArray();

                var length = children.Any() ? children.Length : 1;

                var parentEntries = parent.Where(x => x.Value is string)
                                    .Repeat(length)
                                    .ToLookup(x => x.Key, x => x.Value);

                var childEntries = children.SelectMany(x => x.First())
                                   .ToLookup(x => x.Key, x => x.Value);

                var allEntries = parentEntries.Concat(childEntries)
                                 .ToDictionary(x => x.Key, x => x.ToArray());

                var headers = Enumerable.Cast <DataColumn>(allEntries.Select(x => x.Key).Except(Enumerable.Cast <string>(table.Columns))).Select(x => x.ColumnName)
                              .Select(x => new DataColumn(x))
                              .ToArray();

                table.Columns.AddRange(headers);

                var addedRows = new int[length];
                for (int i = 0; i < length; i++)
                {
                    addedRows[i] = table.Rows.IndexOf(table.Rows.Add());
                }

                foreach (DataColumn col in table.Columns)
                {
                    object[] columnRows;
                    if (!allEntries.TryGetValue(col.ColumnName, out columnRows))
                    {
                        continue;
                    }

                    for (int i = 0; i < addedRows.Length; i++)
                    {
                        table.Rows[addedRows[i]][col] = columnRows[i];
                    }
                }
            }

            return(table);
        }
Пример #20
0
        private static void GetChildPrivateFields(IList <MemberInfo> initialFields, Type targetType, BindingFlags bindingAttr)
        {
            if ((bindingAttr & BindingFlags.NonPublic) == BindingFlags.Default)
            {
                return;
            }
            BindingFlags bindingAttr1 = ReflectionUtils.RemoveFlag(bindingAttr, BindingFlags.Public);

            while ((targetType = TypeExtensions.BaseType(targetType)) != null)
            {
                IEnumerable <MemberInfo> collection = Enumerable.Cast <MemberInfo>((IEnumerable)Enumerable.Where <FieldInfo>((IEnumerable <FieldInfo>)targetType.GetFields(bindingAttr1), (Func <FieldInfo, bool>)(f => f.IsPrivate)));
                CollectionUtils.AddRange <MemberInfo>(initialFields, collection);
            }
        }
        private object TraverseMember(object target, MemberTraversal member, bool isLastPathSegment)
        {
            if (target == null)
            {
                return(null);
            }

            object result = null;

            // Is Target a Collection?
            // Extract first item
            target.TryAs <IEnumerable>(collection =>
            {
                var list      = Enumerable.Cast <object>(collection);
                var newTarget = list.FirstOrDefault();
                result        = TraverseMember(newTarget, member, isLastPathSegment);
            });


            if (result == null)
            {
                // Target is a single object

                if (string.IsNullOrEmpty(member.MemberName))
                {
                    // Self
                    result = target;
                }
                else
                {
                    // Get Related Member
                    result = ReflectionHelper.GetMemberValue(target, member.MemberName);
                }

                // Is it a Collection?
                result.TryAs <IEnumerable>(collection =>
                {
                    // If not last path segment
                    // or supposed to extract item
                    bool shouldExtractItem = !isLastPathSegment || member is ExtractFromCollectionTraversal;

                    if (shouldExtractItem)
                    {
                        result = ExtractItemFromCollection(collection.Cast <object>().ToList(), member);
                    }
                });
            }

            return(result);
        }
Пример #22
0
        public void MatrixNxNConstructorFromMatrix()
        {
            var values = new int[, ]
            {
                { 1, 2 },
                { 3, 4 }
            };
            var matrix1 = new MatrixNxN <int>(values);

            Assert.AreEqual(matrix1.Zip(Enumerable.Cast <int>(matrix1), (a, b) => a == b).Count(a => !a), 0);
            var matrix2 = new MatrixNxN <int>(matrix1);

            Assert.IsTrue(matrix2.Equals(matrix1));
        }
        internal HttpContentTypeField(byte[] fieldValue)
            : base("Content-Type", (IList <byte>)fieldValue)
        {
            string @string = HttpRegex.GetString(fieldValue);
            Match  match   = HttpContentTypeField._regex.Match(@string);

            if (!match.Success)
            {
                return;
            }
            this.MediaType    = Enumerable.First <Capture>(Enumerable.Cast <Capture>((IEnumerable)match.Groups["MediaType"].Captures)).Value;
            this.MediaSubtype = Enumerable.First <Capture>(Enumerable.Cast <Capture>((IEnumerable)match.Groups["MediaSubType"].Captures)).Value;
            this.Parameters   = new HttpFieldParameters(MatchExtensions.GroupCapturesValues(match, "ParameterName"), MatchExtensions.GroupCapturesValues(match, "ParameterValue"));
        }
Пример #24
0
 void ITable.InsertAllOnSubmit(IEnumerable entities)
 {
     if (entities == null)
     {
         throw System.Data.Linq.Error.ArgumentNull("entities");
     }
     CheckReadOnly();
     Context.CheckNotInSubmitChanges();
     Context.VerifyTrackingEnabled();
     foreach (var item in Enumerable.ToList(Enumerable.Cast <object>(entities)))
     {
         ((ITable)this).InsertOnSubmit(item);
     }
 }
Пример #25
0
 public static void BindTo <TFrom, TTo>(this ObservableCollection <TFrom> from, ICollection <TTo> to) where TFrom : TTo
 {
     if (from == null)
     {
         throw new ArgumentNullException("from");
     }
     if (to == null)
     {
         throw new ArgumentNullException("to");
     }
     to.Clear();
     CollectionUtilities.AddRange <TTo>(to, Enumerable.Cast <TTo>((IEnumerable)from));
     CollectionUtilities.StartReplicatingChangesTo <TTo>((INotifyCollectionChanged)from, to, true);
 }
Пример #26
0
        protected void FillColumnsList()
        {
            lbDynamicColumns.Items.Clear();
            lbSelectCategory.Items.Clear();

            UpdateRules();

            lbDynamicColumns.Items.Add("[Built-in category]");

            lbDynamicColumns.Items.AddRange(Enumerable.Cast <object>(_views.MainForm.datasetMain.DynamicColumns.Where(x => x.Type == (int)DynamicColumnType.Category))
                                            .ToArray());

            lbDynamicColumns.SelectedIndex = 0;
        }
Пример #27
0
        public static Array Slice(this Array a,
                                  int beginIndex, int endIndex)
        {
            if (a == null || a.Length == 0)
            {
                return(a);
            }

            var e = Enumerable.Cast <object>(a);

            return(beginIndex >= 0 ?
                   e.Skip(beginIndex).ToArray() :
                   e.Skip(e.Count() - beginIndex).ToArray());
        }
Пример #28
0
 public IAttachedPropertyMetadata[] AllAttachedProperties()
 {
     if (this.cachedAllAttachedProperties == null || this.owner.platformTypesWorker.IsDirty || this.owner.projectTypesWorker.IsDirty)
     {
         List <IAttachedPropertyMetadata> list;
         lock (AttachedPropertiesMetadata.platformTypesWorkerLock)
             list = Enumerable.ToList <IAttachedPropertyMetadata>(Enumerable.Cast <IAttachedPropertyMetadata>((IEnumerable)this.owner.platformTypesWorker.properties));
         list.AddRange(Enumerable.Cast <IAttachedPropertyMetadata>((IEnumerable)this.owner.projectTypesWorker.properties));
         this.owner.platformTypesWorker.IsDirty = false;
         this.owner.projectTypesWorker.IsDirty  = false;
         this.cachedAllAttachedProperties       = list.ToArray();
     }
     return(this.cachedAllAttachedProperties);
 }
Пример #29
0
        public static void ThrowExceptionWhenNotInEnum(string paramName, object value, Type enumType)
        {
            Validators.EnsureValidParamName(paramName);
            Validators.ThrowExceptionWhenIsNull("enumType", (object)enumType);
            Type enumType1 = enumType;
            bool flag      = false;

            if (enumType.IsGenericType)
            {
                if (!enumType.Assembly.FullName.Equals(typeof(Nullable <>).Assembly.FullName) || !enumType.Namespace.Equals(typeof(Nullable <>).Namespace) || !enumType.Name.Equals(typeof(Nullable <>).Name))
                {
                    throw new ArgumentException("enumType debe ser una enumeración", "enumType");
                }
                flag      = true;
                enumType1 = Nullable.GetUnderlyingType(enumType);
            }
            if (!enumType1.IsEnum)
            {
                throw new ArgumentException("enumType debe ser una enumeración", "enumType");
            }
            if (!flag && value == null)
            {
                throw new ArgumentException("El valor de '{0}' no puedo ser nulo si el tipo no es nulable", paramName);
            }
            if (!Enumerable.Any <FlagsAttribute>(Enumerable.OfType <FlagsAttribute>((IEnumerable)enumType1.GetCustomAttributes(false))))
            {
                if (value != null && !Enum.IsDefined(enumType1, value))
                {
                    throw new ArgumentException("El valor de '{0}' no es un valor posible", paramName);
                }
            }
            else
            {
                IEnumerable <long> enumerable = Enumerable.Select <object, long>(Enumerable.Cast <object>((IEnumerable)Enum.GetValues(enumType1)), (Func <object, long>)(x => (long)Convert.ChangeType(x, typeof(long))));
                long num1 = 0;
                long num2 = (long)Convert.ChangeType(value, typeof(long));
                foreach (long num3 in enumerable)
                {
                    if ((num3 & num2) == num3)
                    {
                        num1 += num3;
                    }
                }
                if (num1 != num2)
                {
                    throw new ArgumentException("El valor de '{0}' no es un valor posible", paramName);
                }
            }
        }
Пример #30
0
 public IEnumerable <IDictionary> GetAllDictionaries()
 {
     try{
         int currentUserID = CurrentOptions.CurrentUser.UserID;
         using (var context = new DataContext())
         {
             var query = context.Users.SingleOrDefault(x => x.UserID == currentUserID);
             return(Enumerable.Cast <IDictionary>(query.Dictionaries).ToList());
         }
     }
     catch (Exception) {
         Console.WriteLine("User was not selected");
     }
     return(null);
 }