本文整理汇总了C#中PropertyDeclaration.HasModifier方法的典型用法代码示例。如果您正苦于以下问题:C# PropertyDeclaration.HasModifier方法的具体用法?C# PropertyDeclaration.HasModifier怎么用?C# PropertyDeclaration.HasModifier使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PropertyDeclaration
的用法示例。
在下文中一共展示了PropertyDeclaration.HasModifier方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: VisitPropertyDeclaration
public override void VisitPropertyDeclaration(PropertyDeclaration propertyDeclaration)
{
if (propertyDeclaration.HasModifier(Modifiers.Static))
{
this.CheckDependency(propertyDeclaration.ReturnType);
if (!propertyDeclaration.Getter.IsNull)
{
propertyDeclaration.Getter.AcceptVisitor(this);
}
}
}
示例2: CreateChangedEventDeclaration
EventDeclaration CreateChangedEventDeclaration (RefactoringContext context, PropertyDeclaration propertyDeclaration)
{
return new EventDeclaration {
Modifiers = propertyDeclaration.HasModifier (Modifiers.Static) ? Modifiers.Public | Modifiers.Static : Modifiers.Public,
ReturnType = context.CreateShortType("System", "EventHandler"),
Variables = {
new VariableInitializer {
Name = propertyDeclaration.Name + "Changed"
}
}
};
}
示例3: GetBackingField
internal static IField GetBackingField (BaseRefactoringContext context, PropertyDeclaration propertyDeclaration)
{
// automatic properties always need getter & setter
if (propertyDeclaration == null || propertyDeclaration.Getter.IsNull || propertyDeclaration.Setter.IsNull || propertyDeclaration.Getter.Body.IsNull || propertyDeclaration.Setter.Body.IsNull)
return null;
if (!context.Supports(csharp3) || propertyDeclaration.HasModifier (ICSharpCode.NRefactory.CSharp.Modifiers.Abstract) || ((TypeDeclaration)propertyDeclaration.Parent).ClassType == ClassType.Interface)
return null;
var getterField = ScanGetter (context, propertyDeclaration);
if (getterField == null)
return null;
var setterField = ScanSetter (context, propertyDeclaration);
if (setterField == null)
return null;
if (!getterField.Equals(setterField))
return null;
return getterField;
}
示例4: 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" ||
a.AttributeType.FullName == "Bridge.IgnoreAttribute" ||
a.AttributeType.FullName == "Bridge.ExternalAttribute") ||
(propertyDeclaration.Getter.IsNull && propertyDeclaration.Setter.IsNull)))
{
return;
}
if (!accessor.IsNull && this.Emitter.GetInline(accessor) == null)
{
//this.EnsureComma();
this.EnsureNewLine();
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();
name = setter ? "set" + name : "get" + name;
TransformCtx.CurClassMethodNames.Add(new TransformCtx.MethodInfo() {
Name = name,
IsPrivate = propertyDeclaration.HasModifier(Modifiers.Private),
});
this.Write(name);
this.WriteEqualsSign();
this.WriteFunction();
this.WriteOpenParentheses();
if(propertyDeclaration.HasModifier(Modifiers.Static)) {
this.Write(setter ? "value" : "");
}
else {
this.WriteThis();
this.Write(setter ? ", value" : "");
}
this.WriteCloseParentheses();
this.WriteSpace();
this.BeginFunctionBlock();
var script = this.Emitter.GetScript(accessor);
if (script == null)
{
accessor.Body.AcceptVisitor(this.Emitter);
}
else
{
foreach (var line in script)
{
this.Write(line);
this.WriteNewLine();
}
}
this.EndFunctionBlock();
this.ClearLocalsMap(prevMap);
this.ClearLocalsNamesMap(prevNamesMap);
this.Emitter.Comma = true;
}
}
示例5: VisitPropertyDeclaration
public override void VisitPropertyDeclaration(PropertyDeclaration propertyDeclaration)
{
if (propertyDeclaration.HasModifier(Modifiers.Abstract))
{
return;
}
bool isStatic = propertyDeclaration.HasModifier(Modifiers.Static);
IDictionary<string, List<EntityDeclaration>> dict = isStatic
? CurrentType.StaticProperties
: CurrentType.InstanceProperties;
var key = propertyDeclaration.Name;
if (dict.ContainsKey(key))
{
dict[key].Add(propertyDeclaration);
}
else
{
dict.Add(key, new List<EntityDeclaration>(new[] { propertyDeclaration }));
}
if (!propertyDeclaration.Getter.IsNull
&& !this.HasInline(propertyDeclaration.Getter)
&& propertyDeclaration.Getter.Body.IsNull
&& !this.HasScript(propertyDeclaration.Getter))
{
Expression initializer = this.GetDefaultFieldInitializer(propertyDeclaration.ReturnType);
TypeConfigInfo info = isStatic ? this.CurrentType.StaticConfig : this.CurrentType.InstanceConfig;
if (!this.AssemblyInfo.AutoPropertyToField)
{
info.Properties.Add(new TypeConfigItem
{
Name = key,
Entity = propertyDeclaration,
Initializer = initializer
});
}
else
{
info.Fields.Add(new TypeConfigItem
{
Name = key,
Entity = propertyDeclaration,
Initializer = initializer
});
}
}
}
示例6: OverloadsCollection
private OverloadsCollection(IEmitter emitter, PropertyDeclaration propDeclaration, bool isSetter)
{
this.Emitter = emitter;
this.Name = propDeclaration.Name;
this.JsName = Helpers.GetPropertyRef(propDeclaration, emitter, isSetter, true, true);
this.AltJsName = Helpers.GetPropertyRef(propDeclaration, emitter, !isSetter, true, true);
this.Inherit = !propDeclaration.HasModifier(Modifiers.Static);
this.Static = propDeclaration.HasModifier(Modifiers.Static);
this.CancelChangeCase = !Helpers.IsFieldProperty(propDeclaration, emitter);
this.IsSetter = isSetter;
this.Member = this.FindMember(propDeclaration);
this.TypeDefinition = this.Member.DeclaringTypeDefinition;
this.Type = this.Member.DeclaringType;
this.InitMembers();
this.Emitter.OverloadsCache[propDeclaration.GetHashCode().ToString() + isSetter.GetHashCode().ToString()] = this;
}
示例7: VisitPropertyDeclaration
public override void VisitPropertyDeclaration(PropertyDeclaration e)
{
var pd = e.Annotation<PropertyDefinition>();
if (pd != null)
{
if (!e.PrivateImplementationType.IsNull && pd.DeclaringType.IsCompilerGenerated())
{
// 将接口实现转换为显式实现
var convert = true;
if (pd.DeclaringType.Interfaces.Count > 1)
{
//TagSnapshotRange<T> IEnumerator<TagSnapshotRange<T>>.Current { get { …… } }
//object IEnumerator.Current { get { …… } }
var trInterface = e.PrivateImplementationType.Annotation<TypeReference>();
var hasSameNameInterfaces = pd.DeclaringType.Interfaces.Select(x => x.Resolve()).Where(x => x == null || x.WellFullName != trInterface.WellFullName && x.Properties.Any(y => y.WellName == pd.WellName));
if (hasSameNameInterfaces.Any())
{
if (hasSameNameInterfaces.Any(x => x == null) ||
!trInterface.HasGenericParameters ||
hasSameNameInterfaces.Any(x => x.HasGenericParameters))
{
convert = false;
}
}
}
if (convert)
{
e.PrivateImplementationType = null;
e.Modifiers |= Modifiers.Public;
}
}
var accessor = pd.GetMethod ?? pd.SetMethod;
if (accessor != null && accessor.HasOverrides)
{
// 属性重载或接口属性的显式实现
// bool ICollection.xxx
//====>
// bool ICollection.IsSynchronized
var access = accessor.Overrides.First();
if (access.Name.StartsWith("get_") || access.Name.StartsWith("set_"))
{
var opn = access.Name.Substring(4);
var opd = access.DeclaringType.Resolve().Properties.FirstOrDefault(x => x.Name == opn);
if (opd != null) e.Name = opd.WellName;
}
}
else if (e.HasModifier(Modifiers.Override))
{
}
}
base.VisitPropertyDeclaration(e);
}