Click here to Skip to main content
15,890,557 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Meaning of public enum error, not compile, solve

C#
public enum ConnectionOwnership
{
    public const DbHelperBase<TConnection, TCommand, TParameter, TTransaction, TDataAdapter, TDataReader>.ConnectionOwnership External = DbHelperBase<TConnection, TCommand, TParameter, TTransaction, TDataAdapter, TDataReader>.ConnectionOwnership.External;
    public const DbHelperBase<TConnection, TCommand, TParameter, TTransaction, TDataAdapter, TDataReader>.ConnectionOwnership Internal = DbHelperBase<TConnection, TCommand, TParameter, TTransaction, TDataAdapter, TDataReader>.ConnectionOwnership.Internal;

}


System\Data\DbHelperBase.cs(494,10): 错误 CS1041: 应输入标识符;“public”是关键字
System\Data\DbHelperBase.cs(495,13): 错误 CS1001: 应输入标识符
System\Data\DbHelperBase.cs(506,1): 错误 CS1022: 应输入类型、命名空间定义或文件尾
Posted
Updated 16-Feb-11 4:44am
v5
Comments
Henry Minute 16-Feb-11 9:58am    
I have a pretty good idea what your problem is but before posting an answer I would like to see the EXACT error message.

When you ask a question about an error message you should ALWAYS include the exact message in your question.

So, please edit your question to include the error text. Use the green 'Improve question' widget DO NOT POST AN ANSWER, edit the question.
jim lahey 16-Feb-11 10:00am    
I've never seen aything like this before.. anyone?

That's totally messed up, and just plain wrong.

You can't define a const inside an enum. You can only define ordinals, like this:

C#
public enum ConnectionOwnership { External, Internal };


Beyond that, why are you defining a const? It's kinda pointless when you're using enums which are constants by their very nature.

What in god's name are you trying to do there?
 
Share this answer
 
Comments
jim lahey 16-Feb-11 10:05am    
ditto.
johannesnestler 16-Feb-11 10:06am    
yep, I had the same thoughts...
Albin Abel 16-Feb-11 10:29am    
my 5
Manas Bhardwaj 16-Feb-11 10:48am    
have my 5
Sergey Alexandrovich Kryukov 16-Feb-11 12:30pm    
My 5.
Strictly speaking, enumeration members are static read-only fields, which can be easily validated using Reflection.
--SA
John has told you why you got those errors, but if you are looking to expose some static properties that you need to use from various parts of your code, you need to use a static class and then expose these as read-only (get-only) properties.
 
Share this answer
 
Comments
Espen Harlinn 16-Feb-11 15:13pm    
Reasonable, my 5
What is the integral form of your enumeration?
This is usually the first questions I ask when making then enumeration because that is the only difference.

For instance your enumeration is representing states of a model. What are the integral values of that type?

Are they int? Are they char? does it matter?

You would then define the enumeration like so...

public enum ConnectionOwnership : int { Internal = 0, External, Other, Another = 4 }


The only reason the integral type matters is how the enumeration is used in binary when performing bit wise functions such as AND, OR, XOR, SHL, SHR

The default type is int which can be written in short hand like so

public enum ConnectionOwnership { Invalid = -1, Internal, External, Other, Another = 4 }


The type of element using the Enum is never ever relevant to the declaration of the enumeration.

Take DayOfWeek for Example (System.DayOfWeek I Believe)

Does it care what type is using the enumeration... no it does not... because DayOfWeek is a DayOfWeek regardless of the type which is using the enumeration.


If it is you need another type of DataStructure such as a GenericEnum or Enum<t>.. The problem you will find is that enum cannot be a specified in a where constraint... There is a reason for this.

See this page for the work around which is essentially Enum<t> but does not limit T to be a enum...

http://devlicious.com/blogs/christopher_bennage/archive/2007/09/13/my-new-little-friend-enum-lt-t-gt.aspx[^]

I think I can see what you are trying to do... you want each ConnectionOwnership type to be related to the type in which is instantiated.. What I cannot see is why this is relevant... What you would end up having is multiple enum classes generated with the same exact values. How is this at all useful? Only if the generated enum classes have different values for instance if a Connection<TypeA> is created and then a Connection<TypeB> the values for Internal and External may be swapped... E.g. Connection<TypeA> would have Internal as 1 and External as 0 where Connection<TypeB> may have Internal 0 and External 1.

Consider the ramifications... Why is this a enum? and further more why is that useful? Would it not be more useful to have a constant concrete concept of ConnectionOwnership which is not generic and means the same thing in all instances regardless of the type of the Connection? I believe so.. and I am fairly sure that what you are doing is a violation of some principal of the GOF and OOP. Please review them to ensure you are doing the needful thing...

Hopefully I have answered your question and given you greater insight into what you are actually doing. If you have further questions please let us know and we will try to help.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900