本文整理汇总了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;
}
示例2: FastField
public FastField(FieldInfo field, bool omitGetInitializer)
{
field.ThrowIfNull("field", "Paramater cannot be null.");
this.Field = field;
if (!omitGetInitializer)
InitializeGet();
InitializeSet();
}
示例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;
}
示例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));
}