System.Array.GetValue(int)

Here are the examples of the csharp api System.Array.GetValue(int) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

773 Examples 7

19 Source : ModelBindingHelper.cs
with MIT License
from DevZest

private static object UnwrapPossibleArrayType(object value, Type destinationType, CultureInfo culture)
        {
            // array conversion results in four cases, as below
            var valueAsArray = value as Array;
            if (destinationType.IsArray)
            {
                var destinationElementType = destinationType.GetElementType();
                if (valueAsArray != null)
                {
                    // case 1: both destination + source type are arrays, so convert each element
                    var converted = (IList)Array.CreateInstance(destinationElementType, valueAsArray.Length);
                    for (var i = 0; i < valueAsArray.Length; i++)
                    {
                        converted[i] = ConvertSimpleType(valueAsArray.GetValue(i), destinationElementType, culture);
                    }
                    return converted;
                }
                else
                {
                    // case 2: destination type is array but source is single element, so wrap element in
                    // array + convert
                    var element = ConvertSimpleType(value, destinationElementType, culture);
                    var converted = (IList)Array.CreateInstance(destinationElementType, 1);
                    converted[0] = element;
                    return converted;
                }
            }
            else if (valueAsArray != null)
            {
                // case 3: destination type is single element but source is array, so extract first element + convert
                if (valueAsArray.Length > 0)
                {
                    value = valueAsArray.GetValue(0);
                    return ConvertSimpleType(value, destinationType, culture);
                }
                else
                {
                    // case 3(a): source is empty array, so can't perform conversion
                    return null;
                }
            }

            // case 4: both destination + source type are single elements, so convert
            return ConvertSimpleType(value, destinationType, culture);
        }

19 Source : FolderDragDropHelper.cs
with GNU General Public License v3.0
from DineshSolanki

private static void Control_DragOver(object sender, DragEventArgs e)
        {
            var dt = e.Data.GetData(DataFormats.FileDrop);
            var data = (dt as Array)?.GetValue(0)?.ToString();

            e.Effects = Directory.Exists(data) ? DragDropEffects.Link : DragDropEffects.None;
            e.Handled = true;
        }

19 Source : CustomIconControlViewModel.cs
with GNU General Public License v3.0
from DineshSolanki

public void OnFileDrop(string[] filePaths, string senderName)
        {
            switch (senderName)
            {
                case "FolderButton":
                case "FoldersList":
                    SelectedDirectory = filePaths.GetValue(0)?.ToString();
                    break;
                case "IconButton":
                case "IconsList":
                    SelectedIconsDirectory = filePaths.GetValue(0)?.ToString();
                    break;
            }
        }

19 Source : MainWindowViewModel.cs
with GNU General Public License v3.0
from DineshSolanki

public void OnFileDrop(string[] filePaths, string senderName)
        {
            SelectedFolder = filePaths.GetValue(0)?.ToString();
            StatusBarProperties.ResetData();
            IsMakeEnabled = true;
        }

19 Source : OracleValueConverter.cs
with MIT License
from DIPSAS

private static T ConvertArray<T>(object value)
        {
            var nullableType = Nullable.GetUnderlyingType(typeof(T));
            var arr = (Array)value;


            if (typeof(T) == typeof(DateTime[]))
            {
                var dateArray = new DateTime[arr.Length];
                for (int i = 0; i < arr.Length; i++)
                {
                    var oraDate = arr.GetValue(i);
                    var date = (DateTime)oraDate.GetType().GetProperty("Value").GetValue(oraDate, null);
                    dateArray[i] = date;
                }
                return (T)System.Convert.ChangeType(dateArray, nullableType ?? typeof(T));
            }

            if (typeof(T) == typeof(DateTime?[]))
            {
                var dateArray = new DateTime?[arr.Length];
                for (int i = 0; i < arr.Length; i++)
                {
                    var oraDate = arr.GetValue(i);
                    dateArray[i] = null;

                    if (oraDate != null)
                    {
                        var isOraDateValNull = (bool)oraDate?.GetType()?.GetProperty("IsNull")?.GetValue(oraDate, null);
                        if(!isOraDateValNull)
                        {
                            dateArray[i] = (DateTime?)oraDate?.GetType()?.GetProperty("Value")?.GetValue(oraDate, null);
                        }
                    }
                }
                return (T)System.Convert.ChangeType(dateArray, nullableType ?? typeof(T));
            }

            switch (typeof(T).FullName)
            {
                case "Oracle.ManagedDataAccess.Types.OracleString[]":
                case "System.Byte[]":
                    return (T)System.Convert.ChangeType(value, nullableType ?? typeof(T));

                case "System.Int16[]":
                    var shortArray = new short[arr.Length];
                    for (int i = 0; i < arr.Length; i++)
                    {
                        shortArray[i] = short.Parse(arr.GetValue(i)?.ToString());
                    }
                    return (T)System.Convert.ChangeType(shortArray, nullableType ?? typeof(T));

                case "System.Int32[]":
                    var intArray = new int[arr.Length];
                    for (int i = 0; i < arr.Length; i++)
                    {
                        intArray[i] = int.Parse(arr.GetValue(i)?.ToString());
                    }
                    return (T)System.Convert.ChangeType(intArray, nullableType ?? typeof(T));

                case "System.Int64[]":
                    var longArray = new long[arr.Length];
                    for (int i = 0; i < arr.Length; i++)
                    {
                        longArray[i] = long.Parse(arr.GetValue(i)?.ToString());
                    }
                    return (T)System.Convert.ChangeType(longArray, nullableType ?? typeof(T));

                case "System.Decimal[]":
                case "Oracle.ManagedDataAccess.Types.OracleDecimal[]":
                    var decimalArray = new decimal[arr.Length];
                    for (int i = 0; i < arr.Length; i++)
                    {
                        decimalArray[i] = decimal.Parse(arr.GetValue(i)?.ToString());
                    }
                    return (T)System.Convert.ChangeType(decimalArray, nullableType ?? typeof(T));
                case "System.Boolean[]":
                    var boolArray = new bool[arr.Length];
                    for (int i = 0; i < arr.Length; i++)
                    {
                        boolArray[i] = bool.Parse(arr.GetValue(i)?.ToString());
                    }
                    return (T)System.Convert.ChangeType(boolArray, nullableType ?? typeof(T));
                default:
                    var strArray = new string[arr.Length];
                    for (int i = 0; i < arr.Length; i++)
                    {
                        strArray[i] = arr.GetValue(i)?.ToString();
                    }
                    return (T)System.Convert.ChangeType(strArray, nullableType ?? typeof(T));
            }
        }

19 Source : SolutionDB.cs
with MIT License
from Dirkster99

public int InserreplacedemTypeEnumeration(
             string[] names
           , Array values
           , SQLiteDatabase db = null)
        {
            if (db == null)
                db = this;

            int result = 0;

            // Insert into Database
            string query = "INSERT INTO itemtype ([id],[name])VALUES(@id, @name)";

            // Write data out to database
            using (SQLiteCommand cmd = new SQLiteCommand(query, db.Connection))
            {
                // https://www.jokecamp.com/blog/make-your-sqlite-bulk-inserts-very-fast-in-c/
                using (var transaction = cmd.Connection.BeginTransaction())
                {
                    for (int i = 0; i < values.Length; i++)
                    {
                        cmd.Parameters.AddWithValue("@id", values.GetValue(i));
                        cmd.Parameters.AddWithValue("@name", names[i]);

                        result += cmd.ExecuteNonQuery();
                    }

                    transaction.Commit();
                }
            }
            return result;
        }

19 Source : AppViewModel.cs
with MIT License
from Dirkster99

private bool CompareItemTypeEnums(Dictionary<long, string> mapKeyToItem)
        {
            var names = Enum.GetNames(typeof(SolutionModelsLib.Enums.SolutionModelItemType));
            var values = Enum.GetValues(typeof(SolutionModelsLib.Enums.SolutionModelItemType));

            for (int i = 0; i < names.Length; i++)
            {
                string name;
                if (mapKeyToItem.TryGetValue((int)values.GetValue(i), out name) == false)
                    return false;

                if (name != names[i].ToString())
                    return false;
            }

            return true;
        }

19 Source : StringUtils.cs
with GNU General Public License v3.0
from Doreamonsky

public static string ToStringAdvanced(this object o) {

            if ( o == null || o.Equals(null) ) {
                return "NULL";
            }

            if ( o is string ) {
                return string.Format("\"{0}\"", (string)o);
            }

            if ( o is UnityEngine.Object ) {
                return ( o as UnityEngine.Object ).name;
            }

            var t = o.GetType();
            if ( t.RTIsSubclreplacedOf(typeof(System.Enum)) ) {
                if ( t.RTIsDefined<System.FlagsAttribute>(true) ) {
                    var value = string.Empty;
                    var cnt = 0;
                    var list = System.Enum.GetValues(t);
                    for ( var i = 1; i < list.Length; i++ ) {
                        var e = list.GetValue(i);
                        if ( ( Convert.ToInt32(e) & Convert.ToInt32(o) ) == Convert.ToInt32(e) ) {
                            cnt++;
                            if ( value == string.Empty ) {
                                value = e.ToString();
                            } else {
                                value = "Mixed...";
                            }
                        }
                    }
                    if ( cnt == 0 ) {
                        return "Nothing";
                    }
                    if ( cnt == list.Length - 1 ) {
                        return "Everything";
                    }
                    return value;
                }
            }

            return o.ToString();
        }

19 Source : Switch.cs
with GNU General Public License v3.0
from Doreamonsky

public override void OnGraphStarted() {
            if ( selectionMode == CaseSelectionMode.EnumBased ) {
                enumCasePairing = new Dictionary<int, int>();
                var enumValues = System.Enum.GetValues(enumCase.value.GetType());
                for ( var i = 0; i < enumValues.Length; i++ ) {
                    enumCasePairing[(int)enumValues.GetValue(i)] = i;
                }
            }
        }

19 Source : DemoWeatherApi.cs
with MIT License
from dotnet-ad

private static DayForecast CreateForecast(int i, DateTime date, Location location)
		{
			return new DayForecast
			{
				Identifier = $"{uniqueId++}", 
				Date = date + TimeSpan.FromDays(i),
				Condition = (Condition)conditions.GetValue(random.Next(conditions.Length)),
				MinTemperature = random.Next(5, 10),
				MaxTemperature = random.Next(11, 15),
				Location = location,
				Humidity = random.Next(0, 15),
				Pressure = random.Next(1018, 1020),
				wind = new Wind { Direction = random.Next(0, 360), Speed = random.Next(0, 30) }

			};
		}

19 Source : SvgElementInstanceList.cs
with MIT License
from dotnet-campus

public ISvgElementInstance Item(ulong index)
        {
            if (index < Length)
            {
                return (ISvgElementInstance)items.GetValue((int)index);
            }
            else return null;
        }

19 Source : ArrayExtensions.cs
with MIT License
from dotnet-toolbelt

public static List<T> ToList<T>(this Array items, Func<object, T> mapFunction)
        {
            if (items == null || mapFunction == null)
                return new List<T>();
            var col = new List<T>();
            for (int i = 0; i < items.Length; i++)
            {
                T val = mapFunction(items.GetValue(i));
                if (val != null)
                    col.Add(val);
            }
            return col;
        }

19 Source : ArrayExtensions.cs
with MIT License
from dotnet-toolbelt

public static List<T> ToList<T>(this Array items)
        {
            var list = new List<T>();
            for (int i = 0; i < items.Length; i++)
            {
                T val = (T)items.GetValue(i);
                if (val != null)
                    list.Add(val);
            }
            return list;
        }

19 Source : RandomExtensions.cs
with MIT License
from dotnet-toolbelt

public static T NextEnum<T>(this System.Random random) where T : Enum
        {
            Type type = typeof(T);
            if (type.IsEnum == false) throw new InvalidOperationException();

            var array = Enum.GetValues(type);
            var index = random.Next(array.GetLowerBound(0), array.GetUpperBound(0) + 1);
            return (T)array.GetValue(index);
        }

19 Source : TypeExtensions.cs
with MIT License
from dotnet-toolbelt

public static IDictionary<string, int> EnumToDictionary(this Type @this)
        {
            if (@this == null) throw new NullReferenceException();
            if ([email protected]) throw new InvalidCastException("object is not an Enum.");

            var names = Enum.GetNames(@this);
            var values = Enum.GetValues(@this);

            return (from i in Enumerable.Range(0, names.Length)
                    select new { Key = names[i], Value = (int)values.GetValue(i) })
                .ToDictionary(k => k.Key, k => k.Value);
        }

19 Source : MultiColumnTreeView.cs
with MIT License
from dshook

void DrawGuiForValues(
      Rect cellRect,
      Type dataType,
      ref object value,
      ref object originalValue,
      ref string editorStrValue,
      ref bool isValidValue,
      Action<object, object, SaveEditorTreeElement> setValue,
      SaveEditorTreeElement element
    ){

      var hasChanged = false;
      var funcStartingValue = value;

      if(value != null || originalValue != null){
        hasChanged =
          (value == null && originalValue != null)
          || (originalValue == null && value != null)
          || !value.Equals(originalValue);
      }

      var textFieldStyle = defaultGuiStyle;
      if(!isValidValue){
        textFieldStyle = errorGuiStyle;
      }else if(hasChanged){
        textFieldStyle = changedGuiStyle;
      }

      if(dataType == typeof(bool)){
        value = GUI.Toggle(cellRect, (bool)value, hasChanged ? "*" : "");
      }else if(dataType == typeof(string)){
        value = GUI.TextField(cellRect, (string)value, textFieldStyle);
      }else if(dataType.IsEnum){
        var enumValues = dataType.GetEnumValues();
        var enumNames = dataType.GetEnumNames();
        var _choiceIndex = Array.IndexOf(enumValues, value);
        if(_choiceIndex < 0){ _choiceIndex = 0; }

        GUILayout.BeginArea(cellRect);
        // EditorGUILayout.EnumPopup() a possibility?
        _choiceIndex = EditorGUILayout.Popup("", _choiceIndex, enumNames, hasChanged ? changeDropdownStyle : defaultDropdownStyle);
        GUILayout.EndArea();
        value = enumValues.GetValue(_choiceIndex);

      }else if(numberTypes.Contains(dataType)){

        if(editorStrValue == null){
          editorStrValue = value.ToString();
        }

        editorStrValue = GUI.TextField(cellRect, editorStrValue, textFieldStyle);

        var converter = TypeDescriptor.GetConverter(dataType);
        if (converter != null && converter.IsValid(editorStrValue)){
          value = converter.ConvertFromString(editorStrValue);
          isValidValue = true;
        }
        else{
          isValidValue = false;
        }

      }else if(dataType == typeof(BigInteger)){

        if(editorStrValue == null){
          editorStrValue = value.ToString();
        }

        editorStrValue = GUI.TextField(cellRect, editorStrValue, textFieldStyle);

        if(BigInteger.TryParse(editorStrValue, out var newInt)){
          value = newInt;
          isValidValue = true;
        }else{

          isValidValue = false;
        }

      }else{
        var label = GetCSharpRepresentation(dataType, true);
        if(value == null){
          label += " null";
        }else if(dataType.IsValueType){
          var toStr = value.ToString();
          if(!string.IsNullOrEmpty(toStr) && toStr != label){
            label += " " + toStr;
          }
        }

        GUI.Label(cellRect, label);
      }

      if(value != funcStartingValue){
        setValue(funcStartingValue, value, element);
      }
    }

19 Source : Enums.cs
with GNU General Public License v3.0
from DSorlov

internal static Enum GetArbitraryValue(System.Type enumType)
		{
			Array values = GetEnumValues(enumType);
			int pos = (int)(DateTimeUtilities.CurrentUnixMs() & int.MaxValue) % values.Length;
			return (Enum)values.GetValue(pos);
		}

19 Source : DeepCloneHelper.cs
with MIT License
from ebenso

private object DeepClone(Object objectToBeCloned)
        {
            if (objectToBeCloned == null)
            {
                return null;
            }

            Type _primaryType = objectToBeCloned.GetType();

            Console.WriteLine(_primaryType);

            // If the type of object is the value type, we will always get a new object when
            // the original object is replacedigned to another variable. So if the type of the
            // object is primitive or enum, we just return the object. We will process the
            // struct type subsequently because the struct type may contain the reference
            // fields.
            // If the string variables contain the same chars, they always refer to the same
            // string in the heap. So if the type of the object is string, we also return the
            // object.
            if (objectToBeCloned == null)
                return null;

            if (_primaryType.IsPrimitive || _primaryType.IsEnum || _primaryType == typeof(string))
            {
                return objectToBeCloned;
            }

            // if object objectToBeCloned is visited then return the copied object from dictionary
            if (_visited.ContainsKey(objectToBeCloned)) return _visited[objectToBeCloned];

            // If the type of the object is the Array, we use the CreateInstance method to get
            // a new instance of the array. We also process recursively this method in the
            // elements of the original array because the type of the element may be the reference
            // type.
            else if (_primaryType.IsArray)
            {
                Type typeElement = Type.GetType(_primaryType.FullName.Replace("[]", string.Empty));
                var array = objectToBeCloned as Array;
                Array copiedArray = Array.CreateInstance(typeElement, array.Length);
                for (int i = 0; i < array.Length; i++)
                {
                    // Get the deep clone of the element in the original array and replacedign the
                    // clone to the new array.
                    copiedArray.SetValue(DeepClone(array.GetValue(i)), i);
                }

                //adding in visited array
                _visited.Add(objectToBeCloned, copiedArray);

                return copiedArray;
            }
            // If the type of the object is clreplaced or struct, it may contain the reference fields,
            // so we use reflection and process recursively this method in the fields of the object
            // to get the deep clone of the object.
            // We use Type.IsValueType method here because there is no way to indicate directly whether
            // the Type is a struct type.
            else if (_primaryType.IsClreplaced || _primaryType.IsValueType)
            {
                object copiedObject = Activator.CreateInstance(objectToBeCloned.GetType());

                // Get all FieldInfo.
                FieldInfo[] fields = _primaryType.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
                foreach (FieldInfo field in fields)
                {
                    object fieldValue = field.GetValue(objectToBeCloned);
                    if (fieldValue != null)
                    {
                        var clonedFieldValue = DeepClone(fieldValue);
                        // Get the deep clone of the field in the original object and replacedign the
                        // clone to the field in the new object.
                        field.SetValue(copiedObject, clonedFieldValue);
                    }
                }

                //adding in visited array
                _visited.Add(objectToBeCloned, copiedObject);

                return copiedObject;
            }
            else
            {
                throw new ArgumentException("The object is unknown type");
            }
        }

19 Source : Utils.cs
with MIT License
from ebenso

private static object DeepClone(object objectToBeCloned, Type primaryType, BindingFlags binding)
        {
            if (objectToBeCloned == null)
                return null;

            if (primaryType.IsPrimitive || primaryType.IsEnum || primaryType == typeof(string))
            {
                // if the item is a string then Clone it and return it directly.
                if (primaryType == typeof(string))
                    return (objectToBeCloned as string)?.Clone();

                return objectToBeCloned;
            }

            if (primaryType.IsArray)
            {
                Type _typeElement = Type.GetType(primaryType.FullName.Replace("[]", string.Empty));
                var _array = objectToBeCloned as Array;
                Array _copiedArray = Array.CreateInstance(_typeElement, _array.Length);
                for (int i = 0; i < _array.Length; i++)
                {
                    // Get the deep clone of the element in the original array and replacedign the
                    // clone to the new array.
                    var _type = _array.GetValue(i).GetType();
                    _copiedArray.SetValue(DeepClone(_array.GetValue(i), _type, binding), i);
                }

                //return ((Array)objectToBeCloned).Clone();

                return _copiedArray;
            }

            object _tObject = objectToBeCloned as IList;

            if (_tObject != null)
            {
                var properties = primaryType.GetProperties();

                // Get the IList Type of the object
                var customList = typeof(List<>).MakeGenericType
                                 ((properties[properties.Length - 1]).PropertyType);
                _tObject = (IList)Activator.CreateInstance(customList);
                var list = (IList)_tObject;

                // loop throw each object in the list and clone it
                foreach (var item in ((IList)objectToBeCloned))
                {
                    if (item == null)
                        continue;
                    var _type = item.GetType();
                    var value = DeepClone(item, _type, binding);
                    list?.Add(value);
                }
            }
            else
            {
                // Create an empty object and ignore its construtore.
                _tObject = FormatterServices.GetUninitializedObject(primaryType);
                FieldInfo[] fields = objectToBeCloned.GetType().GetFields(binding);
                foreach (var field in fields)
                {
                    if (field.IsInitOnly) // Validate if the property is a writable one.
                        continue;
                    var value = field.GetValue(objectToBeCloned);
                    if (field.FieldType.IsClreplaced && field.FieldType != typeof(string))
                    {
                        //Type _propertyType = property.FieldType;
                        //var shellPropertyType = value.GetType();
                        //var specificShellPropertyType = shellPropertyType.MakeGenericType(_propertyType);

                        //IList LObj = Clone(value);
                        //object obj = LObj.

                        _tObject.GetType().GetField(field.Name, binding)?.SetValue
                        (_tObject, value);
                    }
                    else
                        _tObject.GetType().GetField(field.Name, binding)?.SetValue(_tObject, value);
                }
            }

            return _tObject;
        }

19 Source : MaterialGraphAsset.cs
with MIT License
from ecidevilin

public static ShaderError[] GetShaderErrors(Shader shader)
        {
            var invoke = s_GetErrorsCall.Invoke(null, new object[] { shader });
            var objects = (Array)invoke;
            var errors = new ShaderError[objects.Length];
            for (var i = 0; i < objects.Length; i++)
            {
                var obj = objects.GetValue(i);
                errors[i] = new ShaderError
                {
                    message = (string)s_ShaderErrorMessageField.GetValue(obj),
                    messageDetails = (string)s_ShaderErrorMessageDetailsField.GetValue(obj),
                    platform = (string)s_ShaderErrorPlatformField.GetValue(obj),
                    file = (string)s_ShaderErrorFileField.GetValue(obj),
                    line = (int)s_ShaderErrorLineField.GetValue(obj),
                    warning = (int)s_ShaderErrorWarningField.GetValue(obj),
                };
            }
            return errors;
        }

19 Source : Extensions.cs
with MIT License
from ecp4224

public static T RandomEnumValue<T> (params T[] exclude)
    {
        while (true)
        {
            var v = Enum.GetValues(typeof(T));
            var t = (T) v.GetValue(new Random().Next(v.Length));

            if (exclude.Contains(t))
                continue;

            return t;
        }
    }

19 Source : FaceMatcher.cs
with GNU Lesser General Public License v3.0
from Edgar077

public void UpdateModel_Joints()
        {

            for (int i = 0; i < Enum.GetValues(typeof(ModelExchangeSizes)).Length; i++)
            {
                string modelName = Enum.GetValues(typeof(ModelExchangeSizes)).GetValue(i).ToString();
                ModelExchangeSizes men = (ModelExchangeSizes)Enum.Parse(typeof(ModelExchangeSizes), modelName, true);
                float modelValue = Skeleton.ModelExchangeDictionary[men];
                Humanoid.updateWishList(modelName, modelValue);

            }



            Humanoid.UpdateModel_WishedMeasures(true);
            //Humanoid.update_character(UpdateMode.update_directly_verts);
            
        }

19 Source : _OpenGLUC.cs
with GNU Lesser General Public License v3.0
from Edgar077

private void InitComboBox()
        {
            comboBoxFill.Items.Add("Points/Lines");
            comboBoxFill.Items.Add("Fill");
            if (GLSettings.Fill)
                comboBoxFill.SelectedIndex = 1;
            else
            {
                comboBoxFill.SelectedIndex = 0;
            }


            int iPrev = -1;
            for (int i = 0; i < Enum.GetValues(typeof(PrimitiveType)).GetLength(0); i++)
            {
                string strVal = Enum.GetValues(typeof(PrimitiveType)).GetValue(i).ToString();
                int iVal = (int)Enum.GetValues(typeof(PrimitiveType)).GetValue(i);
                if (iVal != iPrev)
                    this.comboRenderMode.Items.Add(strVal);
                iPrev = iVal;
            }
        }

19 Source : _OpenGLUC.cs
with GNU Lesser General Public License v3.0
from Edgar077

private void comboViewMode_SelectedIndexChanged(object sender, EventArgs e)
        {
            string strDisplay = Enum.GetValues(typeof(PrimitiveType)).GetValue(comboRenderMode.SelectedIndex).ToString();

            GLSettings.ViewMode = strDisplay;

            this.OGLControl.GLrender.PrimitiveTypes = PrimitiveType.Points;
            for (int i = 0; i < Enum.GetValues(typeof(PrimitiveType)).GetLength(0); i++)
            {
                string strVal = Enum.GetValues(typeof(PrimitiveType)).GetValue(i).ToString();
                if (strVal == strDisplay)
                {
                    this.OGLControl.GLrender.PrimitiveTypes = (PrimitiveType)Enum.GetValues(typeof(PrimitiveType)).GetValue(i);
                    break;
                }

            }
            this.OGLControl.Invalidate();

        }

19 Source : KinectSkeleton.cs
with GNU Lesser General Public License v3.0
from Edgar077

private void InitJoints()
        {
            for (int i = 0; i < Enum.GetValues(typeof(JointType)).GetLength(0); i++)
            {

               // JointType jointType = Enum.GetValues(typeof(JointType)).GetValue(i);
                string strVal = Enum.GetValues(typeof(JointType)).GetValue(i).ToString();
                JointType jointType = (JointType)Enum.GetValues(typeof(JointType)).GetValue(i);

                Joints[jointType] = Vector3.Zero;
              
            }
        }

19 Source : PointCloudSettings.cs
with GNU Lesser General Public License v3.0
from Edgar077

private static void SetScannerType(string stringMode)
        {
            for (int i = 0; i < Enum.GetValues(typeof(ScannerType)).GetLength(0); i++)
            {
                string strVal = Enum.GetValues(typeof(ScannerType)).GetValue(i).ToString();
                if (stringMode == strVal)
                {
                    ScannerTypeDefault = (ScannerType)Enum.GetValues(typeof(ScannerType)).GetValue(i);


                }
            }

        }

19 Source : PointCloudSettings.cs
with GNU Lesser General Public License v3.0
from Edgar077

private static void SetDisplayType(string displayType)
        {
            for (int i = 0; i < Enum.GetValues(typeof(DisplayType)).GetLength(0); i++)
            {
                string strVal = Enum.GetValues(typeof(DisplayType)).GetValue(i).ToString();
                if (displayType == strVal)
                {
                    DisplayType = (DisplayType)Enum.GetValues(typeof(DisplayType)).GetValue(i);


                }
            }

        }

19 Source : PointCloudSettings.cs
with GNU Lesser General Public License v3.0
from Edgar077

private static void SetScannerMode(string stringMode)
        {
            for (int i = 0; i < Enum.GetValues(typeof(ScannerMode)).GetLength(0); i++)
            {
                string strVal = Enum.GetValues(typeof(ScannerMode)).GetValue(i).ToString();
                if (stringMode == strVal)
                {
                    ScannerMode = (ScannerMode)Enum.GetValues(typeof(ScannerMode)).GetValue(i);


                }
            }

        }

19 Source : NetSerializer.cs
with MIT License
from edornd

private StructInfo Register<T>(Type t, ulong nameHash) where T : struct
        {
            StructInfo info;
            if (_cache.TryGetValue(nameHash, out info))
            {
                return info;
            }

#if WINRT || NETCORE
            var props = t.GetRuntimeProperties();
#else
            var props = t.GetProperties(
                BindingFlags.Instance | 
                BindingFlags.Public | 
                BindingFlags.GetProperty | 
                BindingFlags.SetProperty);
#endif
            List<PropertyInfo> accepted = new List<PropertyInfo>();
            foreach(var prop in props)
            {
                if (_acceptedTypes.Contains(prop.PropertyType) ||
                   (prop.PropertyType.IsArray && _registeredCustomTypes.ContainsKey(prop.PropertyType.GetElementType())))
                {
                    accepted.Add(prop);
                }
            }
            if(accepted.Count < 0)
            {
                throw new ArgumentException("Type does not contain acceptable fields");
            }

            info = new StructInfo(accepted.Count);
            var sref = new StructReference<T>();
            info.Reference = sref;

            for(int i = 0; i < accepted.Count; i++)
            {
#if WINRT || NETCORE
                var getMethod = accepted[i].GetMethod;
                var setMethod = accepted[i].SetMethod;
#else
                var getMethod = accepted[i].GetGetMethod();
                var setMethod = accepted[i].GetSetMethod();
#endif
                var propertyType = accepted[i].PropertyType;
                if (propertyType == typeof(string))
                {
                    var setDelegate = ExtractSetDelegate<T, string>(setMethod);
                    var getDelegate = ExtractGetDelegate<T, string>(getMethod);
                    info.ReadDelegate[i] = reader => setDelegate(ref sref.Structure, reader.GetString(MaxStringLenght));
                    info.WriteDelegate[i] = writer => writer.Put(getDelegate(ref sref.Structure), MaxStringLenght);
                }
                else if (propertyType == typeof(byte))
                {
                    var setDelegate = ExtractSetDelegate<T, byte>(setMethod);
                    var getDelegate = ExtractGetDelegate<T, byte>(getMethod);
                    info.ReadDelegate[i] = reader => setDelegate(ref sref.Structure, reader.GetByte());
                    info.WriteDelegate[i] = writer => writer.Put(getDelegate(ref sref.Structure));
                }
                else if (propertyType == typeof(sbyte))
                {
                    var setDelegate = ExtractSetDelegate<T, sbyte>(setMethod);
                    var getDelegate = ExtractGetDelegate<T, sbyte>(getMethod);
                    info.ReadDelegate[i] = reader => setDelegate(ref sref.Structure, reader.GetSByte());
                    info.WriteDelegate[i] = writer => writer.Put(getDelegate(ref sref.Structure));
                }
                else if (propertyType == typeof(short))
                {
                    var setDelegate = ExtractSetDelegate<T, short>(setMethod);
                    var getDelegate = ExtractGetDelegate<T, short>(getMethod);
                    info.ReadDelegate[i] = reader => setDelegate(ref sref.Structure, reader.GetShort());
                    info.WriteDelegate[i] = writer => writer.Put(getDelegate(ref sref.Structure));
                }
                else if (propertyType == typeof(ushort))
                {
                    var setDelegate = ExtractSetDelegate<T, ushort>(setMethod);
                    var getDelegate = ExtractGetDelegate<T, ushort>(getMethod);
                    info.ReadDelegate[i] = reader => setDelegate(ref sref.Structure, reader.GetUShort());
                    info.WriteDelegate[i] = writer => writer.Put(getDelegate(ref sref.Structure));
                }
                else if (propertyType == typeof(int))
                {
                    var setDelegate = ExtractSetDelegate<T, int>(setMethod);
                    var getDelegate = ExtractGetDelegate<T, int>(getMethod);
                    info.ReadDelegate[i] = reader => setDelegate(ref sref.Structure, reader.GetInt());
                    info.WriteDelegate[i] = writer => writer.Put(getDelegate(ref sref.Structure));
                }
                else if (propertyType == typeof(uint))
                {
                    var setDelegate = ExtractSetDelegate<T, uint>(setMethod);
                    var getDelegate = ExtractGetDelegate<T, uint>(getMethod);
                    info.ReadDelegate[i] = reader => setDelegate(ref sref.Structure, reader.GetUInt());
                    info.WriteDelegate[i] = writer => writer.Put(getDelegate(ref sref.Structure));
                }
                else if (propertyType == typeof(long))
                {
                    var setDelegate = ExtractSetDelegate<T, long>(setMethod);
                    var getDelegate = ExtractGetDelegate<T, long>(getMethod);
                    info.ReadDelegate[i] = reader => setDelegate(ref sref.Structure, reader.GetLong());
                    info.WriteDelegate[i] = writer => writer.Put(getDelegate(ref sref.Structure));
                }
                else if (propertyType == typeof(ulong))
                {
                    var setDelegate = ExtractSetDelegate<T, ulong>(setMethod);
                    var getDelegate = ExtractGetDelegate<T, ulong>(getMethod);
                    info.ReadDelegate[i] = reader => setDelegate(ref sref.Structure, reader.GetULong());
                    info.WriteDelegate[i] = writer => writer.Put(getDelegate(ref sref.Structure));
                }
                else if (propertyType == typeof(float))
                {
                    var setDelegate = ExtractSetDelegate<T, float>(setMethod);
                    var getDelegate = ExtractGetDelegate<T, float>(getMethod);
                    info.ReadDelegate[i] = reader => setDelegate(ref sref.Structure, reader.GetFloat());
                    info.WriteDelegate[i] = writer => writer.Put(getDelegate(ref sref.Structure));
                }
                else if (propertyType == typeof(double))
                {
                    var setDelegate = ExtractSetDelegate<T, double>(setMethod);
                    var getDelegate = ExtractGetDelegate<T, double>(getMethod);
                    info.ReadDelegate[i] = reader => setDelegate(ref sref.Structure, reader.GetDouble());
                    info.WriteDelegate[i] = writer => writer.Put(getDelegate(ref sref.Structure));
                }
                // Array types
                else if (propertyType == typeof(string[]))
                {
                    var setDelegate = ExtractSetDelegate<T, string[]>(setMethod);
                    var getDelegate = ExtractGetDelegate<T, string[]>(getMethod);
                    info.ReadDelegate[i] = reader => setDelegate(ref sref.Structure, reader.GetStringArray(MaxStringLenght));
                    info.WriteDelegate[i] = writer => writer.Put(getDelegate(ref sref.Structure), MaxStringLenght);
                }
                else if (propertyType == typeof(byte[]))
                {
                    var setDelegate = ExtractSetDelegate<T, byte[]>(setMethod);
                    var getDelegate = ExtractGetDelegate<T, byte[]>(getMethod);
                    info.ReadDelegate[i] = reader => setDelegate(ref sref.Structure, reader.GetBytes());
                    info.WriteDelegate[i] = writer => writer.Put(getDelegate(ref sref.Structure));
                }
                else if (propertyType == typeof(short[]))
                {
                    var setDelegate = ExtractSetDelegate<T, short[]>(setMethod);
                    var getDelegate = ExtractGetDelegate<T, short[]>(getMethod);
                    info.ReadDelegate[i] = reader => setDelegate(ref sref.Structure, reader.GetShortArray());
                    info.WriteDelegate[i] = writer => writer.Put(getDelegate(ref sref.Structure));
                }
                else if (propertyType == typeof(ushort[]))
                {
                    var setDelegate = ExtractSetDelegate<T, ushort[]>(setMethod);
                    var getDelegate = ExtractGetDelegate<T, ushort[]>(getMethod);
                    info.ReadDelegate[i] = reader => setDelegate(ref sref.Structure, reader.GetUShortArray());
                    info.WriteDelegate[i] = writer => writer.Put(getDelegate(ref sref.Structure));
                }
                else if (propertyType == typeof(int[]))
                {
                    var setDelegate = ExtractSetDelegate<T, int[]>(setMethod);
                    var getDelegate = ExtractGetDelegate<T, int[]>(getMethod);
                    info.ReadDelegate[i] = reader => setDelegate(ref sref.Structure, reader.GetIntArray());
                    info.WriteDelegate[i] = writer => writer.Put(getDelegate(ref sref.Structure));
                }
                else if (propertyType == typeof(uint[]))
                {
                    var setDelegate = ExtractSetDelegate<T, uint[]>(setMethod);
                    var getDelegate = ExtractGetDelegate<T, uint[]>(getMethod);
                    info.ReadDelegate[i] = reader => setDelegate(ref sref.Structure, reader.GetUIntArray());
                    info.WriteDelegate[i] = writer => writer.Put(getDelegate(ref sref.Structure));
                }
                else if (propertyType == typeof(long[]))
                {
                    var setDelegate = ExtractSetDelegate<T, long[]>(setMethod);
                    var getDelegate = ExtractGetDelegate<T, long[]>(getMethod);
                    info.ReadDelegate[i] = reader => setDelegate(ref sref.Structure, reader.GetLongArray());
                    info.WriteDelegate[i] = writer => writer.Put(getDelegate(ref sref.Structure));
                }
                else if (propertyType == typeof(ulong[]))
                {
                    var setDelegate = ExtractSetDelegate<T, ulong[]>(setMethod);
                    var getDelegate = ExtractGetDelegate<T, ulong[]>(getMethod);
                    info.ReadDelegate[i] = reader => setDelegate(ref sref.Structure, reader.GetULongArray());
                    info.WriteDelegate[i] = writer => writer.Put(getDelegate(ref sref.Structure));
                }
                else if (propertyType == typeof(float[]))
                {
                    var setDelegate = ExtractSetDelegate<T, float[]>(setMethod);
                    var getDelegate = ExtractGetDelegate<T, float[]>(getMethod);
                    info.ReadDelegate[i] = reader => setDelegate(ref sref.Structure, reader.GetFloatArray());
                    info.WriteDelegate[i] = writer => writer.Put(getDelegate(ref sref.Structure));
                }
                else if (propertyType == typeof(double[]))
                {
                    var setDelegate = ExtractSetDelegate<T, double[]>(setMethod);
                    var getDelegate = ExtractGetDelegate<T, double[]>(getMethod);
                    info.ReadDelegate[i] = reader => setDelegate(ref sref.Structure, reader.GetDoubleArray());
                    info.WriteDelegate[i] = writer => writer.Put(getDelegate(ref sref.Structure));
                }
                else
                {
                    RWDelegates registeredCustomType;
                    PropertyInfo property = accepted[i];
                    Type arrayType = null;
                    if (propertyType.IsArray)
                    {
                        arrayType = propertyType;
                        propertyType = arrayType.GetElementType();
                    }

                    if (_registeredCustomTypes.TryGetValue(propertyType, out registeredCustomType))
                    {
                        if (arrayType != null) //Array type serialize/deserialize
                        {
                            info.ReadDelegate[i] = reader =>
                            { 
                                ushort arrLength = reader.GetUShort();
                                Array arr = Array.CreateInstance(propertyType, arrLength);
                                for (int k = 0; k < arrLength; k++)
                                {
                                    arr.SetValue(registeredCustomType.ReadDelegate(reader), k);
                                }

                                object boxedStruct = sref.Structure;
                                property.SetValue(boxedStruct, arr, null);
                                sref.Structure = (T)boxedStruct;
                            };

                            info.WriteDelegate[i] = writer =>
                            {
                                Array arr = (Array)property.GetValue(sref.Structure, null);
                                writer.Put((ushort)arr.Length);
                                for (int k = 0; k < arr.Length; k++)
                                {
                                    registeredCustomType.WriteDelegate(writer, arr.GetValue(k));
                                }
                            };
                        }
                        else //Simple
                        {
                            info.ReadDelegate[i] = reader =>
                            {
                                object boxedStruct = sref.Structure;
                                property.SetValue(boxedStruct, registeredCustomType.ReadDelegate(reader), null);
                                sref.Structure = (T)boxedStruct;
                            };

                            info.WriteDelegate[i] = writer =>
                            {
                                registeredCustomType.WriteDelegate(writer, property.GetValue(sref.Structure, null));
                            };
                        }

                    }
                    else
                    {
                        throw new ArgumentException("Unregistered argument type: " + propertyType);
                    }
                }
            }
            _cache.Add(nameHash, info);

            return info;
        }

19 Source : AIUtility.cs
with BSD 3-Clause "New" or "Revised" License
from edouardlicn

public static CampType[] GetCamps(CampType camp, RelationType relation)
        {
            KeyValuePair<CampType, RelationType> key = new KeyValuePair<CampType, RelationType>(camp, relation);
            CampType[] result = null;
            if (s_CampAndRelationToCamps.TryGetValue(key, out result))
            {
                return result;
            }

            List<CampType> camps = new List<CampType>();
            Array campTypes = Enum.GetValues(typeof(CampType));
            for (int i = 0; i < campTypes.Length; i++)
            {
                CampType campType = (CampType)campTypes.GetValue(i);
                if (GetRelation(camp, campType) == relation)
                {
                    camps.Add(campType);
                }
            }

            result = camps.ToArray();
            s_CampAndRelationToCamps[key] = result;

            return result;
        }

19 Source : IdeUtils.cs
with MIT License
from EgorBo

public static Project GetActiveProject(this DTE dte)
        {
            var activeSolutionProjects = dte.ActiveSolutionProjects as Array;
            if (activeSolutionProjects != null && activeSolutionProjects.Length > 0)
                return activeSolutionProjects.GetValue(0) as Project;
            return null;
        }

19 Source : COMAddin.cs
with Mozilla Public License 2.0
from ehsan2022002

void NetOffice.Tools.Native.IDTExtensibility2.OnConnection(object application, ext_ConnectMode ConnectMode, object AddInInst, ref Array custom)
        {
            try
            {
                if (AttributeReflector.GetTweakAttribute(Type).Enabled == true)
                {
                    string registryEndPoint = TryDetectHostRegistryKey(Application);
                    if (null != registryEndPoint)
                        Tweaks.ApplyTweaks(Factory, this, Type, registryEndPoint, IsLoadedFromSystem);
                }

                if (custom.Length > 0)
                {
                    object firstCustomItem = custom.GetValue(1);
                    string tryString = null != firstCustomItem ? firstCustomItem.ToString() : String.Empty;
                    System.Int32.TryParse(tryString, out _automationCode);
                }

                this.Application = Factory.CreateObjectFromComProxy(null, application, true);
                Utils = OnCreateUtils();
                TryCreateCustomObject(AddInInst);
                RaiseOnConnection(Application, ConnectMode, AddInInst, ref custom);
            }
            catch (NetRuntimeSystem.Exception exception)
            {
                NetOffice.DebugConsole.Default.WriteException(exception);
                OnError(ErrorMethodKind.OnConnection, exception);
            }
        }

19 Source : COMAddin.cs
with Mozilla Public License 2.0
from ehsan2022002

void NetOffice.Tools.Native.IDTExtensibility2.OnConnection(object application, ext_ConnectMode ConnectMode, object AddInInst, ref Array custom)
        {
            try
            {
                if (null != custom && custom.Length > 0)
                {
                    object firstCustomItem = custom.GetValue(1);
                    string tryString = null != firstCustomItem ? firstCustomItem.ToString() : String.Empty;
                    NetRuntimeSystem.Int32.TryParse(tryString, out _automationCode);
                }

                this.Application = new Outlook.Application(Factory, null, application);
                Utils = OnCreateUtils();
                TryCreateCustomObject(AddInInst);
                RaiseOnConnection(this.Application, ConnectMode, AddInInst, ref custom);
            }
            catch (NetRuntimeSystem.Exception exception)
            {
                NetOffice.DebugConsole.Default.WriteException(exception);
                OnError(ErrorMethodKind.OnConnection, exception);
            }
        }

19 Source : COMAddin.cs
with Mozilla Public License 2.0
from ehsan2022002

void NetOffice.Tools.Native.IDTExtensibility2.OnConnection(object application, ext_ConnectMode ConnectMode, object AddInInst, ref Array custom)
        {
            try
            {
                if (null != custom && custom.Length > 0)
                {
                    object firstCustomItem = custom.GetValue(1);
                    string tryString = null != firstCustomItem ? firstCustomItem.ToString() : String.Empty;
                    System.Int32.TryParse(tryString, out _automationCode);
                }

                this.Application = new VBE(null, application);
                TryCreateCustomObject(AddInInst);
                RaiseOnConnection(this.Application, ConnectMode, AddInInst, ref custom);
            }
            catch (System.Exception exception)
            {
                Factory.Console.WriteException(exception);
                OnError(ErrorMethodKind.OnConnection, exception);
            }
        }

19 Source : COMAddin.cs
with Mozilla Public License 2.0
from ehsan2022002

void NetOffice.Tools.Native.IDTExtensibility2.OnConnection(object application, ext_ConnectMode ConnectMode, object AddInInst, ref Array custom)
        {
            try
            {
                if (null != custom && custom.Length > 0)
                {
                    object firstCustomItem = custom.GetValue(1);
                    string tryString = null != firstCustomItem ? firstCustomItem.ToString() : String.Empty;
                    NetRuntimeSystem.Int32.TryParse(tryString, out _automationCode);
                }

                this.Application = new Word.Application(Factory, null, application);
                Utils = OnCreateUtils();
                TryCreateCustomObject(AddInInst);
                RaiseOnConnection(this.Application, ConnectMode, AddInInst, ref custom);
            }
            catch (NetRuntimeSystem.Exception exception)
            {
                NetOffice.DebugConsole.Default.WriteException(exception);
                OnError(ErrorMethodKind.OnConnection, exception);
            }
        }

19 Source : Cache.cs
with Mozilla Public License 2.0
from ehsan2022002

public void PutAll(IDictionary source)
        {
            var keys = new object[source.Keys.Count];
            var values = new object[source.Values.Count];

            source.Keys.CopyTo(keys, 0);
            source.Values.CopyTo(values, 0);

            for (int index = 0; index < source.Keys.Count; index++)
            {
                mMap[keys.GetValue(index)] = values.GetValue(index);
            }
        }

19 Source : Extentions_BinaryWriter.cs
with Apache License 2.0
from Eightvo

public static void WritePrimative(this BinaryWriter wtr, object o)
        {
            //The only nullable object that should be preplaceded to this function is a string

            if (o == null)
                o = String.Empty;
            if (o.GetType() == typeof(bool))
            {
                wtr.Write((bool)o);
                return;
            }

            if (o.GetType() == typeof(byte))
            {
                wtr.Write((byte)o);
                return;
            }

            if (o.GetType() == typeof(Char))
            {
                wtr.Write((char)o);
                return;
            }

            if (o.GetType() == typeof(short))
            {
                wtr.Write((short)o);
                return;
            }

            if (o.GetType() == typeof(ushort))
            {
                wtr.Write((ushort)o);
                return;
            }

            if (o.GetType() == typeof(int))
            {
                wtr.Write((int)o);
                return;
            }

            if (o.GetType() == typeof(uint))
            {
                wtr.Write((uint)o);
                return;
            }

            if (o.GetType() == typeof(long))
            {
                wtr.Write((long)o);
                return;
            }

            if (o.GetType() == typeof(ulong))
            {
                wtr.Write((ulong)o);
                return;
            }

            if (o.GetType() == typeof(String))
            {
                wtr.Write((String)o);
                return;
            }

            if (o.GetType() == typeof(Decimal))
            {
                wtr.Write((Decimal)o);
                return;
            }
            if (o.GetType() == typeof(Double))
            {
                wtr.Write((double)o);
                return;
            }
            if (o.GetType() == typeof(float))
            {
                wtr.Write((float)o);
                return;
            }

            if (o.GetType() == typeof(Vector2))
            {
                wtr.WriteVector2((Vector2)o);
                return;
            }

            if (o.GetType() == typeof(Vector3))
            {
                wtr.WriteVector3((Vector3)o);
                return;
            }

            if (o.GetType()==typeof(Vector4))
            {
                wtr.WriteVector4((Vector4)o);
                return;
            }
            if (o.GetType()==typeof(RectangleF))
            {
                wtr.WriteRectangleF((RectangleF)o);
                return;
            }
            if (o.GetType() == typeof(Enum))
            {
                wtr.Write((int)o);
                return;
            }

            if (o.GetType().IsArray)
            {
                var arry = o as Array;
                wtr.Write(arry.Length);
                for (int i = 0; i < arry.Length; i++)
                    wtr.WritePrimative(arry.GetValue(i));
                return;
            }
            if (IsSameOrSubclreplaced(typeof(BareE.DataStructures.AttributeCollectionBase), o.GetType()))
            {
                WriteAttributeCollection(wtr, (AttributeCollectionBase)o);
                return;
            }
            //It is a complex time.
            foreach (var v in o.GetType().GetProperties(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance))
            {
                if (v.IsDefined(typeof(Newtonsoft.Json.JsonIgnoreAttribute), true))
                    continue;
                if (!v.CanWrite)
                    continue;
                object objVal = v.GetValue(o);
                wtr.WritePrimative(objVal);
            }
            foreach (var v in o.GetType().GetFields(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance))
            {
                if (v.IsDefined(typeof(Newtonsoft.Json.JsonIgnoreAttribute), true))
                    continue;
                object objVal = v.GetValue(o);
                wtr.WritePrimative(objVal);
            }
        }

19 Source : Validator.cs
with Apache License 2.0
from elastic

private static IEnumerable<string> GetEnumValues(Type enumType)
		{
			var values = Enum.GetValues(enumType);
			for (var i = 0; i < values.Length; i++)
			{
				var value = values.GetValue(i);
				var info = enumType.GetField(value.ToString());
				var da = info.GetCustomAttribute<EnumMemberAttribute>();
				var enumValue = da != null ? da.Value : Enum.GetName(enumType, value);
				yield return enumValue;
			}
		}

19 Source : BSelect.razor.cs
with MIT License
from Element-Blazor

private void InitilizeEnumValues(bool firsreplacedemAsValue)
        {
            valueType = typeof(TValue);
            nullable = Nullable.GetUnderlyingType(valueType);
            isClearable = nullable != null;
            valueType = nullable ?? valueType;
            var valueSet = false;
            if (valueType.IsEnum)
            {
                var names = Enum.GetNames(valueType);
                var values = Enum.GetValues(valueType);
                dict = new Dictionary<TValue, string>();
                for (int i = 0; i < names.Length; i++)
                {
                    var name = names[i];
                    if (IgnoreEnumNames.Contains(name, StringComparer.CurrentCultureIgnoreCase))
                    {
                        continue;
                    }
                    var value = values.GetValue(i);
                    var field = valueType.GetField(name);
                    var text = field.GetCustomAttributes(typeof(DescriptionAttribute), true)
                        .Cast<DescriptionAttribute>()
                        .FirstOrDefault()?.Description ?? name;
                    if (!valueSet && firsreplacedemAsValue)
                    {
                        valueSet = true;
                        if (nullable == null)
                        {
                            if (!TypeHelper.Equal(Value, (TValue)value))
                            {
                                Value = (TValue)value;
                                InitialValue = Value;
                                SetFieldValue(Value, false);
                            }
                            Label = text;
                        }
                    }
                    dict.Add((TValue)value, text);
                }
                ChildContent = builder =>
                {
                    int seq = 0;
                    foreach (var itemValue in dict.Keys)
                    {
                        builder.OpenComponent<BSelectOption<TValue>>(seq++);
                        builder.AddAttribute(seq++, "Text", dict[itemValue]);
                        builder.AddAttribute(seq++, "Value", itemValue);
                        builder.CloseComponent();
                    }
                };
            }
        }

19 Source : AIUtility.cs
with MIT License
from EllanJiang

public static CampType[] GetCamps(CampType camp, RelationType relation)
        {
            KeyValuePair<CampType, RelationType> key = new KeyValuePair<CampType, RelationType>(camp, relation);
            CampType[] result = null;
            if (s_CampAndRelationToCamps.TryGetValue(key, out result))
            {
                return result;
            }

            // TODO: GC Alloc
            List<CampType> camps = new List<CampType>();
            Array campTypes = Enum.GetValues(typeof(CampType));
            for (int i = 0; i < campTypes.Length; i++)
            {
                CampType campType = (CampType)campTypes.GetValue(i);
                if (GetRelation(camp, campType) == relation)
                {
                    camps.Add(campType);
                }
            }

            // TODO: GC Alloc
            result = camps.ToArray();
            s_CampAndRelationToCamps[key] = result;

            return result;
        }

19 Source : DataBinder.cs
with Apache License 2.0
from ElmahCore

private static object GetIndex(object obj, object index, Func<object, object, object> missingSelector)
        {
            if (obj == null) throw new ArgumentNullException(nameof(obj));
            if (index == null) throw new ArgumentNullException(nameof(index));

            var isIntegralIndex = index is int;

            if (obj is Array array && isIntegralIndex)
                return array.GetValue((int) index);

            if (obj is IList list && isIntegralIndex)
                return list[(int) index];

            var property = FindIndexerProperty(obj.GetType(), index.GetType());

            return property != null
                ? property.GetValue(obj, new[] {index})
                : missingSelector?.Invoke(obj, index);
        }

19 Source : Cloner.cs
with MIT License
from emulamer

private static void ClonePropsInObj(object curObj, replacedetsObject parentObj, Dictionary<replacedetsObject, replacedetsObject> clonedObjects, replacedetsFile toFile, List<replacedetsObject> addedObjects, List<CloneExclusion> exclusions)
        {
            var file = parentObj.ObjectInfo.ParentFile.replacedetsFilename;
            var updateProps = curObj.GetType().GetProperties().ToList();

            //remove any array properties that are a string or a value type
            updateProps.Where(x => x.PropertyType.IsArray && (x.PropertyType.GetElementType().IsValueType || x.PropertyType.GetElementType() == typeof(string)))
                .ToList().ForEach(x => updateProps.Remove(x));

            //look through any properties that are smart pointers, clone their targets and make a new pointer, then remove them from the list of props to update
            var propsToClone = updateProps.Where(x => typeof(ISmartPtr<replacedetsObject>).IsreplacedignableFrom(x.PropertyType)).ToList();
            foreach (var prop in propsToClone)
            {
                var baseVal = prop.GetValue(curObj, null);
                if (baseVal == null)
                    continue;
                var propPtr = (prop.GetValue(curObj, null) as ISmartPtr<replacedetsObject>);
                var propObj = propPtr.Target.Object;
                replacedetsObject replacedignObject = null;

                switch (exclusions.GetExclusionMode(propPtr, prop))
                {
                    case ExclusionMode.LeaveRef:
                        replacedignObject = propObj;
                        break;
                    case ExclusionMode.Remove:
                        replacedignObject = null;
                        Log.LogErr($"WARNING: Cloner is leaving the pointer NULL on property '{curObj.GetType().Name}.{prop.Name}'");
                        break;
                    default:
                        replacedignObject = DeepClone(propObj, toFile, addedObjects, clonedObjects, exclusions);
                        break;
                }
                                                             
                prop.SetValue(curObj, ReflectionHelper.MakeTypedPointer(parentObj, replacedignObject), null);
            }
            propsToClone.ForEach(x => updateProps.Remove(x));

            //look through any properties that lists of smart pointers, this code isn't ideal because it only actually supports things that have a default indexer
            //  I should clean this up to work better
            var listsToClone = updateProps.Where(x => typeof(IEnumerable<ISmartPtr<replacedetsObject>>).IsreplacedignableFrom(x.PropertyType)).ToList();
            foreach (var listProp in listsToClone)
            {
                var listVal = listProp.GetValue(curObj, null) as IEnumerable<ISmartPtr<replacedetsObject>>;

                if (listVal == null)
                    continue;
                if (listProp.PropertyType.IsArray)
                {
                    Array listArr = (Array)listVal;
                    for (int i = 0; i < listArr.Length; i++)
                    {
                        var ptrVal = listArr.GetValue(i) as ISmartPtr<replacedetsObject>;
                        ISmartPtr<replacedetsObject> clonedObj = null;
                        switch (exclusions.GetExclusionMode(ptrVal, listProp))
                        {
                            case ExclusionMode.LeaveRef:
                                clonedObj = listArr.GetValue(i) as ISmartPtr<replacedetsObject>;
                                break;
                            case ExclusionMode.Remove:
                                clonedObj = null;
                                break;
                            default:
                                clonedObj = ReflectionHelper.MakeTypedPointer(DeepClone(ptrVal.Target.Object, toFile, addedObjects, clonedObjects, exclusions), parentObj);
                                break;
                        }
                        if (clonedObj == null)
                        {
                            listArr.RemoveAt(i);
                            i--;
                        }
                        else
                        {
                            listArr.SetValue( clonedObj, i);
                        }
                    }
                }
                else
                {
                    var indexerProp = listVal.GetType().GetProperties().Where(x => x.Name == "Item").FirstOrDefault();

                    if (indexerProp == null)
                    {
                        throw new NotSupportedException($"Couldn't find the default indexer property on {curObj.GetType().Name}.{listProp.Name}!");
                    }
                    for (int i = 0; i < listVal.Count(); i++)
                    {
                        var ptrVal = indexerProp.GetValue(listVal, new object[] { i }) as ISmartPtr<replacedetsObject>;
                        replacedetsObject clonedObj = null;
                        switch (exclusions.GetExclusionMode(ptrVal, listProp))
                        {
                            case ExclusionMode.LeaveRef:
                                clonedObj = ptrVal.Target.Object;
                                break;
                            case ExclusionMode.Remove:
                                clonedObj = null;
                                break;
                            default:
                                clonedObj = DeepClone(ptrVal.Target.Object, toFile, addedObjects, clonedObjects, exclusions);
                                break;
                        }

                        //if the cloned object comes back null, remove it from the list instead of setting it null
                        if (clonedObj == null)
                        {
                            ReflectionHelper.InvokeRemoveAt(listVal, i);
                        }
                        else
                        {
                            indexerProp.SetValue(listVal, ReflectionHelper.MakeTypedPointer(parentObj as replacedetsObject, clonedObj), new object[] { i });
                        }
                    }
                }
            }
            listsToClone.ForEach(x => updateProps.Remove(x));

            //look through any objects that are plain old lists of whatever.  this is to catch lists of "structs" that may have pointers in them
            var plainEnumerableToClone = updateProps.Where(x => !x.PropertyType.IsValueType && !(x.PropertyType == typeof(string)) && typeof(IEnumerable).IsreplacedignableFrom(x.PropertyType)).ToList();
            foreach (var enumProp in plainEnumerableToClone)
            {
                var listVal = enumProp.GetValue(curObj, null) as IEnumerable;

                if (listVal == null)
                    continue;

                foreach (var plainObj in listVal)
                {
                    //preplaced in the parent replacedetsObject that was preplaceded to us since that object will be the "owner", not the struct object
                    ClonePropsInObj(plainObj, parentObj, clonedObjects, toFile, addedObjects, exclusions);
                }
            }
            plainEnumerableToClone.ForEach(x => updateProps.Remove(x));
            //look through any "struct" type properties that may have pointers in them
            var plainObjToClone = updateProps.Where(x => !x.PropertyType.IsValueType && !(x.PropertyType == typeof(string)));
            foreach (var plainProp in plainObjToClone)
            {
                var objVal = plainProp.GetValue(curObj, null) as IEnumerable;
                if (objVal == null)
                    continue;

                foreach (var plainObj in objVal)
                {
                    //preplaced in the parent replacedetsObject that was preplaceded to us since that object will be the "owner", not the struct object
                    ClonePropsInObj(plainObj, parentObj, clonedObjects, toFile, addedObjects, exclusions);
                }
            }
        }

19 Source : SurrogateGadgetGenerator.cs
with GNU General Public License v3.0
from EncodeGroup

public void GetObjectData(SerializationInfo info, StreamingContext context)
		{
			try
			{
				List<byte[]> bytes = new List<byte[]> { replacedemblyBytes };
				var d1 = bytes.Select(replacedembly.Load);
				Func<replacedembly, IEnumerable<Type>> types = (Func<replacedembly, IEnumerable<Type>>)Delegate.CreateDelegate(typeof(Func<replacedembly, IEnumerable<Type>>), typeof(replacedembly).GetMethod("GetTypes"));
				var d2 = d1.SelectMany(types);
				var d3 = d2.Select(Activator.CreateInstance);
				PagedDataSource pds = new PagedDataSource() { DataSource = d3 };
				IDictionary dictionary = (IDictionary)Activator.CreateInstance(typeof(int).replacedembly.GetType("System.Runtime.Remoting.Channels.AggregateDictionary"), pds);
				DesignerVerb dv = new DesignerVerb("", null);
				typeof(MenuCommand).GetField("properties", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(dv, dictionary);
				List<object> objects = new List<object>();
				objects.Add(d1);
				objects.Add(d2);
				objects.Add(d3);
				objects.Add(pds);
				objects.Add(dv);
				objects.Add(dictionary);
				Hashtable ht = new Hashtable();
				ht.Add(dv, "v1");
				ht.Add("p2", "v2");
				FieldInfo fiBuckets = ht.GetType().GetField("buckets", BindingFlags.NonPublic | BindingFlags.Instance);
				Array buckets = (Array)fiBuckets.GetValue(ht);
				FieldInfo fiKey = buckets.GetType().GetElementType().GetField("key", BindingFlags.Public | BindingFlags.Instance);

				for (int i = 0; i < buckets.Length; ++i)
				{
					object bucket = buckets.GetValue(i);
					object key = fiKey.GetValue(bucket);

					if (key is string)
					{
						fiKey.SetValue(bucket, dv);
						buckets.SetValue(bucket, i);
						break;
					}
				}

				fiBuckets.SetValue(ht, buckets);
				objects.Add(ht);
				info.SetType(typeof(DataSet));
				info.AddValue("DataSet.RemotingFormat", SerializationFormat.Binary);
				info.AddValue("DataSet.DataSetName", "");
				info.AddValue("DataSet.Namespace", "");
				info.AddValue("DataSet.Prefix", "");
				info.AddValue("DataSet.CaseSensitive", false);
				info.AddValue("DataSet.LocaleLCID", 0x409);
				info.AddValue("DataSet.EnforceConstraints", false);
				info.AddValue("DataSet.ExtendedProperties", null);
				info.AddValue("DataSet.Tables.Count", 1);
				BinaryFormatter bf = new BinaryFormatter();
				MemoryStream ms = new MemoryStream();
				bf.SurrogateSelector = new SurrogateSelector();
				bf.Serialize(ms, objects);
				info.AddValue("DataSet.Tables_0", ms.ToArray());
			}

			catch (Exception) { }
		}

19 Source : GetItemAtIndex.cs
with MIT License
from ENGworks-DEV

public override void Calculate()
        {
            if (InputPorts[1].Data != null || InputPorts[0].Data != null)
            {
                //TODO : Catch this one
                var count = Int32.Parse(InputPorts[1].Data.ToString());
                
                object inputs = InputPorts[0].Data ;
               
                object[] res  = ((IEnumerable)inputs).Cast<object>()
                                 
                                 .ToArray();

                if (res != null && res.Length >= count + 1)
                {
                    OutputPorts[0].Data = res.GetValue(count);

                }
            }
          
        }

19 Source : UsingTaskCollection_Tests.cs
with MIT License
from enricosada

[Test]
        public void CopyTo_WeakAndGetEnumerator()
        {
            Project p = new Project(new Engine());
            p.AddNewUsingTaskFromreplacedemblyFile("TaskName1", "replacedemblyFile1.dll");
            p.AddNewUsingTaskFromreplacedemblyFile("TaskName2", "replacedemblyFile2.dll");
            Array taskArray = Array.CreateInstance(typeof(UsingTask), p.UsingTasks.Count);
            p.UsingTasks.CopyTo(taskArray, 0);
            replacedertion.replacedertEquals(p.UsingTasks.Count, taskArray.Length);
            int i = 0;
            foreach (UsingTask usingTask in p.UsingTasks)
            {
                replacedertion.replacedertEquals(((UsingTask)taskArray.GetValue(i)), usingTask.replacedemblyFile);
                i++;
            }
        }

19 Source : SpriteNaming.cs
with MIT License
from ErikOverflow

private static void InitNamingLists()
		{
			var allNamingSchemes = Enum.GetValues(typeof(SpriteNamingScheme));

			_namingSchemesValues = new int[allNamingSchemes.Length];
			_namingSchemesDisplayValues = new string[allNamingSchemes.Length];

			for (int i = 0; i < allNamingSchemes.Length; i++)
			{
				SpriteNamingScheme namingScheme = (SpriteNamingScheme)allNamingSchemes.GetValue(i);
				_namingSchemesValues[i] = (int)namingScheme;
				_namingSchemesDisplayValues[i] = namingScheme.ToDisplayString();
			}
		}

19 Source : HitboxTriggerSpikes.cs
with MIT License
from EverestAPI

private static void Enreplacedy_DebugRender(On.Monocle.Enreplacedy.orig_DebugRender orig, Enreplacedy self, Camera camera) {
            if (!CelesteTasModule.Settings.ShowHitboxes || self is not TriggerSpikes && self is not TriggerSpikesOriginal) {
                orig(self, camera);
                return;
            }

            self.Collider?.Render(camera, HitboxColor.EnreplacedyColorInverselyLessAlpha);

            if (self is TriggerSpikes triggerSpikes) {
                Vector2 offset, value;
                bool vertical = false;
                switch (TriggerSpikesDirection(triggerSpikes)) {
                    case TriggerSpikes.Directions.Up:
                        offset = new Vector2(-2f, -4f);
                        value = new Vector2(1f, 0f);
                        break;
                    case TriggerSpikes.Directions.Down:
                        offset = new Vector2(-2f, 0f);
                        value = new Vector2(1f, 0f);
                        break;
                    case TriggerSpikes.Directions.Left:
                        offset = new Vector2(-4f, -2f);
                        value = new Vector2(0f, 1f);
                        vertical = true;
                        break;
                    case TriggerSpikes.Directions.Right:
                        offset = new Vector2(0f, -2f);
                        value = new Vector2(0f, 1f);
                        vertical = true;
                        break;
                    default:
                        return;
                }

                Array spikes = TriggerSpikesSpikes.GetValue(self) as Array;
                for (int i = 0; i < spikes.Length; i++) {
                    object spikeInfo = spikes.GetValue(i);
                    if (triggerSpikesTriggered == null) {
                        triggerSpikesTriggered = spikeInfo.GetType().GetField("Triggered", BindingFlags.Instance | BindingFlags.Public);
                    }

                    if (triggerSpikesLerp == null) {
                        triggerSpikesLerp = spikeInfo.GetType().GetField("Lerp", BindingFlags.Instance | BindingFlags.Public);
                    }

                    if ((bool) triggerSpikesTriggered.GetValue(spikeInfo) && (float) triggerSpikesLerp.GetValue(spikeInfo) >= 1f) {
                        Vector2 position = self.Position + value * (2 + i * 4) + offset;

                        int num = 1;
                        for (int j = i + 1; j < spikes.Length; j++) {
                            object nextSpikeInfo = spikes.GetValue(j);
                            if ((bool) triggerSpikesTriggered.GetValue(nextSpikeInfo) && (float) triggerSpikesLerp.GetValue(nextSpikeInfo) >= 1f) {
                                num++;
                                i++;
                            } else {
                                break;
                            }
                        }

                        Draw.HollowRect(position, 4f * (vertical ? 1 : num), 4f * (vertical ? num : 1),
                            HitboxColor.GetCustomColor(Color.Red, self));
                    }
                }
            } else if (self is TriggerSpikesOriginal triggerSpikesOriginal) {
                Vector2 offset;
                float width, height;
                bool vertical = false;
                switch (TriggerSpikesOriginalDirection(triggerSpikesOriginal)) {
                    case TriggerSpikesOriginal.Directions.Up:
                        width = 8f;
                        height = 3f;
                        offset = new Vector2(-4f, -4f);
                        break;
                    case TriggerSpikesOriginal.Directions.Down:
                        width = 8f;
                        height = 3f;
                        offset = new Vector2(-4f, 1f);
                        break;
                    case TriggerSpikesOriginal.Directions.Left:
                        width = 3f;
                        height = 8f;
                        offset = new Vector2(-4f, -4f);
                        vertical = true;
                        break;
                    case TriggerSpikesOriginal.Directions.Right:
                        width = 3f;
                        height = 8f;
                        offset = new Vector2(1f, -4f);
                        vertical = true;
                        break;
                    default:
                        return;
                }

                Array spikes = TriggerSpikesOriginalSpikes.GetValue(self) as Array;
                for (int i = 0; i < spikes.Length; i++) {
                    object spikeInfo = spikes.GetValue(i);

                    if (triggerSpikesOriginalTriggered == null) {
                        triggerSpikesOriginalTriggered = spikeInfo.GetType().GetField("Triggered", BindingFlags.Instance | BindingFlags.Public);
                    }

                    if (triggerSpikesOriginalLerp == null) {
                        triggerSpikesOriginalLerp = spikeInfo.GetType().GetField("Lerp", BindingFlags.Instance | BindingFlags.Public);
                    }

                    if (triggerSpikesOriginalPosition == null) {
                        triggerSpikesOriginalPosition = spikeInfo.GetType().GetField("Position", BindingFlags.Instance | BindingFlags.Public);
                    }

                    if ((bool) triggerSpikesOriginalTriggered.GetValue(spikeInfo) && (float) triggerSpikesOriginalLerp.GetValue(spikeInfo) >= 1) {
                        int num = 1;
                        for (int j = i + 1; j < spikes.Length; j++) {
                            object nextSpikeInfo = spikes.GetValue(j);
                            if ((bool) triggerSpikesOriginalTriggered.GetValue(nextSpikeInfo) &&
                                (float) triggerSpikesOriginalLerp.GetValue(nextSpikeInfo) >= 1) {
                                num++;
                                i++;
                            } else {
                                break;
                            }
                        }

                        Vector2 position = (Vector2) triggerSpikesOriginalPosition.GetValue(spikeInfo) + self.Position + offset;
                        Draw.HollowRect(position, width * (vertical ? 1 : num), height * (vertical ? num : 1),
                            HitboxColor.GetCustomColor(Color.Red, self));
                    }
                }
            }
        }

19 Source : ExcelHelperClass.cs
with BSD 3-Clause "New" or "Revised" License
from EvolutionJobs

public static string getNameStringfromBuiltInFunctionID(string idstring)
        {
            char firstChar = (char)idstring.ToCharArray().GetValue(0);

            switch (firstChar)
            {
                case (char)0x00: return "Consolidate_Area";
                case (char)0x01: return "Auto_Open";
                case (char)0x02: return "Auto_Close";
                case (char)0x03: return "Extract";
                case (char)0x04: return "Database";
                case (char)0x05: return "Criteria";
                case (char)0x06: return "Print_Area";
                case (char)0x07: return "Print_replacedles";
                case (char)0x08: return "Recorder";
                case (char)0x09: return "Data_Form";
                case (char)0x0A: return "Auto_Activate";
                case (char)0x0B: return "Auto_Deactivate";
                case (char)0x0C: return "Sheet_replacedle";
                case (char)0x0D: return "_FilterDatabase";


                default: return idstring;

            }
        }

19 Source : EnumExtensions.cs
with Apache License 2.0
from eXpandFramework

private static bool EnumToObject(Type type, Type underlyingType, string[] names, Array values, string input, out object value) {
            for (int i = 0; i < names.Length; i++) {
                if (string.Compare(names[i], input, StringComparison.OrdinalIgnoreCase) == 0) {
                    value = values.GetValue(i);
                    return true;
                }
            }

            if ((char.IsDigit(input[0]) || (input[0] == '-')) || (input[0] == '+')) {
                object obj = EnumToObject(underlyingType, input);
                if (obj == null) {
                    value = type.CreateInstance();
                    return false;
                }
                value = obj;
                return true;
            }

            value = type.CreateInstance();
            return false;
        }

19 Source : DefaultQuery.cs
with MIT License
from eznew-net

Expression GenerateSingleExpression(Expression parameter, Criteria criteria)
        {
            object criteriaValue = criteria.GetCriteriaRealValue();
            Expression valueExpression = Expression.Constant(criteriaValue, criteriaValue?.GetType() ?? typeof(object));
            Expression property = Expression.PropertyOrField(parameter, criteria.Name);
            switch (criteria.Operator)
            {
                case CriteriaOperator.Equal:
                case CriteriaOperator.IsNull:
                    if (criteriaValue == null && !property.Type.AllowNull())
                    {
                        property = Expression.Constant(false, typeof(bool));
                    }
                    else
                    {
                        property = Expression.Equal(property, valueExpression);
                    }
                    break;
                case CriteriaOperator.NotEqual:
                case CriteriaOperator.NotNull:
                    if (criteriaValue == null && !property.Type.AllowNull())
                    {
                        property = Expression.Constant(true, typeof(bool));
                    }
                    else
                    {
                        property = Expression.NotEqual(property, valueExpression);
                    }
                    break;
                case CriteriaOperator.GreaterThan:
                    property = Expression.GreaterThan(property, valueExpression);
                    break;
                case CriteriaOperator.GreaterThanOrEqual:
                    property = Expression.GreaterThanOrEqual(property, valueExpression);
                    break;
                case CriteriaOperator.LessThan:
                    property = Expression.LessThan(property, valueExpression);
                    break;
                case CriteriaOperator.LessThanOrEqual:
                    property = Expression.LessThanOrEqual(property, valueExpression);
                    break;
                case CriteriaOperator.BeginLike:
                    Expression beginLikeExpression = Expression.Call(property, ReflectionManager.String.StringIndexOfMethod, valueExpression);
                    property = Expression.Equal(beginLikeExpression, Expression.Constant(0));
                    break;
                case CriteriaOperator.Like:
                    Expression likeExpression = Expression.Call(property, ReflectionManager.String.StringIndexOfMethod, valueExpression);
                    property = Expression.GreaterThanOrEqual(likeExpression, Expression.Constant(0));
                    break;
                case CriteriaOperator.EndLike:
                    property = Expression.Call(property, ReflectionManager.String.EndWithMethod, valueExpression);
                    break;
                case CriteriaOperator.In:
                    Type valueType = criteriaValue.GetType();
                    if (valueType != null && valueType.GenericTypeArguments != null && valueType.GenericTypeArguments.Length > 0)
                    {
                        valueType = valueType.GenericTypeArguments[valueType.GenericTypeArguments.Length - 1];
                    }
                    else if (valueType.IsArray)
                    {
                        Array arrayValue = criteriaValue as Array;
                        if (arrayValue != null && arrayValue.Length > 0)
                        {
                            valueType = arrayValue.GetValue(0).GetType();
                        }
                        else
                        {
                            valueType = typeof(object);
                        }
                    }
                    else
                    {
                        valueType = typeof(object);
                    }
                    var inMethod = ReflectionManager.Collections.GetCollectionContainsMethod(valueType);
                    property = Expression.Call(inMethod, valueExpression, property);
                    break;
                case CriteriaOperator.NotIn:
                    Type notInValueType = criteriaValue.GetType();
                    if (notInValueType != null && notInValueType.GenericTypeArguments != null)
                    {
                        notInValueType = notInValueType.GenericTypeArguments[0];
                    }
                    else
                    {
                        notInValueType = typeof(object);
                    }
                    var notInMethod = ReflectionManager.Collections.GetCollectionContainsMethod(notInValueType);
                    property = Expression.Not(Expression.Call(notInMethod, valueExpression, property));
                    break;
                default:
                    property = null;
                    break;
            }
            if (property == null)
            {
                return null;
            }
            return property;
        }

See More Examples