当前位置: 首页>>代码示例>>C#>>正文


C# ILGenerator.EmitGetValueFromNullableProperty方法代码示例

本文整理汇总了C#中System.Reflection.Emit.ILGenerator.EmitGetValueFromNullableProperty方法的典型用法代码示例。如果您正苦于以下问题:C# ILGenerator.EmitGetValueFromNullableProperty方法的具体用法?C# ILGenerator.EmitGetValueFromNullableProperty怎么用?C# ILGenerator.EmitGetValueFromNullableProperty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Reflection.Emit.ILGenerator的用法示例。


在下文中一共展示了ILGenerator.EmitGetValueFromNullableProperty方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GenerateFilterIl

        public override void GenerateFilterIl(ILGenerator generator, Dictionary<string, string> filterValues, PropertyInfo property)
        {
            // Note: If the user specifies both true and false, we can skip this instance

            string selection = filterValues["selection"];
            string selectionLower = selection.ToLower();

            bool selectionContainsTrue = selectionLower.Contains("true");
            bool selectionContainsFalse = selectionLower.Contains("false");
            bool selectionContainsNull = selectionLower.Contains("null");

            Label lblReturnFalse = generator.DefineLabel();
            Label lblCheckNextProperty = generator.DefineLabel();

            generator.EmitCheckHasValue(property, nullableBoolStorage); // push 1 onto the stack if property has value; 0 if it is null.
            generator.Emit(OpCodes.Pop);

            // If the filter matches null, check if the value is null.
            if (selectionContainsNull)
            {
                generator.EmitCheckHasValue(property, nullableBoolStorage);
                generator.Emit(OpCodes.Brfalse, lblCheckNextProperty);
            }
            // If the property didn't match null and has no value, return false.
            generator.EmitCheckHasValue(property, nullableBoolStorage);
            generator.Emit(OpCodes.Brfalse, lblReturnFalse);

            // From here on out, we assume the property has a value.
            if (selectionContainsTrue)
            {
                generator.EmitGetValueFromNullableProperty(property, nullableBoolStorage);
                generator.Emit(OpCodes.Brtrue, lblCheckNextProperty);
            }
            if (selectionContainsFalse)
            {
                generator.EmitGetValueFromNullableProperty(property, nullableBoolStorage);
                generator.Emit(OpCodes.Brfalse, lblCheckNextProperty);
            }

            // If we've gotten this far without finding one of the values the user passed in, the record doesn't match, so return false.
            generator.MarkLabel(lblReturnFalse);
            generator.EmitReturnFalse();

            generator.MarkLabel(lblCheckNextProperty);
        }
开发者ID:rupeshtelang,项目名称:ExpressForms,代码行数:45,代码来源:ExpressFormsFilterBool.cs

示例2: GenerateFilterIl

        public override void GenerateFilterIl(ILGenerator generator, Dictionary<string, string> filterValues, PropertyInfo property)
        {
            Label lblReturnFalse = generator.DefineLabel();
            Label lblNextProperty = generator.DefineLabel();

            string minNumberString = filterValues["minNumber"];
            string maxNumberString = filterValues["maxNumber"];

            // If this is a nullable type such as bool?, the type is wrapped inside Nullable<> and we need to get the generic argument.
            string myPropertyType = IsNullable ?
                property.PropertyType.GetGenericArguments().Single().Name :
                property.PropertyType.Name;

            int storageIndex;

            switch (myPropertyType)
            {
                // Regardless of the width of the integer coming in, we treat it as a 64-bit integer.
                case "Byte":
                case "Int16":
                case "Int32":
                case "Int64":
                    if (myPropertyType == "Byte") storageIndex = nullableByteStorage;
                    else if (myPropertyType == "Int16") storageIndex = nullableInt16Storage;
                    else if (myPropertyType == "Int32") storageIndex = nullableInt32Storage;
                    else storageIndex = nullableInt64Storage;

                    if (!string.IsNullOrWhiteSpace(minNumberString))
                    {
                        generator.EmitCheckHasValue(property, storageIndex);
                        generator.Emit(OpCodes.Brfalse, lblReturnFalse); // return false if the property is null

                        // the integer from the record.
                        generator.EmitGetValueFromNullableProperty(property, storageIndex);
                        generator.Emit(OpCodes.Conv_I8); // convert to 64-bit integer
                        // the minimum integer
                        generator.Emit(OpCodes.Ldc_I8, Convert.ToInt64(minNumberString));
                        // If the integer is less than the minimum, return false.
                        generator.Emit(OpCodes.Blt, lblReturnFalse);
                    }
                    if (!string.IsNullOrWhiteSpace(maxNumberString))
                    {
                        generator.EmitCheckHasValue(property, storageIndex);
                        generator.Emit(OpCodes.Brfalse, lblReturnFalse); // return false if the property is null

                        // the integer from the record.
                        generator.EmitGetValueFromNullableProperty(property, storageIndex);
                        generator.Emit(OpCodes.Conv_I8); // convert to 64-bit integer
                        // the maximum integer
                        generator.Emit(OpCodes.Ldc_I8, Convert.ToInt64(maxNumberString));
                        // If the integer is greater than the maximum, return false.
                        generator.Emit(OpCodes.Bgt, lblReturnFalse);
                    }
                    break;
                // Floating point types
                case "Single":
                case "Double":
                    if (myPropertyType == "Single") storageIndex = nullableSingleStorage;
                    else storageIndex = nullableDoubleStorage;
                    if (!string.IsNullOrWhiteSpace(minNumberString))
                    {
                        generator.EmitCheckHasValue(property, storageIndex);
                        generator.Emit(OpCodes.Brfalse, lblReturnFalse); // return false if the integer is false

                        // the number from the record.
                        generator.EmitGetValueFromNullableProperty(property, storageIndex);
                        generator.Emit(OpCodes.Conv_R8); // convert to 64-bit floating-point number

                        // the minimum number
                        generator.Emit(OpCodes.Ldc_R8, Convert.ToDouble(minNumberString));
                        // If the number is less than the minimum, return false.
                        generator.Emit(OpCodes.Blt, lblReturnFalse);
                    }
                    if (!string.IsNullOrWhiteSpace(maxNumberString))
                    {
                        generator.EmitCheckHasValue(property, storageIndex);
                        generator.Emit(OpCodes.Brfalse, lblReturnFalse); // return false if the integer is false

                        // the number from the record.
                        generator.EmitGetValueFromNullableProperty(property, storageIndex);
                        generator.Emit(OpCodes.Conv_R8); // convert to 64-bit floating-point number
                        // the maximum number
                        generator.Emit(OpCodes.Ldc_R8, Convert.ToDouble(maxNumberString));
                        // If the number is greater than the maximum, return false.
                        generator.Emit(OpCodes.Bgt, lblReturnFalse);
                    }
                    break;
                // TODO: DECIMAL type
            }
            generator.Emit(OpCodes.Br, lblNextProperty);

            generator.MarkLabel(lblReturnFalse);
            generator.EmitReturnFalse();

            generator.MarkLabel(lblNextProperty);
        }
开发者ID:rupeshtelang,项目名称:ExpressForms,代码行数:96,代码来源:ExpressFormsFilterNumber.cs


注:本文中的System.Reflection.Emit.ILGenerator.EmitGetValueFromNullableProperty方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。