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


C# FieldInfo.ThrowIfNull方法代码示例

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


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

示例1: Create

        /// <summary>
        /// Creates dynamic field instance for the specified <see cref="FieldInfo"/>.
        /// </summary>
        /// <param name="field">Field info to create dynamic field for.</param>
        /// <returns>Dynamic field for the specified <see cref="FieldInfo"/>.</returns>
        public static IDynamicField Create(FieldInfo field)
        {
            field.ThrowIfNull("field", "You cannot create a dynamic field for a null value.");

            IDynamicField dynamicField = new SafeFieldWrapper(field);
            return dynamicField;
        }
开发者ID:OleksandrKulchytskyi,项目名称:Sharedeployed,代码行数:12,代码来源:DynamicField.cs

示例2: FastField

 public FastField(FieldInfo field, bool omitGetInitializer)
 {
     field.ThrowIfNull("field", "Paramater cannot be null.");
     this.Field = field;
     if (!omitGetInitializer)
         InitializeGet();
     InitializeSet();
 }
开发者ID:OleksandrKulchytskyi,项目名称:Sharedeployed,代码行数:8,代码来源:FastField.cs

示例3: SafeFieldWrapper

        /// <summary>
        /// Creates a new instance of the safe field wrapper.
        /// </summary>
        /// <param name="field">Field to wrap.</param>
        public SafeFieldWrapper(FieldInfo field)
        {
            field.ThrowIfNull("field", "You cannot create a dynamic field for a null value.");

            fieldInfo = field;
            DynamicFieldInfo fi = GetOrCreateDynamicField(field);
            getter = fi.Getter;
            setter = fi.Setter;
        }
开发者ID:OleksandrKulchytskyi,项目名称:Sharedeployed,代码行数:13,代码来源:DynamicField.cs

示例4: CreateFieldSetter

        /// <summary>
        /// Create a new Set method delegate for the specified field using <see cref="System.Reflection.Emit.DynamicMethod"/>
        /// </summary>
        /// <param name="fieldInfo">the field to create the delegate for</param>
        /// <returns>a delegate that can be used to read the field.</returns>
        /// <remarks>
        /// If the field's <see cref="FieldInfo.IsLiteral"/> returns true, the returned method 
        /// will throw an <see cref="InvalidOperationException"/> when called.
        /// </remarks>
        public static FieldSetterDelegate CreateFieldSetter(FieldInfo fieldInfo)
        {
            fieldInfo.ThrowIfNull("fieldInfo", "You cannot create a delegate for a null value.");

            bool skipVisibility = true; // !IsPublic(fieldInfo);
            System.Reflection.Emit.DynamicMethod dmSetter = CreateDynamicMethod("set_" + fieldInfo.Name, null, new Type[] { typeof(object), typeof(object) }, fieldInfo, skipVisibility);
            ILGenerator il = dmSetter.GetILGenerator();
            EmitFieldSetter(il, fieldInfo, false);
            return (FieldSetterDelegate)dmSetter.CreateDelegate(typeof(FieldSetterDelegate));
        }
开发者ID:OleksandrKulchytskyi,项目名称:Sharedeployed,代码行数:19,代码来源:ILManager.cs


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