本文整理汇总了C#中this.As方法的典型用法代码示例。如果您正苦于以下问题:C# this.As方法的具体用法?C# this.As怎么用?C# this.As使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类this
的用法示例。
在下文中一共展示了this.As方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetMemberType
public static Type GetMemberType(this MemberInfo member)
{
if (member is FieldInfo) return member.As<FieldInfo>().FieldType;
if (member is PropertyInfo) return member.As<PropertyInfo>().PropertyType;
throw new NotSupportedException();
}
示例2: GetContentName
public static string GetContentName(this IContent content)
{
if (content.Has<TitlePart>()) { return content.As<TitlePart>().Title; }
if (content.Has<WidgetPart>()) { return content.As<WidgetPart>().Title; }
if (content.Has<UserPart>()) { return content.As<UserPart>().UserName; }
if (content.Has<WidgetPart>()) { return content.As<WidgetPart>().Title; }
if (content.Has<LayerPart>()) { return content.As<LayerPart>().Name; }
return "Unknown";
}
示例3: GetComponentsHandlerOrder
public static string GetComponentsHandlerOrder(this IProductElement endpoint)
{
var sb = new StringBuilder();
var app = endpoint.Root.As<NServiceBusStudio.IApplication>();
var endpoints = app.Design.Endpoints.GetAll();
var sourceComponents = (endpoint.As<IToolkitInterface>() as IAbstractEndpoint).EndpointComponents.AbstractComponentLinks.OrderBy(o => o.Order);
var components = sourceComponents.Select(ac => ac.ComponentReference.Value)
.Where(c => c.Subscribes.ProcessedCommandLinks.Any() || c.Subscribes.SubscribedEventLinks.Any())
.Select(cmp => HandlerTypeFromComponent(cmp));
// Add authentication first if needed
if (app.HasAuthentication && (endpoint.As<IToolkitInterface>() as IAbstractEndpoint).Project != null)
{
components = new string[] { string.Format("{0}.Infrastructure.Authentication", (endpoint.As<IToolkitInterface>() as IAbstractEndpoint).Project.Data.RootNamespace) }.Union(components);
}
////
if (components.Count() > 1)
{
sb.Append(@"
public void SpecifyOrder(Order order)
{
order.Specify(");
int pos = 1;
foreach (var c in components)
{
if (pos == 1)
{
sb.AppendFormat("First<{0}>", c);
}
else if (pos == 2)
{
sb.AppendFormat(".Then<{0}>()", c);
}
else
{
sb.AppendFormat(".AndThen<{0}>()", c);
}
pos++;
}
sb.Append(@");
}");
}
////
return sb.ToString();
}
示例4: GetMemberType
public static Type GetMemberType(this MemberInfo member)
{
Type rawType = null;
if (member is FieldInfo)
{
rawType = member.As<FieldInfo>().FieldType;
}
if (member is PropertyInfo)
{
rawType = member.As<PropertyInfo>().PropertyType;
}
return rawType.IsNullable() ? rawType.GetInnerTypeFromNullable() : rawType;
}
示例5: AsTable
public static TableGrammar AsTable(this IGrammar inner, string title, string leafName)
{
return new TableGrammar(inner.As<IGrammarWithCells>(), leafName)
{
LabelName = title
};
}
示例6: Build
/// <summary>
/// Starts a build of the solution.
/// </summary>
public static Task<bool> Build(this ISolutionNode solution)
{
var sln = solution.As<EnvDTE.Solution>();
if (sln == null)
throw new ArgumentException(Strings.ISolutionNodeExtensions.BuildNotSupported);
return System.Threading.Tasks.Task.Factory.StartNew<bool>(() =>
{
var mre = new ManualResetEventSlim();
var events = sln.DTE.Events.BuildEvents;
EnvDTE._dispBuildEvents_OnBuildDoneEventHandler done = (scope, action) => mre.Set();
events.OnBuildDone += done;
try
{
// Let build run async.
sln.SolutionBuild.Build(false);
// Wait until it's done.
mre.Wait();
// LastBuildInfo == # of projects that failed to build.
return sln.SolutionBuild.LastBuildInfo == 0;
}
catch (Exception ex)
{
tracer.Error(ex, Strings.ISolutionNodeExtensions.BuildException);
return false;
}
finally
{
// Cleanup handler.
events.OnBuildDone -= done;
}
}, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default);
}
示例7: ToGraph
public static ServiceGraph ToGraph(this IServiceRegistry registry)
{
var behaviorGraph = new BehaviorGraph();
registry.As<IConfigurationAction>().Configure(behaviorGraph);
return behaviorGraph.Services;
}
示例8: DisplayName
public static string DisplayName(this IUser user)
{
var userProfilePart = user.As<UserProfilePart>();
if (userProfilePart != null && !string.IsNullOrWhiteSpace(userProfilePart.Name)) return userProfilePart.Name;
if (!string.IsNullOrWhiteSpace(user.Email)) return user.Email;
return user.UserName;
}
示例9: GetMessageConventions
public static string GetMessageConventions(this IProductElement endpoint)
{
var generatedConventions = string.Empty;
try
{
var app = endpoint.Root.As<NServiceBusStudio.IApplication>();
var rootNameSpace = string.Empty;
var applicationName = app.CodeIdentifier;
var projectNameForInternal = app.ProjectNameInternalMessages;
var projectNameForContracts = app.ProjectNameContracts;
var project = endpoint.As<IAbstractEndpoint>().As<IProductElement>().GetProject();
if (project != null)
{
rootNameSpace = project.Data.RootNamespace;
}
generatedConventions = GetMessageConventions(rootNameSpace, applicationName, projectNameForInternal, projectNameForContracts);
}
catch (Exception ex)
{
//TODO: Why are we catching the exception here??
}
return generatedConventions;
}
示例10: GetMessageConventions
public static string GetMessageConventions(this IProductElement endpoint)
{
var generatedConventions = string.Empty;
try
{
var app = endpoint.Root.As<IApplication>();
var rootNameSpace = string.Empty;
var applicationName = app.InstanceName;
var projectNameForInternal = app.ProjectNameInternalMessages;
var projectNameForContracts = app.ProjectNameContracts;
var project = endpoint.As<IAbstractEndpoint>().As<IProductElement>().GetProject();
if (project != null)
{
rootNameSpace = project.Data.RootNamespace;
}
generatedConventions =
app.TargetNsbVersion == TargetNsbVersion.Version4
? GetMessageConventionsV4(rootNameSpace, applicationName, projectNameForInternal, projectNameForContracts)
: GetMessageConventionsV5(rootNameSpace, applicationName, projectNameForInternal, projectNameForContracts);
}
catch (Exception ex)
{
//TODO: Why are we catching the exception here??
}
return generatedConventions;
}
示例11: ShouldBeRangeVariableToken
public static AndConstraint<RangeVariableToken> ShouldBeRangeVariableToken(this QueryToken token, string expectedName)
{
token.Should().BeOfType<RangeVariableToken>();
var parameterQueryToken = token.As<RangeVariableToken>();
parameterQueryToken.Kind.Should().Be(QueryTokenKind.RangeVariable);
parameterQueryToken.Name.Should().Be(expectedName);
return new AndConstraint<RangeVariableToken>(parameterQueryToken);
}
示例12: ShouldBeUnaryOperatorQueryToken
public static AndConstraint<UnaryOperatorToken> ShouldBeUnaryOperatorQueryToken(this QueryToken token, UnaryOperatorKind expectedOperatorKind)
{
token.Should().BeOfType<UnaryOperatorToken>();
var propertyAccessQueryToken = token.As<UnaryOperatorToken>();
propertyAccessQueryToken.Kind.Should().Be(QueryTokenKind.UnaryOperator);
propertyAccessQueryToken.OperatorKind.Should().Be(expectedOperatorKind);
return new AndConstraint<UnaryOperatorToken>(propertyAccessQueryToken);
}
示例13: IsSynchronous
/// <summary>
/// indicates the task is synchronous
/// </summary>
/// <param name="task"></param>
/// <returns></returns>
public static ISynchronousDecoration IsSynchronous(this ITask task)
{
Condition.Requires(task).IsNotNull();
var rv = task.As<SynchronousDecoration>();
if (rv == null)
rv = new SynchronousDecoration(task);
return rv;
}
示例14: ShouldBeEndPathToken
public static AndConstraint<EndPathToken> ShouldBeEndPathToken(this QueryToken token, string expectedName)
{
token.Should().BeOfType<EndPathToken>();
var propertyAccessQueryToken = token.As<EndPathToken>();
propertyAccessQueryToken.Kind.Should().Be(QueryTokenKind.EndPath);
propertyAccessQueryToken.Identifier.Should().Be(expectedName);
return new AndConstraint<EndPathToken>(propertyAccessQueryToken);
}
示例15: IsAsynchronous
/// <summary>
/// Decoration that flags a task as being asynchronous and provides the conditions needed to trigger completion and error.
/// Automatically decorates with TriggerConditions.
/// </summary>
/// <param name="task"></param>
/// <returns></returns>
public static IAsynchronousDecoration IsAsynchronous(this ITask task, ICondition markCompleteCondition, ICondition markErrorCondition)
{
Condition.Requires(task).IsNotNull();
var rv = task.As<AsynchronousDecoration>();
if (rv == null)
rv = new AsynchronousDecoration(task, markCompleteCondition, markErrorCondition);
return rv;
}