本文整理汇总了C#中System.Object.ThrowIfNull方法的典型用法代码示例。如果您正苦于以下问题:C# Object.ThrowIfNull方法的具体用法?C# Object.ThrowIfNull怎么用?C# Object.ThrowIfNull使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Object
的用法示例。
在下文中一共展示了Object.ThrowIfNull方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RefEquals
/// <summary>
/// Determines whether the specified objects instances are the same instance.
/// </summary>
/// <exception cref="ArgumentNullException">The first object can not be null.</exception>
/// <exception cref="ArgumentNullException">The second object can not be null.</exception>
/// <param name="obj0">The first object to compare.</param>
/// <param name="obj1">The second object to compare.</param>
/// <returns>Returns true if if the objects are the same instance.</returns>
public static Boolean RefEquals( this Object obj0, Object obj1 )
{
obj0.ThrowIfNull( nameof( obj0 ) );
obj1.ThrowIfNull( nameof( obj1 ) );
return ReferenceEquals( obj0, obj1 );
}
示例2: WireAll
/// <summary>
/// Wires up an entire object according to its usage of CommandWirerAttributes
/// </summary>
/// <param name="toWire"></param>
/// <returns></returns>
public static IList<CommandWirer> WireAll(Object toWire)
{
toWire.ThrowIfNull ("toWire");
var toWireType = toWire.GetType ();
var helperMap = new Dictionary<String, CommandWirer> ();
foreach (var prop in
toWireType.GetProperties (BindingFlags.Public | BindingFlags.Instance)
.Union (toWireType.GetProperties (BindingFlags.NonPublic | BindingFlags.Instance))
.Union (toWireType.GetProperties (BindingFlags.Public | BindingFlags.Static))
.Union (toWireType.GetProperties (BindingFlags.NonPublic | BindingFlags.Static)))
{
foreach (var attr in prop.GetCustomAttributes (typeof (CommandWirerAttribute), true).Cast<CommandWirerAttribute> ())
{
attr.SetKeyFromMethodName (prop.Name);
CommandWirer helper;
if (!helperMap.TryGetValue (attr.Key, out helper))
helperMap[attr.Key] = helper = new CommandWirer { Key = attr.Key, InvokeOn = toWire };
attr.Configure (helper, prop);
}
}
foreach (var method in
toWireType.GetMethods (BindingFlags.Public | BindingFlags.Instance)
.Union (toWireType.GetMethods (BindingFlags.NonPublic | BindingFlags.Instance))
.Union (toWireType.GetMethods (BindingFlags.Public | BindingFlags.Static))
.Union (toWireType.GetMethods (BindingFlags.NonPublic | BindingFlags.Static)))
{
foreach (var attr in method.GetCustomAttributes (typeof (CommandWirerAttribute), true).Cast<CommandWirerAttribute> ())
{
attr.SetKeyFromMethodName (method.Name);
CommandWirer helper;
if (!helperMap.TryGetValue (attr.Key, out helper))
helperMap[attr.Key] = helper = new CommandWirer { Key = attr.Key };
attr.Configure (helper, method);
}
}
foreach (var helper in helperMap.Values)
helper.Wire ();
return helperMap.Values.ToList ();
}
示例3: ThrowIfNull_SetNotNull_Success
public void ThrowIfNull_SetNotNull_Success()
{
object obj = new Object();
obj.ThrowIfNull("obj");
}