本文整理汇总了C#中IContext.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# IContext.GetType方法的具体用法?C# IContext.GetType怎么用?C# IContext.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IContext
的用法示例。
在下文中一共展示了IContext.GetType方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SaveContext
public void SaveContext(IContext context)
{
JsonInit.InitConverter();
IConfigProvider configProvider = Provider.Get();
IConfigSection section = configProvider.LoadSingleSetting(SectionId, context.GetType().FullName);
section.GetSetting<string>(context.GetType().FullName, null, true).Value =
JsonConvert.SerializeObject(context);
configProvider.SaveSection(section);
}
示例2: GetOptionDefinitions
public IEnumerable<OptionDefinition> GetOptionDefinitions(IContext targetContext)
{
Argument.IsNotNull(() => targetContext);
var optionDefinitions = new List<OptionDefinition>();
var properties = targetContext.GetType().GetPropertiesEx();
foreach (var propertyInfo in properties)
{
if (propertyInfo.IsDecoratedWithAttribute<OptionAttribute>())
{
var optionAttribute = (OptionAttribute) propertyInfo.GetCustomAttributeEx(typeof (OptionAttribute), true);
optionDefinitions.Add(new OptionDefinition
{
ShortName = optionAttribute.ShortName,
LongName = optionAttribute.LongName,
DisplayName = optionAttribute.DisplayName,
HelpText = optionAttribute.HelpText,
AcceptsValue = optionAttribute.AcceptsValue,
TrimQuotes = optionAttribute.TrimQuotes,
IsMandatory = optionAttribute.IsMandatory,
PropertyNameOnContext = propertyInfo.Name
});
}
}
return optionDefinitions;
}
示例3: SaveContext
public void SaveContext(IContext context)
{
string filename = Path.Combine(_path, GetJsonFilename(context.GetType()));
using (StreamWriter file = File.CreateText(filename))
{
var serializer = new JsonSerializer();
JsonInit.InitSerializer(serializer);
serializer.Serialize(file, context);
}
}
示例4: Execute
public override CommandResult Execute(IContext ctx)
{
if (!(ctx is MarshalByRefObject))
{
throw new ContextNotRemoteableException("IContext "
+ ctx.GetType() + " is not remoteable (subclass of MarshalByRefObject)");
}
// Statically set up remoting configuration before first call
if (Monitor.TryEnter(_fcLock, TimeSpan.FromSeconds(15)))
{
try
{
if (_firstCall)
{
this.ConfigureRemoting(ctx);
_firstCall = false;
}
}
finally
{
Monitor.Exit(_fcLock);
}
}
else
{
logger.Error("Unable to obtain exclusive lock on first-call state");
}
logger.Debug("Activating remote catalog at {0}", this.CatalogUrl);
ICatalog catalog = (ICatalog)Activator.GetObject(typeof(ICatalog), this.CatalogUrl);
logger.Debug("Got catalog {0}, invoking {1}", catalog.GetDescription(), this.Command);
try
{
return catalog[this.Command].Execute(ctx);
}
finally
{
logger.Debug("Done");
}
}
示例5: CreateILogForSpecificType
private Logger CreateILogForSpecificType(IContext context)
{
return Logger.GetLogger(context.ParentType ?? context.GetType());
}
示例6: UpdateContext
private void UpdateContext(IContext targetContext, OptionDefinition optionDefinition, string value)
{
var propertyInfo = targetContext.GetType().GetPropertyEx(optionDefinition.PropertyNameOnContext);
if (optionDefinition.TrimQuotes)
{
if (!string.IsNullOrWhiteSpace(value))
{
value = value.Trim('\"');
}
}
var finalValue = StringToObjectHelper.ToRightType(propertyInfo.PropertyType, value);
propertyInfo.SetValue(targetContext, finalValue, null);
}