Problemer med intellisence o_O, men compiler fint
Jeg har et projekt hvor jeg pluselig har fået nogle problemer med min intelissence i, ved ikke horfor og hvordan, det er bare pluselig sket..Projektet compiler og kører fint nok, men det er lidt træls i længden at skulle huske hvordan...
Projektet er en inkapsulering af XML sættings, med interesse for at gøre nogle ting lidt nemmere end det er fra ren XML.
XmlSetting (Svarer delvist til et XmlElement)
-----------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Text;
namespace Util.Settings
{
public class XmlSetting
{
private enum SettingType { Undefined = 0x01, Simple = 0x02, Collection = 0x04 }
private Dictionary<string, string> _properties;
private Dictionary<string, List<XmlSetting>> _xmlMap;
private SettingType _type;
private string _value;
private string _name;
#region public XmlSetting( string name )
/// <summary>
///
/// </summary>
/// <param name="name"></param>
public XmlSetting( string name )
{
this._name = name;
this._type = SettingType.Undefined;
this._properties = new Dictionary<string, string>();
this._xmlMap = new Dictionary<string, List<XmlSetting>>();
}
#endregion
#region public string Name
/// <summary>
///
/// </summary>
public string Name
{
get { return _name; }
set { _name = value; }
}
#endregion
#region public Dictionary<string, string> Properties
/// <summary>
///
/// </summary>
public Dictionary<string, string> Properties
{
get
{
return this._properties;
}
}
#endregion
#region public string Value
/// <summary>
///
/// </summary>
public string Value
{
get
{
if ( this._type != SettingType.Collection )
{
return this._value;
}
else
{
throw new InvalidOperationException( "A Setting that consist of several sub-settings cannot contain a value" );
}
}
set
{
if ( this._type != SettingType.Collection )
{
if ( string.IsNullOrEmpty( value ) )
this._type = SettingType.Undefined;
else
this._type = SettingType.Simple;
this._value = value;
}
else
{
throw new InvalidOperationException( "A Setting that consist of several sub-settings cannot contain a value" );
}
}
}
#endregion
#region public List<XmlSetting> this[ string key ]
/// <summary>
///
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
public List<XmlSetting> this[ string key ]
{
get
{
if ( !this._xmlMap.ContainsKey( key ) )
{
throw new IndexOutOfRangeException( "The specified key was not found in the collection" );
}
return this._xmlMap[ key ];
}
}
#endregion
#region public XmlSetting this[ string key, int index ]
/// <summary>
///
/// </summary>
/// <param name="key"></param>
/// <param name="index"></param>
/// <returns></returns>
public XmlSetting this[ string key, int index ]
{
get
{
if ( this._type != SettingType.Simple )
{
if ( !this._xmlMap.ContainsKey( key ) )
{
this._xmlMap[ key ] = new List<XmlSetting>();
this._xmlMap[ key ].Add( new XmlSetting( key ) );
}
this._type = SettingType.Collection;
return this._xmlMap[ key ][ index ];
}
else
{
throw new InvalidOperationException( "A Setting that consist of a value cannot contain sub-settings" );
}
}
set
{
if ( this._type != SettingType.Simple )
{
if ( !this._xmlMap.ContainsKey( key ) )
{
this._xmlMap[ key ] = new List<XmlSetting>();
this._xmlMap[ key ].Add( new XmlSetting( key ) );
}
this._type = SettingType.Collection;
this._xmlMap[ key ][ index ] = value;
}
else
{
throw new InvalidOperationException( "A Setting that consist of a value cannot contain sub-settings" );
}
}
}
#endregion
#region public void AddProperty( string key, string value )
/// <summary>
///
/// </summary>
/// <param name="key"></param>
/// <param name="value"></param>
public void AddProperty( string key, string value )
{
this._properties.Add( key, value );
}
#endregion
#region public void AddValue( string key, string value )
/// <summary>
///
/// </summary>
/// <param name="key"></param>
/// <param name="value"></param>
public void AddValue( string key, string value )
{
XmlSetting item = new XmlSetting( key );
item.Value = value;
if ( !this._xmlMap.ContainsKey( key ) )
this._xmlMap[ key ] = new List<XmlSetting>();
this._xmlMap[ key ].Add( item );
}
#endregion
#region public void AddSubSettings( string key )
/// <summary>
///
/// </summary>
/// <param name="key"></param>
public void AddSubSettings( string key )
{
XmlSetting item = new XmlSetting( key );
item._type = SettingType.Collection;
if ( !this._xmlMap.ContainsKey( key ) )
this._xmlMap[ key ] = new List<XmlSetting>();
this._xmlMap[ key ].Add( item );
}
#endregion
#region internal void AddSettingsNode( XmlSetting node )
/// <summary>
///
/// </summary>
/// <param name="node"></param>
internal void AddSettingsNode( XmlSetting node )
{
if ( !this._xmlMap.ContainsKey( node.Name ) )
this._xmlMap[ node.Name ] = new List<XmlSetting>();
this._xmlMap[ node.Name ].Add( node );
}
#endregion
}
}
-----------------------------------------------------------------
XmlSettingDocumet (Skal stå for exponering uf af til, load samt save, pt mest bare en "dummy" over XmlSetting
-----------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
namespace Util.Settings
{
public class XmlSettingDocument
{
private XmlSetting _root;
public Dictionary<string, string> Properties
{
get { return this._root.Properties; }
}
public List<XmlSetting> this[ string key ]
{
get { return this._root[ key ]; }
}
public XmlSetting this[ string key, int index ]
{
get { return this._root[ key, index ]; }
}
public XmlSettingDocument()
{
this._root = new XmlSetting( "root" );
}
public void Save( XmlDocument xml )
{
}
public void Load( XmlDocument xml )
{
XmlNode n = xml.LastChild;
this._root = this.Traverse( xml.LastChild );
}
private XmlSetting Traverse( XmlNode node )
{
XmlSetting s = new XmlSetting( node.Name );
if ( node.Attributes != null )
{
foreach ( XmlAttribute a in node.Attributes )
{
s.AddProperty( a.Name, a.Value );
}
}
if ( node.HasChildNodes )
{
foreach ( XmlNode n in node.ChildNodes )
{
s.AddSettingsNode( this.Traverse( n ) );
}
}
else
{
s.Value = node.InnerXml;
}
return s;
}
}
}
-----------------------------------------------------------------
Anvendelsen er heller ikke helt på plads, men der hvor Intellisencen går galt er på mine Indexers...
public void AccessTest()
{
XmlDocument xml = new XmlDocument();
xml.Load( @"Sample\XmlSample.xml" );
XmlSettingDocument set = new XmlSettingDocument();
set.Load( xml );
Console.WriteLine( set.Properties[ "PA0" ] );
Console.WriteLine( set[ "B", 0 ][ "C", 0 ].Properties[ "PC0" ] );
}
her stopper intelisensen med at virke efter fx:
set[ "B", 0 ]
derfra skal man så selv huske hvad man skal skrive, og det er død irriterende... og den ved udemærket godt at den returnere et XmlSetting object, så der burde både være indexers, properties og metoder... men det kan den ikke lige finde ud af... ???
Nogen som har nogle geniale ideer?
(Visual Studio 2005)