private SerializedLocation(SerializationInfo info, StreamingContext context) { sourceSpan = (TextSpan)info.GetValue("sourceSpan", typeof(TextSpan)); fileSpan = (FileLinePositionSpan)info.GetValue("fileSpan", typeof(FileLinePositionSpan)); mappedFileSpan = (FileLinePositionSpan)info.GetValue("mappedFileSpan", typeof(FileLinePositionSpan)); kind = (LocationKind)info.GetByte("kind"); }
public Exception ValidateValue(string value, string locationName, LocationKind locationKind) { //Trace.WriteLine("name :" + locationName); //Trace.WriteLine("locationKind :" + locationKind); // Trace.WriteLine("MustNotEqualNullOrEmpty " + value + " " + locationName); var kind = string.Empty; switch (locationKind) { case LocationKind.Parameter: kind = "参数"; break; case LocationKind.Property: kind = "属性"; break; case LocationKind.Field: kind = "字段"; break; case LocationKind.ReturnValue: kind = "返回值"; break; } return(string.IsNullOrEmpty(value) ? new ArgumentException(kind + locationName + "的值不能为空引用或空字符串") : null); }
public Exception ValidateValue(uint value, string name, LocationKind locationKind) { if (value == 0) { return(CreateArgumentOutOfRangeException(value, name, locationKind)); } return(null); }
public Exception ValidateValue(int value, string name, LocationKind locationKind) { if (value < _min || value > _max) { return(new ArgumentException($"{locationKind.ToChineseString()}{name}的值必须大于{_min}且小于{_max}")); } return(null); }
public Exception ValidateValue(float value, string locationName, LocationKind locationKind, LocationValidationContext context) { if (value < 0) { return(new ArgumentOutOfRangeException(locationName, value, "Значение не может быть меньше 0.")); } return(null); }
public Exception ValidateValue([MustNotEqualNull] object value, string name, LocationKind locationKind) { if (!value.GetType().IsAssignableFrom(_type)) { return(CreateArgumentOutOfRangeException(value, name, locationKind)); } return(null); }
public Exception ValidateValue(int value, string name, LocationKind locationKind) { if (value < _min || value > _max) { return(new ArgumentException("参数" + name + "必须大于" + _min + "且小于" + _max)); } return(null); }
public Exception ValidateValue(float value, string locationName, LocationKind locationKind, LocationValidationContext context) { if (value < 0) { return(new ArgumentOutOfRangeException($"Значение {locationName} не может быть отрицательным.")); } return(null); }
public Exception ValidateValue(int value, string locationName, LocationKind locationKind) { int maxValue = (int)this.maxValueFieldBinding.GetValue(ref this.instance, Arguments.Empty); if (value < minValue || value > maxValue) { return(new ArgumentOutOfRangeException(locationName)); } return(null); }
public Exception ValidateValue(Rectangle value, string locationName, LocationKind locationKind, LocationValidationContext context) { if (value.Size == Point.Zero) { return(new ArgumentOutOfRangeException($"The size of {value} must not be 0.")); } else { return(null); } }
public Exception ValidateValue(Point value, string locationName, LocationKind locationKind, LocationValidationContext context) { if (value == Point.Zero) { return(new ArgumentOutOfRangeException($"The coordinates for {locationName} must not be (0, 0).")); } else { return(null); } }
public Exception ValidateValue(object value, string locationName, LocationKind locationKind) { IFreezable freezable = value as IFreezable; if (freezable != null) { freezable.Freeze(); } return(null); }
public Exception ValidateValue(string value, string name, LocationKind locationKind) { if (File.Exists(value)) { return(null); } switch (locationKind) { case LocationKind.Parameter: return(new ArgumentException($"参数{name}所指定的文件{value}不存在.")); default: return(null); } }
public static string ToChineseString(this LocationKind locationKind) { switch (locationKind) { case LocationKind.Parameter: return("参数"); case LocationKind.Property: return("属性"); case LocationKind.Field: return("字段"); case LocationKind.ReturnValue: return("返回值"); default: throw new ArgumentException("未知的LocationKind类型"); } }
public Exception ValidateValue( string value, string locationName, LocationKind locationKind, LocationValidationContext context) => value == null || !string.IsNullOrEmpty(value.Trim()) ? null : CreateArgumentException(value, locationName, locationKind);
private Location(LocationKind diagnosticLocation, string name) { ContextPart = diagnosticLocation; Name = name; }
private Location(LocationKind diagnosticLocation) { ContextPart = diagnosticLocation; }
public Exception ValidateValue(string value, string locationName, LocationKind locationKind) => value.StartsWith("B") ? null : new ApplicationException("Must start with B!");
public Observable(LocationKind location) { Location = location; }
/// <summary> /// Validates the value being assigned to the location to which the current aspect has been applied. /// </summary> /// <param name="value">Value being applied to the location.</param><param name="locationName">Name of the location.</param><param name="locationKind">Location kind (<see cref="F:PostSharp.Reflection.LocationKind.Field"/>, <see cref="F:PostSharp.Reflection.LocationKind.Property"/>, or /// <see cref="F:PostSharp.Reflection.LocationKind.Parameter"/>). /// </param> /// <returns> /// The <see cref="T:System.Exception"/> to be thrown, or <c>null</c> if no exception needs to be thrown. /// </returns> public Exception ValidateValue(double value, string locationName, LocationKind locationKind) { return(value > _doubleCompare ? null : new ArgumentException(locationKind.ToChineseString() + locationName + "的值必须大于" + _doubleCompare)); }
public Exception ValidateValue(object value, string locationName, LocationKind locationKind) { return(value == null ? new ArgumentException($"{locationKind.ToChineseString()}{locationName}的值不能赋值为null.") : null); }
public Exception ValidateValue(uint value, string locationName, LocationKind locationKind) { return(value == 0 ? CreateArgumentOutOfRangeException(value, locationName, locationKind) : null); }
public Exception ValidateValue(object value, string locationName, LocationKind locationKind) { return(Equals(value, _compare) ? new ArgumentException($"{locationKind.ToChineseString()}{locationName}的值不能赋值为{_compare}") : null); }
public Exception ValidateValue(Version value, string locationName, LocationKind locationKind) { return(value == new Version() ? new ArgumentException(locationKind.ToChineseString() + locationName + "的值不能赋值为空版本") : null); }
public Exception ValidateValue(int value, string locationName, LocationKind locationKind) { return(value % _mod == 0 ? null : new ArgumentException($"{locationKind.ToChineseString()}{locationName}的值必须是{_mod}的倍数")); }
public Exception ValidateValue( string value, string locationName, LocationKind locationKind, LocationValidationContext context) => value == "latest" || Version.TryParse(value, out _) ? null : CreateArgumentException(value, locationName, locationKind);
private static float[] ComputeDashDistances(SymPath path, LocationKind kind, float dashLength, float firstDashLength, float lastDashLength, float gapLength, int minGaps, float offset, int numEndSecGaps, float lengthEndSecGaps, int numMiddleSecGaps, float lengthMiddleSecGaps, float decreaseLimit, bool decreaseBothEnds) { // Get length of each segment, deliniated by corner points. PointKind[] pointkinds; float[] segmentLengths = path.GetCornerAndDashPointDistancesBizzarro(out pointkinds); float[] lengthAtEnd = new float[segmentLengths.Length]; float[][] dashDistances = new float[segmentLengths.Length][]; // Compute dash distances for each segment of the path. int totalDistances = 0; for (int i = 0; i < dashDistances.Length; ++i) { // Compute first and last lengths of the segment in question. float firstLength, lastLength; if (i != 0 && pointkinds[i] == PointKind.Dash) firstLength = dashLength / 2; else firstLength = firstDashLength; if (i < dashDistances.Length - 1 && pointkinds[i + 1] == PointKind.Dash) lastLength = dashLength / 2; else lastLength = lastDashLength; // Note that minGaps is only required on the LAST segment. This is because that the minGaps requirement is for // all segments together, not each segment. int numGaps; dashDistances[i] = ComputeDashDistances(segmentLengths[i], kind, dashLength, firstLength, lastLength, gapLength, (i == dashDistances.Length - 1) ? minGaps : 0, offset, numEndSecGaps, lengthEndSecGaps, numMiddleSecGaps, lengthMiddleSecGaps, decreaseLimit, decreaseBothEnds, out lengthAtEnd[i], out numGaps); minGaps = Math.Max(minGaps - numGaps, 0); totalDistances += dashDistances[i].Length; // The last dash and first dash of adjacent parts merge together. if (kind == LocationKind.DashAndGapLengths && i > 0) --totalDistances; } if (dashDistances.Length == 1) { return dashDistances[0]; } // Combine the distances from each segment into a single array. For dash and gap lengths, combine the // dash lengths around segment boundaries. float[] distances = new float[totalDistances]; int index = 0; for (int i = 0; i < dashDistances.Length; ++i) { Array.Copy(dashDistances[i], 0, distances, index, dashDistances[i].Length); if (i > 0 && dashDistances[i].Length > 0) { distances[index] += lengthAtEnd[i - 1]; } if (i > 0 && (dashDistances[i].Length == 0 || (kind == LocationKind.DashAndGapLengths && dashDistances[i].Length == 1))) lengthAtEnd[i] += lengthAtEnd[i - 1]; index += dashDistances[i].Length; if (kind == LocationKind.DashAndGapLengths) --index; } if (kind == LocationKind.DashAndGapLengths) distances = RemoveZeroGaps(distances); return distances; }
// Computes the dash distances for a single segment. Also returns the distance from the last location to the end of the segment. // If LocationKind is DashesAndGapLengths, this is a duplicate of the last array element. private static float[] ComputeDashDistances(float pathLength, LocationKind kind, float dashLength, float firstDashLength, float lastDashLength, float gapLength, int minGaps, float offset, int numEndSecGaps, float lengthEndSecGaps, int numMiddleSecGaps, float lengthMiddleSecGaps, float decreaseLimit, bool decreaseBothEnds, out float lengthAtEnd, out int actualGaps) { int numGaps; // actual number of gaps in the line float actualDashLength; // actual length of each dash float actualFirstDashLength; // actual length of first dash float actualLastDashLength; // actual last dash length. if (kind == LocationKind.GapCentersDecrease) { // Computer number of dashes based on average dash length. dashLength = (dashLength + (dashLength * decreaseLimit)) / 2; } // Computer the number of gaps // The number of gaps is adjusted so that the gap lengths are always preserved exactly, and the dash lengths are as close as possible to the actual dash lengths. if (pathLength - firstDashLength - lastDashLength <= gapLength) numGaps = (minGaps >= 1 || pathLength >= firstDashLength / 2 + lastDashLength / 2 + gapLength) ? 1 : 0; else numGaps = (int) Math.Round((pathLength + dashLength - firstDashLength - lastDashLength) / (dashLength + gapLength)); // Enforce minimum gaps. if (numGaps < minGaps) numGaps = minGaps; // Given the number of gaps, compute the lengths of the dashes. Gaps are always at their nominal length. if (numGaps == 0) actualDashLength = actualFirstDashLength = actualLastDashLength = pathLength; else { if (numGaps == 1 && firstDashLength == 0 && lastDashLength == 0) actualDashLength = actualFirstDashLength = actualLastDashLength = 0; else { actualDashLength = (pathLength - gapLength * numGaps) / (numGaps - 1 + firstDashLength / dashLength + lastDashLength / dashLength); actualFirstDashLength = actualDashLength * firstDashLength / dashLength; actualLastDashLength = actualDashLength * lastDashLength / dashLength; } } actualGaps = numGaps; if (actualDashLength <= 0) { // Special case: the path is "all gap". if (kind == LocationKind.GapCenters) { if (numGaps > 1) { // multiple gaps. Put at either end. lengthAtEnd = 0; return new float[2] { 0, pathLength }; // in middle of single gap } else { lengthAtEnd = pathLength / 2; return new float[1] { pathLength / 2 }; // in middle of single gap } } else if (kind == LocationKind.DashCenters || kind == LocationKind.MiddleDashCenters|| kind == LocationKind.GapCentersOffset) { lengthAtEnd = pathLength; return new float[0]; } else { lengthAtEnd = 0.0F; return new float[3] { 0.0F, pathLength, 0.0F }; } } int index = 0; float[] locations; if (kind == LocationKind.DashCenters) { locations = new float[numGaps + 1]; locations[index++] = actualFirstDashLength / 2; lengthAtEnd = actualLastDashLength / 2; if (numGaps == 0) return locations; else if (numGaps == 1) locations[index++] = actualLastDashLength + gapLength; else { locations[index++] = actualFirstDashLength / 2 + gapLength + actualDashLength / 2; for (int i = 2; i < numGaps; ++i) locations[index++] = actualDashLength + gapLength; locations[index++] = actualLastDashLength / 2 + gapLength + actualDashLength / 2; } } else if (kind == LocationKind.MiddleDashCenters) { if (numGaps >= 2) { locations = new float[numGaps - 1]; locations[index++] = actualFirstDashLength + gapLength + actualDashLength / 2; lengthAtEnd = actualLastDashLength + gapLength + actualDashLength / 2; for (int i = 1; i < numGaps - 1; ++i) locations[index++] = actualDashLength + gapLength; } else { locations = new float[0]; lengthAtEnd = pathLength; } } else if (kind == LocationKind.GapCenters) { locations = new float[numGaps]; if (numGaps == 0) lengthAtEnd = pathLength; else { lengthAtEnd = actualLastDashLength + gapLength / 2; locations[index++] = actualFirstDashLength + gapLength / 2; for (int i = 1; i < numGaps; ++i) locations[index++] = actualDashLength + gapLength; } } else if (kind == LocationKind.GapCentersDecrease) { locations = new float[numGaps]; if (numGaps == 0) lengthAtEnd = pathLength; else { lengthAtEnd = actualLastDashLength + gapLength / 2; locations[index++] = actualFirstDashLength + gapLength / 2; if (numGaps > 1) { if (decreaseBothEnds) { float currentDashLength = 2 * actualDashLength / (1 + decreaseLimit); if (numGaps % 2 == 1) { float dashDelta = (currentDashLength - decreaseLimit * currentDashLength) / (numGaps - 1); currentDashLength = decreaseLimit * currentDashLength; for (int i = 1; i < numGaps; ++i) { if (i == (numGaps + 1) / 2) dashDelta = -dashDelta; currentDashLength += dashDelta; locations[index++] = currentDashLength + gapLength; currentDashLength += dashDelta; } } else { float dashDelta; if (numGaps == 2) dashDelta = 0; else { dashDelta = currentDashLength * (((1.0F - (1.0F - decreaseLimit) / numGaps) - decreaseLimit) / (numGaps - 2)); currentDashLength = decreaseLimit * currentDashLength; } for (int i = 1; i < numGaps; ++i) { if (i != numGaps / 2) currentDashLength += dashDelta; locations[index++] = currentDashLength + gapLength; if (i == numGaps / 2) dashDelta = -dashDelta; else currentDashLength += dashDelta; } } } else { float currentDashLength = 2 * actualDashLength / (1 + decreaseLimit); float dashDelta = -(currentDashLength - decreaseLimit * currentDashLength) / ((numGaps-1) * 2); for (int i = 1; i < numGaps; ++i) { currentDashLength += dashDelta; locations[index++] = currentDashLength + gapLength; currentDashLength += dashDelta; } } } } } else if (kind == LocationKind.GapCentersOffset) { locations = new float[numGaps - 1]; if (numGaps <= 1) lengthAtEnd = pathLength; else { lengthAtEnd = actualLastDashLength + gapLength / 2 + actualDashLength + gapLength - offset; locations[index++] = actualFirstDashLength + gapLength / 2 + offset; for (int i = 1; i < numGaps - 1; ++i) locations[index++] = actualDashLength + gapLength; } } else { Debug.Assert(kind == LocationKind.DashAndGapLengths); List<float> locationList = new List<float>(numGaps * 2 + 1); if (numGaps > 0) { // Add first dash (with secondary gaps as appropriate). if (numEndSecGaps > 0 && (actualFirstDashLength >= firstDashLength / 2)) locationList.AddRange(AddSecondaryGaps(actualFirstDashLength, numEndSecGaps, lengthEndSecGaps)); // add with secondary gaps. else locationList.Add(actualFirstDashLength); // no secondary gaps // Add middle dashes and gaps to them (with secondary gaps as appropriate) for (int i = 1; i < numGaps; ++i) { locationList.Add(gapLength); if (numMiddleSecGaps > 0 && (actualDashLength >= dashLength / 2)) locationList.AddRange(AddSecondaryGaps(actualDashLength, numMiddleSecGaps, lengthMiddleSecGaps)); // add with secondary gaps else locationList.Add(actualDashLength); } // Add gap to last dash. locationList.Add(gapLength); } // Add last dash (with secondary gaps as appropriate). if (numEndSecGaps > 0 && (actualLastDashLength >= lastDashLength / 2) && numGaps > 0) locationList.AddRange(AddSecondaryGaps(actualLastDashLength, numEndSecGaps, lengthEndSecGaps)); // add with secondary gaps. else locationList.Add(actualLastDashLength); // Convert to array. locations = locationList.ToArray(); lengthAtEnd = locationList[locationList.Count - 1]; } return locations; }
public Exception ValidateValue(int value, string name, LocationKind locationKind) { return(value <= _intCompare ? null : new ArgumentException(locationKind.ToChineseString() + name + "的值必须小于或等于" + _intCompare)); }
public static bool IsVariable(this LocationKind kind) { return(kind == LocationKind.Argument || kind == LocationKind.Local); }
public WeatherData(LocationKind location) : base(location) { }