I'm having a couple of FxCop errors that I don't really know how to fix. Well, I do know how to fix them, but I don't really like the solutions I can think of...
[CLSCompliantAttribute(true)]
[AttributeUsage(AttributeTargets.Property)]
public sealed class LightSettingsAttribute : Attribute {
private string sectionName;
private object defaultValue;
public string SectionName {
get {
return this.sectionName;
}
}
public object DefaultValue {
get {
return this.defaultValue;
}
}
public LightSettingsAttribute(String sectionName, Type valueType, string defaultValue) {
this.sectionName = sectionName;
this.defaultValue = TypeDescriptor.GetConverter(valueType).ConvertFromInvariantString(defaultValue);
}
}
I would fix it by creating a public readonly property and then set the private value (that the property returns) to the variable valueType passed as parameter of the constructor and then use the property value in the GetConverter() method. But this is stupid... I only need to use valueType on the GetConverter() inside the constructor, I don't need to save the value of valueType.
I checked similar code in the framework (using Reflector) and Microsoft doesn't do that, it simply uses the parameter value as I did. Anyway to go around this issue?
Basically this is how I'm handling some exception:
try {
} catch (Exception ex) {
}
I'm doing this because no matter what the CLS compilant exception thrown I need the piece of code inside the catch block to be executed. I can't go and catch each individual exception and duplicate the code (yes, I could put it in a method but I was looking to avoid that if possible). Maybe only 2 out of a few exceptions will actually be thrown (if they are) but either way, is there some way to catch multiple exceptions and use the same catch block?
I've never owned any apple products, but I have a coworker who has one and he said it's the best phone he's ever had. And he's pretty much had every apple phone around. His biggest like is the light weight.
Question
ProclaimDragon
Hi,
I'm having a couple of FxCop errors that I don't really know how to fix. Well, I do know how to fix them, but I don't really like the solutions I can think of...
The errors I'm having are:
[suppressMessage("Microsoft.Design", "CA1019:DefineAccessorsForAttributeArguments")]
Code causing the error:
[CLSCompliantAttribute(true)] [AttributeUsage(AttributeTargets.Property)] public sealed class LightSettingsAttribute : Attribute { private string sectionName; private object defaultValue; public string SectionName { get { return this.sectionName; } } public object DefaultValue { get { return this.defaultValue; } } public LightSettingsAttribute(String sectionName, Type valueType, string defaultValue) { this.sectionName = sectionName; this.defaultValue = TypeDescriptor.GetConverter(valueType).ConvertFromInvariantString(defaultValue); } }I would fix it by creating a public readonly property and then set the private value (that the property returns) to the variable valueType passed as parameter of the constructor and then use the property value in the GetConverter() method. But this is stupid... I only need to use valueType on the GetConverter() inside the constructor, I don't need to save the value of valueType.
I checked similar code in the framework (using Reflector) and Microsoft doesn't do that, it simply uses the parameter value as I did. Anyway to go around this issue?
[suppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes")]
Basically this is how I'm handling some exception:
try {
} catch (Exception ex) {
}
I'm doing this because no matter what the CLS compilant exception thrown I need the piece of code inside the catch block to be executed. I can't go and catch each individual exception and duplicate the code (yes, I could put it in a method but I was looking to avoid that if possible). Maybe only 2 out of a few exceptions will actually be thrown (if they are) but either way, is there some way to catch multiple exceptions and use the same catch block?
Link to comment
https://www.neowin.net/forum/topic/647227-suggestions-to-fix-a-couple-of-fxcop-errors/Share on other sites
4 answers to this question
Recommended Posts