public abstract Resolve ( ) : Mono.Cecil.PropertyDefinition | ||
리턴 | Mono.Cecil.PropertyDefinition |
protected virtual string GetPropertyName(PropertyReference property) { PropertyDefinition propertyDefinition = property.Resolve(); if (propertyDefinition != null && propertyDefinition.Module.FilePath == this.ModuleContext.Module.FilePath) { try { return this.ModuleContext.RenamedMembersMap[propertyDefinition.MetadataToken.ToUInt32()]; } catch (Exception ex) { Write(propertyDefinition.MetadataToken.ToUInt32().ToString()); WriteLine(); Write(ModuleContext.RenamedMembersMap.Count.ToString()); WriteLine(); foreach (KeyValuePair<uint, string> pair in ModuleContext.RenamedMembersMap) { Write(pair.Key.ToString() + " " + pair.Value); WriteLine(); } throw ex; } } return Utilities.EscapeName(GenericHelper.GetNonGenericName(property.Name), this.Language); }
private static void CreateWellName(PropertyReference pr) { var name = CleanName(pr.Name); var start = name.IndexOf(NONWELLFLAG); if (start == -1 && pr.Parameters.Count == 0) { if (IsNameRepeated(pr.DeclaringType, name)) name += "_" + GetShortName(pr.PropertyType); } else { var pd = pr.Resolve(); if (pd != null) { var pdJust = pd; var accessor = pd.GetMethod ?? pd.SetMethod; if (accessor != null && accessor.HasOverrides) { var baseAccessor = accessor.Overrides.First().Resolve(); pdJust = baseAccessor.DeclaringType.Properties.First(x => x.GetMethod == baseAccessor || x.SetMethod == baseAccessor); name = baseAccessor.Name.Substring(4); start = name.IndexOf(NONWELLFLAG); } else { // 重载属性,但没有 Overrides ????? } if (pd.HasParameters) { // 将具有参数的缺省属性修改为索引器 //[DefaultMember("Item")] //public class MyClass //{ // public double P_1_double // { // get { switch (e_1) { …… } } // set { switch (e_1) { …… } } // } // …… //} //====> //public class MyClass //{ // public double this[int e_1] // { // get { switch (e_1) { …… } } // set { switch (e_1) { …… } } // } // …… //} pr.mWellName = GetDefaultMemberName(pdJust.DeclaringType) ?? "Item"; return; } } if (start >= 0) name = Replace(name, start, 1, "P") + "_" + GetShortName(pr.PropertyType); } pr.mWellName = Regex.Replace(name, @"\W", "_"); }
/// <summary> /// Mark all reachable items in argument as such. /// </summary> private static void Walk(ReachableContext context, PropertyReference prop) { prop.PropertyType.MarkReachable(context, prop.IsUsedInSerialization); // Parameters if (prop.Parameters.Count > 0) { foreach (ParameterDefinition param in prop.Parameters) { Walk(context, (ParameterReference)param); } } var propDef = prop as PropertyDefinition; if (propDef != null) { // DO NOT AUTOMATICALLY MAKE GET and SET REACHABLE. // (but do so for attributes, so that they can // be properly stored and loaded) if (prop.DeclaringType.Resolve().IsAttribute()) { propDef.GetMethod.MarkReachable(context); propDef.SetMethod.MarkReachable(context); } else if (prop.IsUsedInSerialization || propDef.IsUsedInSerialization) { propDef.GetMethod.MarkReachable(context); propDef.SetMethod.MarkReachable(context); } // Custom attributes Walk(context, (ICustomAttributeProvider)propDef); } else { // Try to resolve prop.Resolve(context).MarkReachable(context, prop.IsUsedInSerialization); } }
/// <summary> /// A cecil property reference will be directed to this method. /// </summary> /// <param name="item">Cecil reference.</param> /// <param name="resolvedItem">Output parameter that will be populated with the resolved cecil definition.</param> /// <returns><c>true</c></returns> private static bool TryResolve(PropertyReference item, out object resolvedItem) { resolvedItem = item.Resolve(); return true; }
/// <summary> /// Mark all eachable items in argument as such. /// </summary> private static void Walk(ReachableContext context, PropertyReference prop) { prop.PropertyType.MarkReachable(context); // Parameters if (prop.Parameters.Count > 0) { foreach (ParameterDefinition param in prop.Parameters) { Walk(context, (ParameterReference)param); } } var propDef = prop as PropertyDefinition; if (propDef != null) { // DO NOT AUTOMATICALLY MAKE GET and SET REACHABLE. //propDef.GetMethod.MarkReachable(context); //propDef.SetMethod.MarkReachable(context); // Custom attributes Walk(context, (ICustomAttributeProvider)propDef); } else { // Try to resolve prop.Resolve(context).MarkReachable(context); } }