本文整理汇总了C#中Accessor类的典型用法代码示例。如果您正苦于以下问题:C# Accessor类的具体用法?C# Accessor怎么用?C# Accessor使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Accessor类属于命名空间,在下文中一共展示了Accessor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetMessageSubstitutions
public IEnumerable<KeyValuePair<string, string>> GetMessageSubstitutions(Accessor accessor)
{
return new List<KeyValuePair<string, string>>
{
new KeyValuePair<string, string>(LENGTH, Length.ToString())
};
}
示例2: EmitIndexerMethod
protected virtual void EmitIndexerMethod(IndexerDeclaration indexerDeclaration, Accessor accessor, bool setter)
{
if (!accessor.IsNull && this.Emitter.GetInline(accessor) == null)
{
XmlToJsDoc.EmitComment(this, this.IndexerDeclaration);
var overloads = OverloadsCollection.Create(this.Emitter, indexerDeclaration, setter);
string name = overloads.GetOverloadName();
this.Write((setter ? "set" : "get") + name);
this.EmitMethodParameters(indexerDeclaration.Parameters, indexerDeclaration, setter);
if (setter)
{
this.Write(", value");
this.WriteColon();
name = BridgeTypes.ToTypeScriptName(indexerDeclaration.ReturnType, this.Emitter);
this.Write(name);
this.WriteCloseParentheses();
this.WriteColon();
this.Write("void");
}
else
{
this.WriteColon();
name = BridgeTypes.ToTypeScriptName(indexerDeclaration.ReturnType, this.Emitter);
this.Write(name);
}
this.WriteSemiColon();
this.WriteNewLine();
}
}
示例3: GetActions
public IEnumerable<CodeAction> GetActions(RefactoringContext context)
{
var pdecl = GetPropertyDeclaration(context);
if (pdecl == null) {
yield break;
}
var type = pdecl.Parent as TypeDeclaration;
if (type != null && type.ClassType == ClassType.Interface) {
yield break;
}
yield return new CodeAction (pdecl.Setter.IsNull ? context.TranslateString("Add getter") : context.TranslateString("Add setter"), script => {
var accessorStatement = BuildAccessorStatement(context, pdecl);
Accessor accessor = new Accessor () {
Body = new BlockStatement { accessorStatement }
};
accessor.Role = pdecl.Setter.IsNull ? PropertyDeclaration.SetterRole : PropertyDeclaration.GetterRole;
if (pdecl.Setter.IsNull && !pdecl.Getter.IsNull) {
script.InsertBefore(pdecl.RBraceToken, accessor);
} else if (pdecl.Getter.IsNull && !pdecl.Setter.IsNull) {
script.InsertBefore(pdecl.Setter, accessor);
} else {
script.InsertBefore(pdecl.Getter, accessor);
}
script.Select(accessorStatement);
script.FormatText(pdecl);
});
}
示例4: establish_context
public override void establish_context()
{
property = ReflectionHelper.GetAccessor(GetPropertyExpression());
target = new PropertyEntity();
sut = new Property<PropertyEntity, string>(property, "expected");
}
示例5: establish_context
public override void establish_context()
{
property = ReflectionHelper.GetAccessor((Expression<Func<ListEntity, IEnumerable<string>>>)(x => x.GetterAndSetter));
target = new ListEntity();
sut = new ReferenceBag<ListEntity, string>(property, new[] { "foo", "bar", "baz" });
}
示例6: FormatValue
/// <summary>
/// Formats the provided value using the property accessor metadata
/// </summary>
/// <param name="modelType">The type of the model to which the property belongs (i.e. Case where the property might be on its base class WorkflowItem)</param>
/// <param name="formatter">The formatter</param>
/// <param name="property">The property that holds the given value</param>
/// <param name="value">The data to format</param>
public static string FormatValue(this IDisplayFormatter formatter, Type modelType, Accessor property, object value)
{
return formatter.GetDisplay(new GetStringRequest(property, value, null)
{
OwnerType = modelType
});
}
示例7: RegisterRule
public RemoteFieldRule RegisterRule(Accessor accessor, IFieldValidationRule rule)
{
var remote = RemoteFieldRule.For(accessor, rule);
_rules[accessor].Fill(remote);
return remote;
}
示例8: fillFields
private static void fillFields(ValidationOptions options, IValidationNode node, IServiceLocator services, Accessor accessor)
{
var mode = node.DetermineMode(services, accessor);
var field = new FieldOptions
{
field = accessor.Name,
mode = mode.Mode
};
var graph = services.GetInstance<ValidationGraph>();
var rules = graph.FieldRulesFor(accessor);
var ruleOptions = new List<FieldRuleOptions>();
rules.Each(rule =>
{
var ruleMode = rule.Mode ?? mode;
ruleOptions.Add(new FieldRuleOptions
{
rule = RuleAliases.AliasFor(rule),
mode = ruleMode.Mode
});
});
field.rules = ruleOptions.ToArray();
options._fields.Add(field);
}
示例9: FormatValue
/// <summary>
/// Formats the provided value using the accessor accessor metadata and a custom format
/// </summary>
/// <param name="formatter">The formatter</param>
/// <param name="modelType">The type of the model to which the accessor belongs (i.e. Case where the accessor might be on its base class WorkflowItem)</param>
/// <param name="accessor">The property that holds the given value</param>
/// <param name="value">The data to format</param>
/// <param name="format">The custom format specifier</param>
public static string FormatValue(this IDisplayFormatter formatter, Type modelType, Accessor accessor,
object value, string format)
{
var request = new GetStringRequest(accessor, value, null, format, null);
return formatter.GetDisplay(request);
}
示例10: GetActions
public override IEnumerable<CodeAction> GetActions(RefactoringContext context)
{
var pdecl = context.GetNode<PropertyDeclaration> ();
if (pdecl == null || !pdecl.Getter.IsNull && !pdecl.Setter.IsNull || !pdecl.NameToken.Contains(context.Location)) {
yield break;
}
var type = pdecl.Parent as TypeDeclaration;
if (type != null && type.ClassType == ClassType.Interface) {
yield break;
}
yield return new CodeAction (pdecl.Setter.IsNull ? context.TranslateString("Add setter") : context.TranslateString("Add getter"), script => {
Statement accessorStatement = null;
var accessor = new Accessor ();
if (!pdecl.Getter.IsNull && !pdecl.Getter.Body.IsNull || !pdecl.Setter.IsNull && !pdecl.Setter.Body.IsNull) {
accessorStatement = BuildAccessorStatement(context, pdecl);
accessor.Body = new BlockStatement { accessorStatement };
}
accessor.Role = pdecl.Setter.IsNull ? PropertyDeclaration.SetterRole : PropertyDeclaration.GetterRole;
if (pdecl.Setter.IsNull && !pdecl.Getter.IsNull) {
script.InsertAfter(pdecl.Getter, accessor);
} else if (pdecl.Getter.IsNull && !pdecl.Setter.IsNull) {
script.InsertBefore(pdecl.Setter, accessor);
} else {
script.InsertBefore(pdecl.Getter, accessor);
}
script.FormatText(pdecl);
if (accessorStatement != null)
script.Select(accessorStatement);
}, pdecl.NameToken);
}
示例11: RouteParameter
public RouteParameter(Accessor accessor)
{
_accessor = accessor;
accessor.ForAttribute<RouteInputAttribute>(x => DefaultValue = x.DefaultValue);
_regex = new Regex(@"{\*?" + Name + @"(?:\:.*?)?}", RegexOptions.Compiled);
}
示例12: VisitAccessor
public virtual void VisitAccessor(Accessor accessor)
{
if (this.ThrowException)
{
throw (Exception)this.CreateException(accessor);
}
}
示例13: GetMessageSubstitutions
public IEnumerable<KeyValuePair<string, string>> GetMessageSubstitutions(Accessor accessor)
{
return new List<KeyValuePair<string, string>>
{
new KeyValuePair<string, string>(FIELD, accessor.Name)
};
}
示例14: EmitPropertyMethod
protected virtual void EmitPropertyMethod(PropertyDeclaration propertyDeclaration, Accessor accessor, bool setter)
{
var memberResult = this.Emitter.Resolver.ResolveNode(propertyDeclaration, this.Emitter) as MemberResolveResult;
if (memberResult != null &&
(memberResult.Member.Attributes.Any(a => a.AttributeType.FullName == "Bridge.FieldPropertyAttribute") ||
(propertyDeclaration.Getter.IsNull && propertyDeclaration.Setter.IsNull)))
{
return;
}
if (!accessor.IsNull && this.Emitter.GetInline(accessor) == null)
{
this.EnsureComma();
this.ResetLocals();
var prevMap = this.BuildLocalsMap();
var prevNamesMap = this.BuildLocalsNamesMap();
if (setter)
{
this.AddLocals(new ParameterDeclaration[] { new ParameterDeclaration { Name = "value" } }, accessor.Body);
}
XmlToJsDoc.EmitComment(this, this.PropertyDeclaration);
var overloads = OverloadsCollection.Create(this.Emitter, propertyDeclaration, setter);
string name = overloads.GetOverloadName();
this.Write((setter ? "set" : "get") + name);
this.WriteColon();
this.WriteFunction();
this.WriteOpenParentheses();
this.Write(setter ? "value" : "");
this.WriteCloseParentheses();
this.WriteSpace();
var script = this.Emitter.GetScript(accessor);
if (script == null)
{
accessor.Body.AcceptVisitor(this.Emitter);
}
else
{
this.BeginBlock();
foreach (var line in script)
{
this.Write(line);
this.WriteNewLine();
}
this.EndBlock();
}
this.ClearLocalsMap(prevMap);
this.ClearLocalsNamesMap(prevNamesMap);
this.Emitter.Comma = true;
}
}
示例15: Validate
public void Validate(Accessor accessor, ValidationContext context)
{
var rawValue = accessor.GetValue(context.Target);
if (rawValue != null && rawValue.ToString().Length > Length)
{
context.Notification.RegisterMessage(accessor, Token, TemplateValue.For(LENGTH, _length));
}
}