本文整理汇总了C#中System.Object.?.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# Object.?.GetType方法的具体用法?C# Object.?.GetType怎么用?C# Object.?.GetType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Object
的用法示例。
在下文中一共展示了Object.?.GetType方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateLiteralExpression
public static CodeExpression CreateLiteralExpression(Object value)
{
var expressionValue = value as CodeExpression;
if (expressionValue != null)
{
return expressionValue;
}
var typeValue = value as Type;
if (typeValue != null)
{
return new CodeTypeOfExpression(typeValue);
}
var type = value?.GetType();
if (type?.IsEnum ?? false)
{
return new CodeFieldReferenceExpression(
new CodeTypeReferenceExpression(type),
type.GetEnumName(value)
);
}
return new CodePrimitiveExpression(value);
}
示例2: AddItemContainer
/// <summary>
/// Adds an item container to this control for the specified item.
/// </summary>
/// <param name="index">The index of the item being added.</param>
/// <param name="item">The item for which to add an item container.</param>
/// <returns>The item container that was added.</returns>
private DependencyObject AddItemContainer(Int32 index, Object item)
{
if (ItemsPanelElement == null)
return null;
var container = default(DependencyObject);
if (IsItemContainer(item))
{
container = (DependencyObject)item;
}
else
{
container = GetContainerForItemOverride();
var template = ItemTemplateSelector?.SelectTemplate(item, container) ?? ItemTemplate;
if (template != null)
{
var templateInstance = template.LoadContent(item, item?.GetType());
PrepareContainerForItemOverride(container, templateInstance);
}
else
{
PrepareContainerForItemOverride(container, item);
}
}
itemContainerGenerator.AssociateContainerWithItem(container, item);
itemContainers.Insert(index, container);
var containerElement = container as UIElement;
if (containerElement != null)
{
ItemsPanelElement.Children.Insert(index, containerElement);
containerElement.ChangeLogicalParent(this);
}
SetValue(HasItemsPropertyKey, true);
return container;
}