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 lived and breathed MSN Messenger/Windows Live Messenger. Going to the mess.be website (still online with no changes since 2013) to download display pictures etc. I was a beta tester for Messenger Plus! and spent quite a lot of time on the MsgPlus! forums (a read-only copy is still online at https://shoutbox.menthix.net)
Some old Neowin articles also https://www.neowin.net/news/messenger-plus-350/ good times but how time flies
Well i'll look into a docking station if needed and use that. Normally i don't usually have all the drives connected at once, usually once a month to sync the latest files, and then they go back in there storage area
memories! completely forgot about alcohol 120%!!!! man this list just makes me think of all the exciting times! everything's become so sterilized these days.
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